From dc0577dcfa77889d8f18e61b8e520f10c10756d2 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 26 Aug 2013 18:16:30 +0200 Subject: [PATCH] 0.7.4 compatibility update - new chat message handling [part1] --- src/API/ChatAPI.php | 14 ++++++++++---- src/Player.php | 15 ++++++++------- src/network/CustomPacketHandler.php | 6 ++++-- src/network/ProtocolInfo.php | 8 ++++---- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/API/ChatAPI.php b/src/API/ChatAPI.php index c07baf46e..225814ab7 100644 --- a/src/API/ChatAPI.php +++ b/src/API/ChatAPI.php @@ -103,15 +103,21 @@ class ChatAPI{ } public function send($owner, $text, $whitelist = false, $blacklist = false){ - $message = ""; + $message = array( + "owner" => $owner, + "message" => $text, + } if($owner !== false){ if($owner instanceof Player){ - $message = "<".$owner->username."> "; + console("[INFO] <".$owner->username."> ".$text); }else{ - $message = "<".$owner."> "; + console("[INFO] <".$owner."> ".$text); } + }else{ + console("[INFO] $text"); + $message["owner"] = ""; } - $message .= $text; + if($whitelist === false){ console("[INFO] ".$message); } diff --git a/src/Player.php b/src/Player.php index 070eeefcc..989b0522a 100644 --- a/src/Player.php +++ b/src/Player.php @@ -562,16 +562,17 @@ class Player{ return; }else{ $message = $data->get(); + $this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", $message["message"]), $message["author"]); //Remove ANSI codes from chat } }else{ $message = (string) $data; + $this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", (string) $data)); //Remove ANSI codes from chat } - $this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", $message)); //Remove ANSI codes from chat break; } } - public function sendChat($message){ + public function sendChat($message, $author = ""){ $mes = explode("\n", $message); foreach($mes as $m){ if(preg_match_all('#@([@A-Za-z_]{1,})#', $m, $matches, PREG_OFFSET_CAPTURE) > 0){ @@ -593,7 +594,8 @@ class Player{ } if($m !== ""){ - $this->dataPacket(MC_CHAT, array( + $this->dataPacket(MC_CHAT, array( + "player" => ($author instanceof Player) ? $author->username:$author, "message" => $m, )); } @@ -1627,7 +1629,7 @@ class Player{ $this->entity->updateMetadata(); } break; - case MC_SIGN_UPDATE: + /*case MC_SIGN_UPDATE: if($this->spawned === false or $this->blocked === true){ break; } @@ -1641,15 +1643,14 @@ class Player{ $t->setText($data["line0"], $data["line1"], $data["line2"], $data["line3"]); } } - break; + break;*/ case MC_CHAT: if($this->spawned === false){ break; } $this->craftingItems = array(); $this->toCraft = array(); - $message = preg_replace('#^<.*> #', "", $data["message"]); - if(trim($data["message"]) != "" and strlen($data["message"]) <= 100 and preg_match('#[^\\x20-\\xff]#', $message) == 0){ + if(trim($data["message"]) != "" and strlen($data["message"]) <= 255 and preg_match('#[^\\x20-\\xff]#', $message) == 0){ if($message{0} === "/"){ //Command $this->server->api->console->run(substr($message, 1), $this); }else{ diff --git a/src/network/CustomPacketHandler.php b/src/network/CustomPacketHandler.php index 7a3dc9667..359485cb8 100644 --- a/src/network/CustomPacketHandler.php +++ b/src/network/CustomPacketHandler.php @@ -185,8 +185,10 @@ class CustomPacketHandler{ break; case MC_CHAT: if($this->c === false){ + $this->data["player"] = $this->get(Utils::readShort($this->get(2), false)); $this->data["message"] = $this->get(Utils::readShort($this->get(2), false)); }else{ + $this->raw .= Utils::writeShort(strlen($this->data["player"])).$this->data["player"]; $this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"]; } break; @@ -808,7 +810,7 @@ class CustomPacketHandler{ $this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"]; } break; - case MC_SIGN_UPDATE: + /*case MC_SIGN_UPDATE: if($this->c === false){ $this->data["x"] = Utils::readShort($this->get(2)); $this->data["y"] = ord($this->get(1)); @@ -824,7 +826,7 @@ class CustomPacketHandler{ $this->raw .= Utils::writeLShort(strlen($this->data["line$i"])).$this->data["line$i"]; } } - break; + break;*/ case MC_ADVENTURE_SETTINGS: if($this->c === false){ $this->data["flags"] = Utils::readInt($this->get(4)); diff --git a/src/network/ProtocolInfo.php b/src/network/ProtocolInfo.php index 8d4e349a8..a08afdd94 100644 --- a/src/network/ProtocolInfo.php +++ b/src/network/ProtocolInfo.php @@ -29,7 +29,7 @@ the Free Software Foundation, either version 3 of the License, or define("DEFLATEPACKET_LEVEL", 1); define("CURRENT_STRUCTURE", 5); -define("CURRENT_PROTOCOL", 11); +define("CURRENT_PROTOCOL", 12); define("RAKNET_MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78"); @@ -98,8 +98,8 @@ define("MC_CONTAINER_SET_DATA", 0xb2); define("MC_CONTAINER_SET_CONTENT", 0xb3); //define("MC_CONTAINER_ACK", 0xb4); define("MC_CLIENT_MESSAGE", 0xb5); -define("MC_SIGN_UPDATE", 0xb6); -define("MC_ADVENTURE_SETTINGS", 0xb7); +define("MC_ADVENTURE_SETTINGS", 0xb6); +define("MC_ENTITY_DATA", 0xb7); class Protocol{ @@ -166,7 +166,7 @@ class Protocol{ MC_CONTAINER_SET_SLOT => "Set Container Slot", MC_CLIENT_MESSAGE => "Client Message", - MC_SIGN_UPDATE => "Sign Update", + //MC_SIGN_UPDATE => "Sign Update", MC_ADVENTURE_SETTINGS => "Adventure Settings", );