diff options
Diffstat (limited to 'src/net/protocol.cpp')
-rw-r--r-- | src/net/protocol.cpp | 188 |
1 files changed, 52 insertions, 136 deletions
diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp index ce27b7ea..17076b90 100644 --- a/src/net/protocol.cpp +++ b/src/net/protocol.cpp @@ -23,10 +23,6 @@ #include "protocol.h" -#ifndef WIN32 -#include "win2linux.h" -#endif - #include "network.h" #include "../being.h" @@ -36,111 +32,24 @@ #include "../playerinfo.h" #include "../sound.h" +#define LOBYTE(w) ((unsigned char)(w)) +#define HIBYTE(w) ((unsigned char)(((unsigned short)(w)) >> 8)) -short packet_lengths[] = { - 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -// #0x0040 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2, - 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6, -// #0x0080 - 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 23, -1, -1, -1, 0, - 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6, - 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6, - 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3, -// #0x00C0 - 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 6, 2, 27, - 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1, - 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2, - 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10, -// #0x0100 - 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1, - 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16, - 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1, - 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26, -// #0x0140 - 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6, - 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42, - -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182, - 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1, -// #0x0180 - 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6, - 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, 4, 6, 2, 6, - 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4, - 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3, -// #0x01C0 - 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 0, 9, 9, 29, 6, 28, - 8, 14, 10, 35, 6, 8, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6, - 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1, - -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10, -// #0x200 - 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -short get_length(short id) { - return packet_lengths[id]; -} - -unsigned short get_dest_x(const char *data) { - short temp; - temp = MAKEWORD(data[3], data[2] & 0x000f); - temp >>= 2; - return temp; -} - -unsigned short get_dest_y(const char *data) { - return MAKEWORD(data[4], data[3] & 0x0003); -} - -unsigned short get_src_x(const char *data) { - short temp; - temp = MAKEWORD(data[1], data[0]); - temp >>= 6; - return temp; -} - -unsigned short get_src_y(const char *data) { - short temp; - temp = MAKEWORD(data[2], data[1] & 0x003f); - temp >>= 4; - return temp; -} - -unsigned char get_src_direction(char data) { +unsigned char get_src_direction(char data) +{ data >>= 4; return data; } -unsigned char get_dest_direction(char data) { +unsigned char get_dest_direction(char data) +{ return data & 0x000f; } -unsigned short get_x(const char *data) { - short temp; - temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff); - temp >>= 6; - return temp; -} - -unsigned short get_y(const char *data) { - short temp; - if (!data) throw "Corrupted data"; - temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f); - temp >>= 4; - return temp; -} - -unsigned char get_direction(const char *data) { - return data[2] & 0x000f; -} - -void set_coordinates(char *data, unsigned short x, unsigned short y, - unsigned char direction) +void set_coordinates(char *data, + unsigned short x, + unsigned short y, + unsigned char direction) { short temp; temp = x; @@ -149,7 +58,7 @@ void set_coordinates(char *data, unsigned short x, unsigned short y, data[1] = 1; data[2] = 2; data[0] = HIBYTE(temp); - data[1] = LOBYTE(temp); + data[1] = (unsigned char)(temp); temp = y; temp <<= 4; data[1] |= HIBYTE(temp); @@ -160,7 +69,7 @@ void set_coordinates(char *data, unsigned short x, unsigned short y, void map_start() { // Connect to map server - if (open_session(iptostring(map_address), map_port) == SOCKET_ERROR) + if (open_session(iptostring(map_address), map_port) == -1) { logger->log("Warning: Unable to connect to map server"); throw "Unable to connect to map server"; @@ -168,63 +77,70 @@ void map_start() } // Send login infos - WFIFOW(0) = net_w_value(0x0072); - WFIFOL(2) = net_l_value(account_ID); - WFIFOL(6) = net_l_value(char_ID); - WFIFOL(10) = net_l_value(session_ID1); - WFIFOL(14) = net_l_value(session_ID2); - WFIFOB(18) = net_b_value(sex); - WFIFOSET(19); - + writeWord(0, 0x0072); + writeLong(2, account_ID); + writeLong(6, char_ID); + writeLong(10, session_ID1); + writeLong(14, session_ID2); + writeByte(18, sex); + writeSet(19); + + // Skip a mysterious 4 bytes while ((in_size < 4)|| (out_size > 0)) flush(); - RFIFOSKIP(4); + skip(4); - while (in_size < 2) flush(); + MessageIn msg = get_next_message(); - if (RFIFOW(0) == SMSG_LOGIN_SUCCESS) { - while (in_size < 11) flush(); - startX = get_x(RFIFOP(6)); - startY = get_y(RFIFOP(6)); - int direction = get_direction(RFIFOP(6)); + if (msg.getId() == SMSG_LOGIN_SUCCESS) + { + unsigned char direction; + msg.readLong(); // server tick + msg.readCoordinates(startX, startY, direction); + msg.skip(2); // unknown logger->log("Protocol: Player start position: (%d, %d), Direction: %d", startX, startY, direction); - RFIFOSKIP(11); - } else if (0x0081) { + } + else if (msg.getId() == 0x0081) + { logger->log("Warning: Map server D/C"); - } else { + } + else + { logger->error("Unknown packet: map_start"); } + skip(msg.getLength()); + // Send "map loaded" - WFIFOW(0) = net_w_value(0x007d); - WFIFOSET(2); - while (out_size > 0) flush(); + writeWord(0, 0x007d); + writeSet(2); + flush(); } void walk(unsigned short x, unsigned short y, unsigned char direction) { char temp[3]; set_coordinates(temp, x, y, direction); - WFIFOW(0) = net_w_value(0x0085); - memcpy(WFIFOP(2), temp, 3); - WFIFOSET(5); + writeWord(0, 0x0085); + memcpy(writePointer(2), temp, 3); + writeSet(5); } void speak(char *speech) { int len = (int)strlen(speech); - WFIFOW(0) = net_w_value(0x008c); - WFIFOW(2) = net_w_value(len + 4); - memcpy(WFIFOP(4), speech, len); - WFIFOSET(len + 4); + writeWord(0, 0x008c); + writeWord(2, len + 4); + memcpy(writePointer(4), speech, len); + writeSet(len + 4); } void action(char type, int id) { - WFIFOW(0) = net_w_value(0x0089); - WFIFOL(2) = net_l_value(id); - WFIFOB(6) = net_b_value(type); - WFIFOSET(7); + writeWord(0, 0x0089); + writeLong(2, id); + writeByte(6, type); + writeSet(7); } Being* attack(unsigned short x, unsigned short y, unsigned char direction) @@ -278,7 +194,7 @@ void attack(Being *target) } // Implement charging attacks here - char_info->lastAttackTime = 0; + player_info->lastAttackTime = 0; player_node->action = Being::ATTACK; action(0, target->getId()); |