11 public class UDPW implements Runnable{
\r
12 private DatagramPacket $pack = null;
\r
13 private DatagramSocket $sock = null;
\r
15 public UDPW(DatagramPacket $p, DatagramSocket $s)throws Exception{
\r
18 new Thread(this).start();
\r
24 String[] $data = new String($pack.getData()).trim().split("\\s+"); //regex: whitespace character once and more
\r
26 if($data[0].equalsIgnoreCase("!list")){
\r
27 String $response = "";
\r
28 for(int $i = 0; $i < Main.$tcp.$conn.size() ; $i++){
\r
29 TCPW $tmp = Main.$tcp.$conn.get($i);
\r
30 if($tmp.isLoggedIn())$response = $response+$tmp.getName()+"\r\n";
\r
34 if($data[0].equalsIgnoreCase("!info")){
\r
35 String[] $usrdata = Main.$usr.get($data[1]);
\r
36 if($usrdata == null){
\r
37 send("No such user!");
\r
40 send($usrdata[0]+" "+$usrdata[2]);
\r
42 }catch(Exception $e){$e.printStackTrace();}
\r
45 public void send(String $msg){
\r
47 DatagramPacket $packet = new DatagramPacket($msg.getBytes(),$msg.length(),$pack.getAddress(),$pack.getPort());
\r
48 $sock.send($packet);
\r
49 }catch(Exception $e){$e.printStackTrace();}
\r