Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function onMessage(ConnectionInterface $from, $msg) {
- /*!
- Triggers everytime a message is received by the application.
- Depending on @p $msg type, the application will broadcast @p $msg accordingly.
- @param ConnectionInterface $from
- This is the socket (client) who sent @p $msg.
- @param string $msg
- A JSON string sent by the client.
- */
- $usermsg = json_decode($msg, true);
- if (isset($usermsg["message"])) {
- $forbidden = ['/</u', '/>/u'];
- $escapes = ['<', '>'];
- $nohtml = preg_replace($forbidden, $escapes, $usermsg["message"]); //Prevent HTML tags from being sent to other clients
- }
- $numRecv = count($this->players) -1;
- switch ($usermsg["type"]) {
- case 'text':
- $this->text($from, $nohtml, "text");
- break;
- case 'token':
- $this->token($from, $usermsg["im"]);
- break;
- case "ready":
- $this->ready($from);
- break;
- case "action":
- $this->text($from, $nohtml, "action");
- break;
- case "users":
- $this->whoIsOnline($from);
- break;
- case "listen":
- $this->listen($from);
- break;
- case "end":
- $this->finish($from, $nohtml);
- break;
- case 'statInit':
- $this->statInit($from);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement