0.7.4 compatibility update - new chat message handling [part1]

This commit is contained in:
Shoghi Cervantes 2013-08-26 18:16:30 +02:00
parent 3779a66bdb
commit dc0577dcfa
4 changed files with 26 additions and 17 deletions

View File

@ -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);
}

View File

@ -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){
@ -594,6 +595,7 @@ class Player{
if($m !== ""){
$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{

View File

@ -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));

View File

@ -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",
);