diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/messageout.cpp | 8 | ||||
-rw-r--r-- | src/net/network.cpp | 35 | ||||
-rw-r--r-- | src/net/network.h | 5 | ||||
-rw-r--r-- | src/net/protocol.cpp | 40 | ||||
-rw-r--r-- | src/net/protocol.h | 23 |
5 files changed, 41 insertions, 70 deletions
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index d25cc62b..aa7f06c4 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -37,7 +37,7 @@ MessageOut::MessageOut(): { // TODO: data not to be already allocated, keep it this way unitl full // conversion - mData = out; + mData = out + out_size; } MessageOut::~MessageOut() @@ -54,8 +54,8 @@ MessageOut::~MessageOut() void MessageOut::expand(size_t bytes) { - mData = (char*)realloc(mData, bytes); - mDataSize = bytes; + /*mData = (char*)realloc(mData, bytes); + mDataSize = bytes;*/ } void MessageOut::writeByte(char value) @@ -97,8 +97,6 @@ void MessageOut::writeString(const std::string &string, int length) { // Write the length at the start if not fixed writeShort(string.length()); - toWrite = string; - expand(mPos + string.length()); } else diff --git a/src/net/network.cpp b/src/net/network.cpp index 3b1d6569..4656a233 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -279,41 +279,6 @@ get_next_message() return MessageIn(in, length); } -void writeByte(int pos, unsigned char value)//writeByte(unsigned char value) -{ - (*(unsigned char *)(out + pos + out_size)) = value; - //out_size++; -} - -void writeWord(int pos, unsigned short value)//writeWord(unsigned short value) -{ -#ifdef MACOSX - (*(unsigned short *)(out + pos + out_size)) = DR_SwapTwoBytes(value); -#else - (*(unsigned short *)(out + pos + out_size)) = value; -#endif - //SDLNet_Write16(value, (out + (pos + out_size))); - //out_size += 2; -} - -void writeLong(int pos, unsigned int value)//writeLong(int value) -{ -#ifdef MACOSX - (*(unsigned int *)(out + pos + out_size)) = DR_SwapFourBytes(value); -#else - (*(unsigned int *)(out + pos + out_size)) = value; -#endif - //SDLNet_Write32((Uint32)value, (out + (pos + out_size))); - //out_size += 4; -} - -char *writePointer(int pos)//writeString(const std::string &string, int length) -{ - return (out+(pos+out_size)); - //memcpy((out + out_size), string.c_str(), length); - //out_size += length; -} - void writeSet(unsigned int value) { if (out_size + value >= buffer_size) { diff --git a/src/net/network.h b/src/net/network.h index b6c4a520..c6a4380b 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -44,11 +44,6 @@ void flush(); MessageIn get_next_message(); extern char *out; - -void writeByte(int pos, unsigned char value);//writeByte(char value); -void writeWord(int pos, unsigned short value);//writeWord(short value); -void writeLong(int pos, unsigned int value);//writeLong(int value); -char *writePointer(int pos); //writeString(const std::string &string, int length); void writeSet(unsigned int value); void skip(int len); diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp index 5a1ed9c5..2e4089d4 100644 --- a/src/net/protocol.cpp +++ b/src/net/protocol.cpp @@ -24,6 +24,7 @@ #include "protocol.h" #include "messagein.h" +#include "messageout.h" #include "network.h" #include "../being.h" @@ -78,12 +79,13 @@ void map_start() } // Send login infos - writeWord(0, 0x0072); - writeLong(2, account_ID); - writeLong(6, char_ID); - writeLong(10, session_ID1); - writeLong(14, session_ID2); - writeByte(18, sex); + MessageOut outMsg; + outMsg.writeShort(0x0072); + outMsg.writeLong(account_ID); + outMsg.writeLong(char_ID); + outMsg.writeLong(session_ID1); + outMsg.writeLong(session_ID2); + outMsg.writeByte(sex); writeSet(19); // Skip a mysterious 4 bytes @@ -113,34 +115,28 @@ void map_start() skip(msg.getLength()); // Send "map loaded" - writeWord(0, 0x007d); + // TODO: be able to reuse the same msg + MessageOut newMsg; + newMsg.writeShort(0x007d); writeSet(2); - flush(); } void walk(unsigned short x, unsigned short y, unsigned char direction) { char temp[3]; + MessageOut outMsg; set_coordinates(temp, x, y, direction); - writeWord(0, 0x0085); - memcpy(writePointer(2), temp, 3); + outMsg.writeShort(0x0085); + outMsg.writeString(temp, 3); writeSet(5); } -void speak(char *speech) -{ - int len = (int)strlen(speech); - writeWord(0, 0x008c); - writeWord(2, len + 4); - memcpy(writePointer(4), speech, len); - writeSet(len + 4); -} - void action(char type, int id) { - writeWord(0, 0x0089); - writeLong(2, id); - writeByte(6, type); + MessageOut outMsg; + outMsg.writeShort(0x0089); + outMsg.writeLong(id); + outMsg.writeByte(type); writeSet(7); } diff --git a/src/net/protocol.h b/src/net/protocol.h index 69b36783..8609530a 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -84,6 +84,26 @@ class Being; // Packets from client to server #define CMSG_TRADE_RESPONSE 0x00e6 +#define CMSG_ITEM_PICKUP 0x009f +#define CMSG_MAP_LOADED 0x007d +#define CMSG_NPC_BUY_REQUEST 0x00c8 +#define CMSG_NPC_BUY_SELL_REQUEST 0x00c5 +#define CMSG_CHAT_MESSAGE 0x008c +#define CMSG_NPC_LIST_CHOICE 0x00b8 +#define CMSG_NPC_NEXT_REQUEST 0x00b9 +#define CMSG_NPC_SELL_REQUEST 0x00c9 +#define CMSG_SKILL_LEVELUP_REQUEST 0x0112 +#define CMSG_STAT_UPDATE_REQUEST 0x00bb +#define CMSG_TRADE_ITEM_ADD_REQUEST 0x00e8 +#define CMSG_TRADE_CANCEL_REQUEST 0x00ed +#define CMSG_TRADE_ADD_COMPLETE 0x00eb +#define CMSG_TRADE_OK 0x00ef +#define CMSG_NPC_TALK 0x0090 +#define CMSG_TRADE_REQUEST 0x00e4 +#define CMSG_PLAYER_INVENTORY_USE 0x00a7 +#define CMSG_PLAYER_INVENTORY_DROP 0x00a2 +#define CMSG_PLAYER_EQUIP 0x00a9 +#define CMSG_PLAYER_UNEQUIP 0x00ab /** Decodes src direction */ @@ -101,9 +121,6 @@ void map_start(); /** Requests to walk */ void walk(unsigned short x, unsigned short y, unsigned char direction); -/** Request to speak */ -void speak(char *speech); - /** Request to attack */ Being* attack(unsigned short x, unsigned short y, unsigned char direction); |