Skip to content

Commit

Permalink
Pacotes colocados para o novo padrão A8 e A9. Adicionado novas funcoe…
Browse files Browse the repository at this point in the history
…s na classe packet.
  • Loading branch information
mbnunes committed Nov 18, 2018
1 parent ed3b806 commit 138e553
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 46 deletions.
52 changes: 13 additions & 39 deletions core/account.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,53 +233,27 @@ public function sendServerList($runInLot = false) {
* Enable locked client features
*/
public function enableLockedFeatures($runInLot = false) {
$packet = "B9";
$packet .= str_pad(dechex($this->featuresFlags), 8, "0", STR_PAD_LEFT);
Sockets::out($this->client, $packet, $runInLot);
$packet = new packet_0xB9($this->client);
$packet->setFlags(dechex($this->featuresFlags));
$packet->send();
}

/**
* Send the account characters list to the client
*/
public function sendCharacterList($runInLot = false) {
$characters = $this->characters;
$characters = $this->characters;
$startingLocations = UltimaPHP::$starting_locations;

$charLimit = 7;
$tmpPacket = "";

for ($i = 0; $i < $charLimit; $i++) {
if ($i < count($characters)) {
$tmpPacket .= str_pad((isset($characters[$i]) ? Functions::strToHex($characters[$i]['name']) : 0), 60, "0", STR_PAD_RIGHT);
$tmpPacket .= str_pad("00", 60, "0", STR_PAD_RIGHT);
} else {
$tmpPacket .= str_pad("00", 120, "0", STR_PAD_RIGHT);
}
}
$tmpPacket .= str_pad(dechex(count($startingLocations)), 2, "0", STR_PAD_LEFT);

foreach ($startingLocations as $key => $location) {
// If Client version is bigger then 7.0.13.0
$tmpPacket .= str_pad(dechex($key + 1), 2, "0", STR_PAD_LEFT);
$tmpPacket .= str_pad(strtoupper(Functions::strToHex($location['name'])), 64, "0", STR_PAD_RIGHT);
$tmpPacket .= str_pad(strtoupper(Functions::strToHex($location['area'])), 64, "0", STR_PAD_RIGHT);
$tmpPacket .= str_pad(strtoupper(dechex($location['position']['x'])), 8, "0", STR_PAD_LEFT);
$tmpPacket .= str_pad(strtoupper(dechex($location['position']['y'])), 8, "0", STR_PAD_LEFT);
$tmpPacket .= str_pad(strtoupper(dechex($location['position']['z'])), 8, "0", STR_PAD_LEFT);
$tmpPacket .= str_pad(strtoupper(dechex($location['position']['map'])), 8, "0", STR_PAD_LEFT);
$tmpPacket .= str_pad(strtoupper(dechex($location['clioc'])), 8, "0", STR_PAD_LEFT);
$tmpPacket .= str_pad("", 8, "0", STR_PAD_RIGHT);
}

$tmpPacket .= str_pad(dechex($this->charListFlags), 8, "0", STR_PAD_LEFT);
$tmpPacket .= "0000";

$packet = "A9";
$packet .= str_pad(dechex(ceil(strlen($tmpPacket) / 2) + 4), 4, "0", STR_PAD_LEFT);
$packet .= "07";
$packet .= $tmpPacket;

Sockets::out($this->client, $packet, $runInLot);
$newPacket = new packet_0xA9($this->client);
$newPacket->setCharCount(7);
$newPacket->setChars($characters);
$newPacket->setCitiesCount(count($startingLocations));
$newPacket->setCities($startingLocations);
$newPacket->setFlags($this->charListFlags);
$newPacket->setLastCharLost(0);
$newPacket->send();

}

/**
Expand Down
15 changes: 10 additions & 5 deletions core/packets.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function getPacketStr() {

public function addText($text = "", $maxByteSyze = false, $fill_zeros = true, $pad_direction = STR_PAD_RIGHT) {
$hexStr = str_split(str_pad(Functions::strToHex($text), ($maxByteSyze ? ($maxByteSyze * 2) : $maxByteSyze), "0", $pad_direction), 2);

foreach ($hexStr as $hex) {
$this->packetBytes[] = $hex;
}
Expand Down Expand Up @@ -96,7 +95,7 @@ public function addUInt16($value = 0) {

public function addInt16($value = 0) {
$hexStr = str_split($this->int16($value), 2);

foreach ($hexStr as $hex) {
$this->packetBytes[] = $hex;
}
Expand Down Expand Up @@ -218,10 +217,16 @@ public static function getSByte(&$var)
{
$packet = array_slice($var, 0, 1);
$var = array_slice($var,1);

var_dump($packet);
var_dump(implode($packet));

return Functions::fromChar8(implode($packet));
}

public static function getUnicodeStringSafe($sendString, $byteSize = 30)
{
$text = "";

$text = str_pad(strtoupper(Functions::strToHex($sendString)), $byteSize*2, "0", STR_PAD_RIGHT);

return $text;
}
}
71 changes: 69 additions & 2 deletions core/packets/0x6C.packet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

class packet_0x6C extends Packets {

private $type;
private $senderSerial;
private $flags;
private $objectSerial;
private $X;
private $Y;
private $Z;
private $graphic;

/**
* Defines the packet, the length and if there is a client send
*/
Expand Down Expand Up @@ -38,9 +47,67 @@ public function receive($data) {
'graphic' => hexdec($this->getInt16($data)),
];

print_r($targetData);

UltimaPHP::$socketClients[$this->client]['account']->player->targetAction($this->client, $targetData);

}

/**s
* Handle the packet transmission
*/
public function send() {
if (!$this->client) {
return false;
}

$this->addInt8($this->type);
$this->addInt32($this->senderSerial);
$this->addInt8($this->flags);
$this->addInt32($this->objectSerial);
$this->addInt16($this->X);
$this->addInt16($this->Y);
$this->addInt16($this->Z);
$this->addInt16($this->graphic);

return Sockets::out($this->client, $this);
}

public function setType($type){
$this->type = $type;
return true;
}

public function setSenderSerial($senderSerial){
$this->senderSerial = $senderSerial;
return true;
}

public function setFlags($flags){
$this->flags = $flags;
return true;
}

public function setObjectSerial($objectSerial){
$this->objectSerial = $objectSerial;
return true;
}

public function setX($X){
$this->X = $X;
return true;
}

public function setY($Y){
$this->Y = $Y;
return true;
}

public function setZ($Z){
$this->Z = $Z;
return true;
}

public function setGraphic($graphic){
$this->graphic = $graphic;
return true;
}
}
105 changes: 105 additions & 0 deletions core/packets/0xA9.packet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php
/**
* Ultima PHP - OpenSource Ultima Online Server written in PHP
* Version: 0.1 - Pre Alpha
*
* Send the server list to the client
*/
class packet_0xA9 extends Packets {

private $sizePacket;
private $charCount;
private $chars;
private $citiesCount;
private $cities;
private $flags;
private $lastCharLost;
/**
* Defines the packet, the length and if there is a client send
*/
public function __construct($client = false) {
$this->setPacket(0xA9);

if ($client) {
$this->client = $client;
}
}

/**s
* Handle the packet receive
*/
public function send() {
if (!$this->client) {
return false;
}

$this->addInt8($this->charCount);

for($i=0;$i<$this->charCount;$i++)
{
if ($i < count($this->chars)) {
$this->addText($this->chars[$i]['name'], 30);
$this->addText("", 30);
} else {
$this->addText("", 60);
}
}

$this->addInt8(dechex($this->citiesCount));

foreach ($this->cities as $key => $location)
{
$this->addInt8(dechex($key+1));
$this->addText($location['name'], 32);
$this->addText($location['area'], 32);
$this->addInt32(dechex($location['position']['x']));
$this->addInt32(dechex($location['position']['y']));
$this->addInt32(dechex($location['position']['z']));
$this->addInt32(dechex($location['position']['map']));
$this->addUInt32(dechex($location['cliloc']));
$this->addInt32(0);
}


$this->addInt32(dechex($this->flags));
$this->addInt16($this->lastCharLost);

Sockets::out($this->client, $this);
return true;
}

public function setSizePacket($sizePacket) {
$this->sizePacket = $sizePacket;
return true;
}

public function setCharCount($charCount) {
$this->charCount = (int)$charCount;
return true;
}

public function setChars($chars) {
$this->chars = $chars;
return true;
}

public function setCitiesCount($citiesCount) {
$this->citiesCount = (int)$citiesCount;
return true;
}

public function setCities($cities) {
$this->cities = $cities;
return true;
}

public function setFlags($flags) {
$this->flags = $flags;
return true;
}

public function setLastCharLost($lastCharLost) {
$this->lastCharLost = (int)$lastCharLost;
return true;
}
}
41 changes: 41 additions & 0 deletions core/packets/0xB9.packet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Ultima PHP - OpenSource Ultima Online Server written in PHP
* Version: 0.1 - Pre Alpha
*/

class packet_0xB9 extends Packets {

private $flags;

/**
* Defines the packet, the length and if there is a client send
*/
public function __construct($client = false) {
$this->setPacket(0xB9);
$this->setLength(5);

if ($client) {
$this->client = $client;
}

}

/**
* Handle the packet sending
*/
public function send() {
if (!$this->client) {
return false;
}

$this->addInt32($this->flags);

return Sockets::out($this->client, $this);
}

public function setFlags($flags) {
$this->flags = $flags;
return true;
}
}

0 comments on commit 138e553

Please sign in to comment.