Permalink
Browse files

Changes for 1.3.1 -> 1.4.6 protocol (not complete)

 * Pickup spawn fixed
 * Reading new field (showcape) from client info
 * Time update packet fixed
 * Fixed server ping reply
  • Loading branch information...
1 parent 7a12610 commit 8ca6578caae3c4383dec20f82b2c7a8687c613df @fador committed Dec 29, 2012
Showing with 74 additions and 29 deletions.
  1. +1 −0 include/constants.h
  2. +29 −6 include/protocol.h
  3. +2 −1 src/constants.cpp
  4. +6 −0 src/inventory.cpp
  5. +3 −5 src/map.cpp
  6. +3 −2 src/mineserver.cpp
  7. +27 −11 src/packets.cpp
  8. +2 −1 src/plugin_api.cpp
  9. +1 −3 src/user.cpp
View
@@ -85,6 +85,7 @@ extern const unsigned int SERVER_CONSOLE_UID;
extern const std::string VERSION;
extern const int PROTOCOL_VERSION;
+extern const std::string MINECRAFT_VERSION;
extern const char COMMENTPREFIX;
View
@@ -198,11 +198,12 @@ class Protocol
return ret;
}
- static Packet loginResponse(int eid)
+ //ToDo: remember gamemode for players
+ static Packet loginResponse(int eid, int8_t gamemode = 0)
{
Packet ret;
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");
return ret;
}
@@ -214,10 +215,11 @@ class Protocol
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;
- ret << (int8_t)PACKET_TIME_UPDATE << (int64_t)time;
+ ret << (int8_t)PACKET_TIME_UPDATE << (int64_t)ageOfTheWorld << (int64_t)time;
return ret;
}
@@ -245,11 +247,32 @@ class Protocol
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;
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)
{
pkt << (int16_t)speed_x << (int16_t)speed_y << (int16_t)speed_z;
View
@@ -36,7 +36,8 @@ const unsigned int SERVER_CONSOLE_UID = -1;
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 = '#';
View
@@ -54,11 +54,17 @@ void Item::sendUpdate()
}
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;
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;
player->sendAll(pkt);
+ }
}
+
int window = 0;
int t_slot = slot;
if (slot == -1)
View
@@ -38,6 +38,7 @@
#include "tree.h"
#include "furnaceManager.h"
#include "mcregion.h"
+#include "protocol.h"
// Copy Construtor
Map::Map(const Map& oldmap)
@@ -1017,11 +1018,8 @@ bool Map::sendPickupSpawn(spawnedItem item)
it->second->items.push_back(storedItem);
Packet pkt;
-
- 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;
-
+ pkt << Protocol::pickupSpawn(item.EID, item.item, item.count, item.health,item.pos.x(), item.pos.y(),item.pos.z());
+
it->second->sendPacket(pkt);
return true;
View
@@ -723,12 +723,14 @@ bool Mineserver::run()
tick = (uint32_t)timeNow;
// 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
/// BIGGER NOTE: Justasic is dumb
User * const & u = *it;
+ //Increment before anything gets deleted
+ it++;
// No data received in 30s, timeout
if (u->logged && timeNow - u->lastData > 30)
{
@@ -746,7 +748,6 @@ bool Mineserver::run()
u->pushMap();
u->popMap();
}
-
}
for (std::vector<Map*>::size_type i = 0 ; i < m_map.size(); i++)
View
@@ -320,16 +320,16 @@ int PacketHandler::client_info(User* user)
}
std::string locale;
- int8_t viewDistance,chatFlags,difficulty;
+ int8_t viewDistance,chatFlags,difficulty,showCape;
user->buffer >> locale;
- if (!user->buffer || !user->buffer.haveData(3))
+ if (!user->buffer || !user->buffer.haveData(4))
{
return PACKET_NEED_MORE_DATA;
}
- user->buffer >> viewDistance >> chatFlags >> difficulty;
+ user->buffer >> viewDistance >> chatFlags >> difficulty >> showCape;
user->buffer.removePacket();
@@ -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)
{
- //Reply with server info
+ //Read the new magic field in the 1.4 protocol
+ int8_t magic;
+ user->buffer >> magic;
user->buffer.removePacket();
-
- std::ostringstream line;
- line << ServerInstance->config()->sData("system.server_name") << "§"
- << ServerInstance->getLoggedUsersCount() << "§"
- << ServerInstance->config()->iData("system.user_limit");
- user->kick(line.str());
+
+ //Reply with server info
+ std::string line;
+
+ //Insert \1 instead of null char \0, then replace it later
+ 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;
}
View
@@ -31,6 +31,7 @@
#include "logger.h"
#include "chat.h"
#include "permissions.h"
+#include "protocol.h"
#include "plugin.h"
#include "config.h"
@@ -285,7 +286,7 @@ bool map_setTime(int timeValue)
{
ServerInstance->map(0)->mapTime = timeValue;
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())
{
View
@@ -244,15 +244,13 @@ bool User::sendLoginInfo()
logged = true;
spawnUser((int32_t)pos.x * 32, (int32_t)((pos.y + 2) * 32), (int32_t)pos.z * 32);
-
-
+
for (int i = 1; i < 45; i++)
{
inv[i].ready = true;
inv[i].sendUpdate();
}
-
// Teleport player (again)
teleport(pos.x, pos.y + 2, pos.z);

0 comments on commit 8ca6578

Please sign in to comment.