Added console commands

This commit is contained in:
Shoghi Cervantes Pueyo
2012-12-08 03:11:06 +01:00
parent 589c151a4c
commit b1d97809c9
7 changed files with 269 additions and 93 deletions

View File

@ -194,8 +194,7 @@ class CustomPacketHandler{
$this->data["z"] = Utils::readFloat($this->get(4));
$this->data["yaw"] = Utils::readFloat($this->get(4));
$this->data["pitch"] = Utils::readFloat($this->get(4));
$this->data["block"] = Utils::readShort($this->get(2), false);
$this->data["meta"] = Utils::readShort($this->get(2), false);
$this->data["metadata"] = $this->get(true);
}else{
$this->raw .= Utils::writeLong($this->data["clientID"]);
$this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"];
@ -205,8 +204,7 @@ class CustomPacketHandler{
$this->raw .= Utils::writeFloat($this->data["z"]);
$this->raw .= Utils::writeFloat($this->data["yaw"]);
$this->raw .= Utils::writeFloat($this->data["pitch"]);
$this->raw .= Utils::writeShort($this->data["block"]);
$this->raw .= Utils::writeShort($this->data["meta"]);
$this->raw .= "\x21\x2c\x01\x10"."\x7f";
}
break;
case MC_REMOVE_ENTITY:

View File

@ -33,7 +33,7 @@ define("ENTITY_ITEM", 3);
define("ENTITY_PAINTING", 4);
class Entity{
var $eid, $type, $name, $position, $dead, $metadata, $class, $attach;
var $eid, $type, $name, $position, $dead, $metadata, $class, $attach, $data, $closed;
protected $health, $client;
function __construct($eid, $class, $type = 0, $server){ //$type = 0 ---> player
@ -42,9 +42,12 @@ class Entity{
$this->type = (int) $type;
$this->class = (int) $class;
$this->attach = false;
$this->data = array();
$this->status = 0;
$this->health = 20;
$this->dead = false;
$this->closed = false;
$this->name = "";
$this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");");
$this->metadata = array();
/*include("misc/entities.php");
@ -62,9 +65,16 @@ class Entity{
}*/
}
public function close(){
if($this->closed === false){
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";");
$this->server->trigger("onEntityRemove", $this->eid);
$this->closed = true;
}
}
public function __destruct(){
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";");
$this->server->trigger("onEntityRemove", $this->eid);
$this->close();
}
public function getEID(){

View File

@ -76,7 +76,7 @@ class PocketMinecraftServer{
$this->event("onChat", "eventHandler", true);
$this->action(1000000, '$this->time += $this->timePerSecond;$this->trigger("onTimeChange", $this->time);');
$this->action(100000, '$this->time += ceil($this->timePerSecond / 10);$this->trigger("onTimeChange", $this->time);');
$this->action(1000000 * 60, '$this->reloadConfig();');
$this->action(1000000 * 60 * 10, '$this->custom = array();');
$this->action(1000000 * 80, '$list = ""; foreach($this->clients as $c){$list .= ", ".$c->username;}$this->chat(false, count($this->clients)."/".$this->maxClients." online: ".substr($list, 2));');
@ -103,7 +103,7 @@ class PocketMinecraftServer{
public function reloadConfig(){
if($this->whitelist === true or is_array($this->whitelist)){
$this->whitelist = explode("\n", str_replace(array(" ","\t","\r"), "", file_get_contents(FILE_PATH."white-list.txt")));
$this->whitelist = explode("\n", str_replace(array("\t","\r"), "", file_get_contents(FILE_PATH."white-list.txt")));
}
$this->bannedIPs = explode("\n", str_replace(array(" ","\t","\r"), "", file_get_contents(FILE_PATH."banned-ips.txt")));
}

View File

@ -70,6 +70,10 @@ class Session{
}
public function close($reason = "server stop", $msg = true){
$this->save();
if(is_object($this->entity)){
$this->entity->close();
}
foreach($this->evid as $ev){
$this->server->deleteEvent($ev[0], $ev[1]);
}
@ -77,10 +81,6 @@ class Session{
if($msg === true){
$this->server->trigger("onChat", $this->username." left the game");
}
$this->save();
if(is_object($this->entity)){
$this->entity->__destruct();
}
console("[INFO] Session with ".$this->ip.":".$this->port." closed due to ".$reason);
unset($this->server->entities[$this->eid]);
unset($this->server->clients[$this->CID]);
@ -102,8 +102,8 @@ class Session{
"x" => $entity->position["x"],
"y" => $entity->position["y"],
"z" => $entity->position["z"],
"yaw" => 0,
"pitch" => 0,
"yaw" => $entity->position["yaw"],
"pitch" => $entity->position["pitch"],
),
));
++$this->counter[0];
@ -129,7 +129,7 @@ class Session{
if($data["eid"] === $this->eid){
break;
}
/*$this->send(0x84, array(
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
@ -142,42 +142,23 @@ class Session{
"z" => $data["z"],
"yaw" => $data["yaw"],
"pitch" => $data["pitch"],
"block" => $data["block"],
"meta" => $data["meta"],
),
));
++$this->counter[0];
*/
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_ADD_ITEM_ENTITY,
"eid" => $data["eid"],
"x" => $data["x"],
"y" => $data["y"],
"z" => $data["z"],
"block" => 10,
"meta" => 0,
"stack" => 1,
),
));
++$this->counter[0];
break;
case "onEntityRemove":
if($data === $this->eid){
$this->close("despawn");
}else{
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_ENTITY_REMOVE,
"eid" => $data,
),
));
++$this->counter[0];
break;
}
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_ENTITY_REMOVE,
"eid" => $data,
),
));
++$this->counter[0];
break;
case "onTimeChange":
$this->send(0x84, array(
@ -277,7 +258,7 @@ class Session{
$this->evid[] = array("onTimeChange", $this->server->event("onTimeChange", array($this, "eventHandler")));
$this->evid[] = array("onChat", $this->server->event("onChat", array($this, "eventHandler")));
$this->evid[] = array("onPlayerAdd", $this->server->event("onPlayerAdd", array($this, "eventHandler")));
$this->evid[] = array("onEntityDespawn", $this->server->event("onEntityDespawn", array($this, "eventHandler")));
$this->evid[] = array("onEntityRemove", $this->server->event("onEntityRemove", array($this, "eventHandler")));
$this->evid[] = array("onEntityMove", $this->server->event("onEntityMove", array($this, "eventHandler")));
$this->evid[] = array("onHealthChange", $this->server->event("onHealthChange", array($this, "eventHandler")));
$this->send(0x84, array(
@ -313,6 +294,7 @@ class Session{
console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2);
$this->entity = new Entity($this->eid, ENTITY_PLAYER, 0, $this->server);
$this->entity->setName($this->username);
$this->entity->data["clientID"] = $this->clientID;
$this->server->entities[$this->eid] = &$this->entity;
$this->server->trigger("onPlayerAdd", array(
"clientID" => $this->clientID,
@ -323,49 +305,45 @@ class Session{
"z" => $this->data["spawn"]["z"],
"yaw" => $this->data["spawn"]["yaw"],
"pitch" => $this->data["spawn"]["pitch"],
"block" => 0,
"meta" => 0,
));
foreach($this->server->entities as $entity){
if($entity->eid !== $this->eid){
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_ADD_ITEM_ENTITY,
if($entity->class === 0){
$this->server->trigger("onPlayerAdd", array(
"clientID" => $entity->data["clientID"],
"username" => $entity->name,
"eid" => $entity->eid,
"x" => $entity->position["x"],
"y" => $entity->position["y"],
"z" => $entity->position["z"],
"block" => 10,
"meta" => 0,
"stack" => 1,
),
));
++$this->counter[0];
"yaw" => $entity->position["yaw"],
"pitch" => $entity->position["pitch"],
));
}else{
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_ADD_ITEM_ENTITY,
"eid" => $entity->eid,
"x" => $entity->position["x"],
"y" => $entity->position["y"],
"z" => $entity->position["z"],
"block" => 10,
"meta" => 0,
"stack" => 1,
),
));
++$this->counter[0];
}
}
}
$this->eventHandler($this->server->motd, "onChat");
$this->server->trigger("onChat", $this->username." joined the game");
//$this->server->trigger("onChat", $this->username." joined the game");
break;
case MC_MOVE_PLAYER:
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["yaw"], $data["pitch"]);
$this->server->trigger("onEntityMove", $this->eid);
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_ADD_ITEM_ENTITY,
"eid" => $this->server->eidCnt++,
"x" => $data["x"],
"y" => $data["y"],
"z" => $data["z"],
"block" => 7,
"meta" => 0,
"stack" => 1,
),
));
++$this->counter[0];
break;
case MC_PLAYER_EQUIPMENT:
console("[DEBUG] EID ".$this->eid." has now ".$data["block"].":".$data["meta"]." in their hands!", true, true, 2);