Skip to content

Commit

Permalink
Changes for 1.3.1 -> 1.4.6 protocol (not complete)
Browse files Browse the repository at this point in the history
 * Pickup spawn fixed
 * Reading new field (showcape) from client info
 * Time update packet fixed
 * Fixed server ping reply
  • Loading branch information
fador committed Dec 29, 2012
1 parent 7a12610 commit 8ca6578
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 29 deletions.
1 change: 1 addition & 0 deletions include/constants.h
Expand Up @@ -85,6 +85,7 @@ extern const unsigned int SERVER_CONSOLE_UID;
extern const std::string VERSION; extern const std::string VERSION;


extern const int PROTOCOL_VERSION; extern const int PROTOCOL_VERSION;
extern const std::string MINECRAFT_VERSION;


extern const char COMMENTPREFIX; extern const char COMMENTPREFIX;


Expand Down
35 changes: 29 additions & 6 deletions include/protocol.h
Expand Up @@ -198,11 +198,12 @@ class Protocol
return ret; return ret;
} }


static Packet loginResponse(int eid) //ToDo: remember gamemode for players
static Packet loginResponse(int eid, int8_t gamemode = 0)
{ {
Packet ret; Packet ret;
ret << (int8_t)PACKET_LOGIN_RESPONSE << (int32_t)eid ret << (int8_t)PACKET_LOGIN_RESPONSE << (int32_t)eid
<< std::string("default") << (int8_t)0 << (int8_t)0 << std::string("default") << (int8_t)gamemode << (int8_t)0
<< (int8_t)2 << (int8_t)0 << (int8_t)ServerInstance->config()->iData("system.user_limit"); << (int8_t)2 << (int8_t)0 << (int8_t)ServerInstance->config()->iData("system.user_limit");
return ret; return ret;
} }
Expand All @@ -214,10 +215,11 @@ class Protocol
return ret; return ret;
} }


static Packet timeUpdate(int64_t time) //ToDo: use age of the world field somewhere
static Packet timeUpdate(int64_t time, int64_t ageOfTheWorld = 0)
{ {
Packet ret; Packet ret;
ret << (int8_t)PACKET_TIME_UPDATE << (int64_t)time; ret << (int8_t)PACKET_TIME_UPDATE << (int64_t)ageOfTheWorld << (int64_t)time;
return ret; return ret;
} }


Expand Down Expand Up @@ -245,11 +247,32 @@ class Protocol
return ret; return ret;
} }


static Packet addObject(int eid, int8_t object, double x, double y, double z, int objectData, int16_t speed_x = 0, int16_t speed_y = 0,int16_t speed_z = 0) static Packet pickupSpawn(int eid, int16_t item, int16_t count, int16_t health, int32_t x, int32_t y, int32_t z)
{
MetaData metadata;

Packet ret;
ret << addObject(eid, 0x02, x/32, y/32, z/32,0) ;
//Add metadata
//ToDo: expand metadata-class to handle this

//Ref: https://gist.github.com/4325656
ret << (int8_t)PACKET_ENTITY_METADATA << eid;
//ret << (int16_t)0; //Char \0 at index 0
//ret << (int8_t)0x21 << (int16_t)300; //Short 300 at index 1
ret << (int8_t)0xAA /*Slot at index 10 */;
ret << slot(item,(int8_t)count,health);
ret << (int8_t)0x7f; //Terminate metadata
return ret;
}

static Packet addObject(int eid, int8_t object, double x, double y, double z, int objectData, int16_t speed_x = 0, int16_t speed_y = 0,int16_t speed_z = 0, int8_t yaw = 0, int8_t pitch = 0)
{ {
Packet pkt; Packet pkt;
pkt //<< (int8_t)PACKET_ENTITY << (int32_t)eid pkt //<< (int8_t)PACKET_ENTITY << (int32_t)eid
<< (int8_t)PACKET_ADD_OBJECT << (int32_t)eid << (int8_t)object << (int32_t)(x * 32 + 16) << (int32_t)(y * 32 + 16) << (int32_t)(z * 32 + 16) << (int32_t)objectData; << (int8_t)PACKET_ADD_OBJECT << (int32_t)eid << (int8_t)object << (int32_t)(x * 32 + 16) << (int32_t)(y * 32 + 16) << (int32_t)(z * 32 + 16)
<< yaw << pitch
<< (int32_t)objectData;
if(objectData) if(objectData)
{ {
pkt << (int16_t)speed_x << (int16_t)speed_y << (int16_t)speed_z; pkt << (int16_t)speed_x << (int16_t)speed_y << (int16_t)speed_z;
Expand Down
3 changes: 2 additions & 1 deletion src/constants.cpp
Expand Up @@ -36,7 +36,8 @@ const unsigned int SERVER_CONSOLE_UID = -1;


const std::string VERSION = "0.1.18 (Alpha)"; const std::string VERSION = "0.1.18 (Alpha)";


const int PROTOCOL_VERSION = 39; const int PROTOCOL_VERSION = 51;
const std::string MINECRAFT_VERSION = "1.4.6";


const char COMMENTPREFIX = '#'; const char COMMENTPREFIX = '#';


Expand Down
6 changes: 6 additions & 0 deletions src/inventory.cpp
Expand Up @@ -54,11 +54,17 @@ void Item::sendUpdate()
} }
if (slot >= 5 && slot <= 8) if (slot >= 5 && slot <= 8)
{ {
//ToDo: Check: With slotID == 4, client crashed -Fador 2012-12-29
if((5 - (slot - 4)) != 4)
{
//std::cout << "slot: " << (5 - (slot - 4)) << " item: " << type << " count: " << count << " health: " << health << std::endl;
Packet pkt; Packet pkt;
pkt << (int8_t)PACKET_ENTITY_EQUIPMENT << (int32_t)player->UID pkt << (int8_t)PACKET_ENTITY_EQUIPMENT << (int32_t)player->UID
<< (int16_t)(5 - (slot - 4)) << Protocol::slot(type,count,health);//<< (int16_t)type << (int16_t) 0; << (int16_t)(5 - (slot - 4)) << Protocol::slot(type,count,health);//<< (int16_t)type << (int16_t) 0;
player->sendAll(pkt); player->sendAll(pkt);
}
} }

int window = 0; int window = 0;
int t_slot = slot; int t_slot = slot;
if (slot == -1) if (slot == -1)
Expand Down
8 changes: 3 additions & 5 deletions src/map.cpp
Expand Up @@ -38,6 +38,7 @@
#include "tree.h" #include "tree.h"
#include "furnaceManager.h" #include "furnaceManager.h"
#include "mcregion.h" #include "mcregion.h"
#include "protocol.h"


// Copy Construtor // Copy Construtor
Map::Map(const Map& oldmap) Map::Map(const Map& oldmap)
Expand Down Expand Up @@ -1017,11 +1018,8 @@ bool Map::sendPickupSpawn(spawnedItem item)
it->second->items.push_back(storedItem); it->second->items.push_back(storedItem);


Packet pkt; Packet pkt;

pkt << Protocol::pickupSpawn(item.EID, item.item, item.count, item.health,item.pos.x(), item.pos.y(),item.pos.z());
pkt << (int8_t)PACKET_PICKUP_SPAWN << (int32_t)item.EID << (int16_t)item.item << (int8_t)item.count << (int16_t)item.health
<< (int32_t)item.pos.x() << (int32_t)item.pos.y() << (int32_t)item.pos.z()
<< (int8_t)0 << (int8_t)0 << (int8_t)0;

it->second->sendPacket(pkt); it->second->sendPacket(pkt);


return true; return true;
Expand Down
5 changes: 3 additions & 2 deletions src/mineserver.cpp
Expand Up @@ -723,12 +723,14 @@ bool Mineserver::run()
tick = (uint32_t)timeNow; tick = (uint32_t)timeNow;


// Loop users // Loop users
for (std::set<User*>::iterator it = m_users.begin(); it != m_users.end(); it++) for (std::set<User*>::iterator it = m_users.begin(); it != m_users.end(); )
{ {
// NOTE: iterators corrupt when you delete their objects, therefore we have to iterate in a special way - Justasic // NOTE: iterators corrupt when you delete their objects, therefore we have to iterate in a special way - Justasic
/// BIGGER NOTE: Justasic is dumb /// BIGGER NOTE: Justasic is dumb


User * const & u = *it; User * const & u = *it;
//Increment before anything gets deleted
it++;
// No data received in 30s, timeout // No data received in 30s, timeout
if (u->logged && timeNow - u->lastData > 30) if (u->logged && timeNow - u->lastData > 30)
{ {
Expand All @@ -746,7 +748,6 @@ bool Mineserver::run()
u->pushMap(); u->pushMap();
u->popMap(); u->popMap();
} }

} }


for (std::vector<Map*>::size_type i = 0 ; i < m_map.size(); i++) for (std::vector<Map*>::size_type i = 0 ; i < m_map.size(); i++)
Expand Down
38 changes: 27 additions & 11 deletions src/packets.cpp
Expand Up @@ -320,16 +320,16 @@ int PacketHandler::client_info(User* user)
} }


std::string locale; std::string locale;
int8_t viewDistance,chatFlags,difficulty; int8_t viewDistance,chatFlags,difficulty,showCape;


user->buffer >> locale; user->buffer >> locale;


if (!user->buffer || !user->buffer.haveData(3)) if (!user->buffer || !user->buffer.haveData(4))
{ {
return PACKET_NEED_MORE_DATA; return PACKET_NEED_MORE_DATA;
} }


user->buffer >> viewDistance >> chatFlags >> difficulty; user->buffer >> viewDistance >> chatFlags >> difficulty >> showCape;


user->buffer.removePacket(); user->buffer.removePacket();


Expand Down Expand Up @@ -1514,17 +1514,33 @@ int PacketHandler::use_entity(User* user)
} }




// Keep Alive (http://mc.kev009.com/wiki/Protocol) // Serverlist ping (http://wiki.vg/Server_List_Ping)
int PacketHandler::ping(User* user) int PacketHandler::ping(User* user)
{ {
//Reply with server info //Read the new magic field in the 1.4 protocol
int8_t magic;
user->buffer >> magic;
user->buffer.removePacket(); user->buffer.removePacket();


std::ostringstream line; //Reply with server info
line << ServerInstance->config()->sData("system.server_name") << "§" std::string line;
<< ServerInstance->getLoggedUsersCount() << "§"
<< ServerInstance->config()->iData("system.user_limit"); //Insert \1 instead of null char \0, then replace it later
user->kick(line.str()); line = "§1\1" +
my_itoa(PROTOCOL_VERSION) + "\1" +
MINECRAFT_VERSION + "\1" +
ServerInstance->config()->sData("system.server_name") + "\1" +
my_itoa(ServerInstance->getLoggedUsersCount()) + "\1" +
my_itoa(ServerInstance->config()->iData("system.user_limit"));
//Replacing \1 with \0
for(unsigned int i = 0; i < line.size();i++)
{
if(line[i] == '\1')
{
line[i] = '\0';
}
}
user->kick(line);


return PACKET_OK; return PACKET_OK;
} }
Expand Down
3 changes: 2 additions & 1 deletion src/plugin_api.cpp
Expand Up @@ -31,6 +31,7 @@
#include "logger.h" #include "logger.h"
#include "chat.h" #include "chat.h"
#include "permissions.h" #include "permissions.h"
#include "protocol.h"


#include "plugin.h" #include "plugin.h"
#include "config.h" #include "config.h"
Expand Down Expand Up @@ -285,7 +286,7 @@ bool map_setTime(int timeValue)
{ {
ServerInstance->map(0)->mapTime = timeValue; ServerInstance->map(0)->mapTime = timeValue;
Packet pkt; Packet pkt;
pkt << (int8_t)PACKET_TIME_UPDATE << (int64_t)ServerInstance->map(0)->mapTime; pkt << Protocol::timeUpdate(ServerInstance->map(0)->mapTime);


if (!User::all().empty()) if (!User::all().empty())
{ {
Expand Down
4 changes: 1 addition & 3 deletions src/user.cpp
Expand Up @@ -244,15 +244,13 @@ bool User::sendLoginInfo()


logged = true; logged = true;
spawnUser((int32_t)pos.x * 32, (int32_t)((pos.y + 2) * 32), (int32_t)pos.z * 32); spawnUser((int32_t)pos.x * 32, (int32_t)((pos.y + 2) * 32), (int32_t)pos.z * 32);



for (int i = 1; i < 45; i++) for (int i = 1; i < 45; i++)
{ {
inv[i].ready = true; inv[i].ready = true;
inv[i].sendUpdate(); inv[i].sendUpdate();
} }



// Teleport player (again) // Teleport player (again)
teleport(pos.x, pos.y + 2, pos.z); teleport(pos.x, pos.y + 2, pos.z);


Expand Down

0 comments on commit 8ca6578

Please sign in to comment.