Advertisement
Sax

Fishgame - onMessage()

Sax
Dec 17th, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. public function onMessage(ConnectionInterface $from, $msg) {
  2.         /*!
  3.         Triggers everytime a message is received by the application.
  4.         Depending on @p $msg type, the application will broadcast @p $msg accordingly.
  5.  
  6.         @param ConnectionInterface $from
  7.         This is the socket (client) who sent @p $msg.
  8.         @param string $msg
  9.         A JSON string sent by the client.
  10.         */
  11.  
  12.         $usermsg = json_decode($msg, true);
  13.  
  14.         if (isset($usermsg["message"])) {
  15.             $forbidden = ['/</u', '/>/u'];
  16.             $escapes = ['&lt;', '&gt;'];
  17.             $nohtml = preg_replace($forbidden, $escapes, $usermsg["message"]); //Prevent HTML tags from being sent to other clients
  18.         }
  19.  
  20.         $numRecv = count($this->players) -1;
  21.  
  22.         switch ($usermsg["type"]) {
  23.  
  24.             case 'text':
  25.                 $this->text($from, $nohtml, "text");
  26.                 break;
  27.  
  28.             case 'token':
  29.                 $this->token($from, $usermsg["im"]);
  30.                 break;
  31.  
  32.             case "ready":
  33.                 $this->ready($from);
  34.                 break;
  35.  
  36.             case "action":
  37.                 $this->text($from, $nohtml, "action");
  38.                 break;
  39.  
  40.             case "users":
  41.                 $this->whoIsOnline($from);
  42.                 break;
  43.  
  44.             case "listen":
  45.                 $this->listen($from);
  46.                 break;
  47.  
  48.             case "end":
  49.                 $this->finish($from, $nohtml);
  50.                 break;
  51.  
  52.             case 'statInit':
  53.                 $this->statInit($from);
  54.                 break;
  55.  
  56.         }
  57.  
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement