Compare commits

...

9 Commits

Author SHA1 Message Date
732ee755e8 Updated to Alpha_1.0.4 2013-01-05 11:37:57 +01:00
f0393f9b93 /give command 2013-01-05 11:34:08 +01:00
f23c2f894d Merge pull request #27 from C0deH4cker/patch-1
Fixed typo [HUGE]
2013-01-05 01:32:41 -08:00
85dfb651bd Merge pull request #29 from C0deH4cker/patch-2
Added pause at the end
2013-01-05 01:31:09 -08:00
b5e6130214 Added pause at the end
Added pause so users can see any errors that occur instead of the command prompt window just closing.
2013-01-05 02:01:05 -05:00
957f24c1f3 Fixed typo 2013-01-04 23:08:39 -05:00
518afeae48 Item pickup 2013-01-05 03:16:11 +01:00
57282225d2 Fixed Sapling, flower placing 2013-01-05 02:40:29 +01:00
369f268b90 Improved compression 2013-01-04 21:47:36 +01:00
9 changed files with 90 additions and 44 deletions

View File

@ -64,7 +64,8 @@ cd ../
--with-zlib \
--enable-sockets \
--enable-pthreads \
--enable-maintainer-zts
--enable-maintainer-zts \
--enable-cli
make
echo "n" | make test
make install

View File

@ -42,6 +42,41 @@ class BlockAPI{
$this->server->addHandler("world.block.update", array($this, "updateBlockRemote"), 1);
$this->server->addHandler("player.block.break", array($this, "blockBreak"), 1);
$this->server->addHandler("player.block.action", array($this, "blockAction"), 1);
$this->server->api->console->register("give", "Give items to a player", array($this, "commandHandler"));
}
public function commandHandler($cmd, $params){
switch($cmd){
case "give":
if(!isset($params[0]) or !isset($params[1])){
console("[INFO] Usage: /give <username> <item> [amount] [damage]");
break;
}
$username = $params[0];
$b = explode(":", $params[1]);
if(!isset($b[1])){
$meta = 0;
}else{
$meta = ((int) $b[1]) & 0x0F;
}
$block = ((int) $b[0]) & 0xFF;
if(!isset($params[2])){
$amount = 64;
}else{
$amount = $params[2] & 0xFF;
}
if(isset($params[3])){
$meta = $params[3] & 0x0F;
}
if(($player = $this->server->api->player->get($username)) !== false){
$this->drop($player->entity->x, $player->entity->y, $player->entity->z, $block, $meta, $amount);
console("[INFO] Giving ".$amount." of ".$block.":".$meta." to ".$username);
}else{
console("[INFO] Unknown player");
}
break;
}
}
private function cancelAction($block){
@ -306,7 +341,7 @@ class BlockAPI{
}
case 37:
case 38:
if($target[0] !== 2 and $target[0] !== 3){
if(($target[0] !== 2 and $target[0] !== 3) or $data["face"] !== 1){
return false;
}
break;

View File

@ -33,7 +33,6 @@ class EntityAPI{
public function init(){
$this->server->addHandler("player.death", array($this, "handle"), 1);
$this->server->api->console->register("give", "Give items to a player [DUMMY]", array($this, "commandHandler"));
}
public function handle($data, $event){
@ -61,15 +60,6 @@ class EntityAPI{
break;
}
}
public function commandHandler($cmd, $params){
switch($cmd){
case "give":
break;
}
}
public function get($eid){
if(isset($this->server->entities[$eid])){

View File

@ -61,6 +61,10 @@ class ChunkParser{
public function loadFile($file){
if(ZLIB_EXTENSION === true and file_exists($file.".gz")){
$this->raw = gzinflate(file_get_contents($file.".gz"));
$r = @gzinflate($this->raw);
if($r !== false and $r != ""){
$this->raw = $r;
}
@unlink($file.".gz");
file_put_contents($file, $this->raw);
}elseif(!file_exists($file)){
@ -166,7 +170,10 @@ class ChunkParser{
flock($fp, LOCK_UN);
fclose($fp);
if(ZLIB_EXTENSION === true){
file_put_contents($this->file .".gz", gzdeflate(file_get_contents($this->file), 9));
$original = filesize($this->file);
file_put_contents($this->file .".gz", gzdeflate(gzdeflate(file_get_contents($this->file),9),9)); //Double compression for flat maps
$compressed = filesize($this->file .".gz");
console("[DEBUG] Saved chunks.dat.gz with ".round(($compressed/$original)*100, 2)."% (".round($compressed/1024, 2)."KB) of the original size", true, true, 2);
if($final === true){
@unlink($this->file);
}

View File

@ -81,6 +81,8 @@ class Entity extends stdClass{
if($player !== true and $player !== false){
if($this->server->api->dhandle("player.item.pick", array(
"eid" => $player["EID"],
"block" => $this->type,
"meta" => $this->meta,
"target" => $this->eid
)) !== false){
$this->close();
@ -163,6 +165,7 @@ class Entity extends stdClass{
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";");
$this->server->api->dhandle("entity.remove", $this->eid);
$this->closed = true;
unset($this);
}
}

View File

@ -114,7 +114,10 @@ class Player{
public function eventHandler($data, $event){
switch($event){
case "player.item.pick":
$this->dataPacket(MC_TAKE_ITEM_ENTITY, $data);
if($data["eid"] === $this->eid){
$data["eid"] = 0;
}
$this->dataPacket(MC_TAKE_ITEM_ENTITY, $data);
break;
case "player.equipment.change":
if($data["eid"] === $this->eid){
@ -277,31 +280,37 @@ class Player{
"eid" => 0,
));
break;
case MC_READY:
if($this->spawned !== false){
break;
}
$this->spawned = true;
$this->entity = $this->server->api->entity->add(ENTITY_PLAYER, 0, array("player" => $this));
$this->eid = $this->entity->eid;
$this->server->query("UPDATE players SET EID = ".$this->eid." WHERE clientID = ".$this->clientID.";");
$this->entity->setName($this->username);
$this->entity->data["clientID"] = $this->clientID;
$this->server->api->entity->spawnAll($this);
$this->server->api->entity->spawnToAll($this->eid);
$this->evid[] = $this->server->event("server.time.change", array($this, "eventHandler"));
$this->evid[] = $this->server->event("server.chat", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.remove", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.move", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler"));
$this->evid[] = $this->server->event("player.equipment.change", array($this, "eventHandler"));
$this->evid[] = $this->server->event("player.item.pick", array($this, "eventHandler"));
$this->evid[] = $this->server->event("world.block.change", array($this, "eventHandler"));
console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2);
$this->eventHandler($this->server->motd, "server.chat");
if($this->MTU <= 548){
$this->eventHandler("Your connection is bad, you may experience lag and slow map loading.", "server.chat");
case MC_READY:
switch($data["status"]){
case 1:
if($this->spawned !== false){
break;
}
$this->spawned = true;
$this->entity = $this->server->api->entity->add(ENTITY_PLAYER, 0, array("player" => $this));
$this->eid = $this->entity->eid;
$this->server->query("UPDATE players SET EID = ".$this->eid." WHERE clientID = ".$this->clientID.";");
$this->entity->setName($this->username);
$this->entity->data["clientID"] = $this->clientID;
$this->server->api->entity->spawnAll($this);
$this->server->api->entity->spawnToAll($this->eid);
$this->evid[] = $this->server->event("server.time.change", array($this, "eventHandler"));
$this->evid[] = $this->server->event("server.chat", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.remove", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.move", array($this, "eventHandler"));
$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler"));
$this->evid[] = $this->server->event("player.equipment.change", array($this, "eventHandler"));
$this->evid[] = $this->server->event("player.item.pick", array($this, "eventHandler"));
$this->evid[] = $this->server->event("world.block.change", array($this, "eventHandler"));
console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2);
$this->eventHandler($this->server->motd, "server.chat");
if($this->MTU <= 548){
$this->eventHandler("Your connection is bad, you may experience lag and slow map loading.", "server.chat");
}
break;
case 2://Chunk loaded?
break;
}
break;
case MC_MOVE_PLAYER:
@ -334,7 +343,7 @@ class Player{
break;
case MC_USE_ITEM:
$data["eid"] = $this->eid;
if(Utils::distance($this->entity->position, $data) > 8){
if(Utils::distance($this->entity->position, $data) > 10){
break;
}
$this->server->handle("player.block.action", $data);

View File

@ -332,7 +332,7 @@ class PocketMinecraftServer extends stdClass{
}
public function clientID($ip, $port){
return md5($pi . $port, true);
return md5($ip . $port, true);
}
public function packetHandler($packet){
@ -542,4 +542,4 @@ class PocketMinecraftServer extends stdClass{
$this->query("DELETE FROM events WHERE ID = ".$id.";");
}
}
}

View File

@ -40,4 +40,4 @@ define("CURRENT_VERSION", 1);
define("LOG", true);
define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78");
define("TEST_MD5", "5ca8eced50a5801619f7ae86d631a4e7");
define("MAJOR_VERSION", "Alpha_1.0.3");
define("MAJOR_VERSION", "Alpha_1.0.4");

View File

@ -27,4 +27,5 @@ echo [ERROR] Couldn't find PHP binary in PATH.
ping 127.0.0.1 -n 3 -w 1000>nul
) else (
START /B /WAIT php -d enable_dl=On PocketMine-MP.php
)
)
pause