summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-03 16:13:12 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-03 16:13:12 +0000
commit182b5231ba13a0a5865a1b7dcb4731c3009d4c57 (patch)
treed0f536d7c3357825efc5f527922c10487517e8bf /src/net
parentb48b39c87da9fc2c59be533e1dc445cc82c2f323 (diff)
downloadmana-182b5231ba13a0a5865a1b7dcb4731c3009d4c57.tar.gz
mana-182b5231ba13a0a5865a1b7dcb4731c3009d4c57.tar.bz2
mana-182b5231ba13a0a5865a1b7dcb4731c3009d4c57.tar.xz
mana-182b5231ba13a0a5865a1b7dcb4731c3009d4c57.zip
Some indent, comment and const parameter changes.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/protocol.cpp288
-rw-r--r--src/net/protocol.h53
2 files changed, 177 insertions, 164 deletions
diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp
index e1c1af9a..7b4c9ced 100644
--- a/src/net/protocol.cpp
+++ b/src/net/protocol.cpp
@@ -17,12 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
*/
#include "protocol.h"
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,
@@ -64,186 +65,165 @@ short packet_lengths[] = {
-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,
-
};
-/** Packet length by id */
short get_length(short id) {
- return packet_lengths[id];
+ return packet_lengths[id];
}
-/** Decodes dest x coord */
-unsigned short get_dest_x(char *data) {
- short temp;
- temp = MAKEWORD(data[3], data[2] & 0x000f);
- temp >>= 2;
- return temp;
+unsigned short get_dest_x(const char *data) {
+ short temp;
+ temp = MAKEWORD(data[3], data[2] & 0x000f);
+ temp >>= 2;
+ return temp;
}
-/** Decodes dest y coord */
-unsigned short get_dest_y(char *data) {
- short temp;
- temp = MAKEWORD(data[4], data[3] & 0x0003);
- return temp;
+unsigned short get_dest_y(const char *data) {
+ return MAKEWORD(data[4], data[3] & 0x0003);
}
-/** Decodes src x coord */
-unsigned short get_src_x(char *data) {
- short temp;
- temp = MAKEWORD(data[1], data[0]);
- temp >>= 6;
- return temp;
+unsigned short get_src_x(const char *data) {
+ short temp;
+ temp = MAKEWORD(data[1], data[0]);
+ temp >>= 6;
+ return temp;
}
-/** Decodes src y coord */
-unsigned short get_src_y(char *data) {
- short temp;
- temp = MAKEWORD(data[2], data[1] & 0x003f);
- temp >>= 4;
- return temp;
+unsigned short get_src_y(const char *data) {
+ short temp;
+ temp = MAKEWORD(data[2], data[1] & 0x003f);
+ temp >>= 4;
+ return temp;
}
-/** Decodes src direction */
unsigned char get_src_direction(char data) {
- data >>= 4;
+ data >>= 4;
return data;
}
-/** Decodes dest direction */
unsigned char get_dest_direction(char data) {
- return data & 0x000f;
-}
-
-/** Decodes x coord */
-unsigned short get_x(char *data) {
- short temp;
- temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff);
- temp >>= 6;
- return temp;
-}
-
-/** Decodes y coord */
-unsigned short get_y(char *data) {
- short temp;
- if(!data)error("Corrupted data");
- temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f);
- if(!temp)error("Corrupted data");
- temp >>= 4;
- return temp;
-}
-
-/** Decodes direction */
-unsigned char get_direction(char *data) {
- char temp;
- temp = data[2] & 0x000f;
- return temp;
-}
-
-/** Encodes coords and direction in 3 bytes data */
-void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction) {
- short temp;
- temp = x;
- temp <<= 6;
- data[0] = 0;
- data[1] = 1;
- data[2] = 2;
- data[0] = HIBYTE(temp);
- data[1] = LOBYTE(temp);
- temp = y;
- temp <<= 4;
- data[1] |= HIBYTE(temp);
- data[2] = LOBYTE(temp);
- data[2] |= direction;
-}
-
-/** Initialize connection with map server */
+ 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)error("Corrupted data");
+ temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f);
+ if(!temp)error("Corrupted data");
+ 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)
+{
+ short temp;
+ temp = x;
+ temp <<= 6;
+ data[0] = 0;
+ data[1] = 1;
+ data[2] = 2;
+ data[0] = HIBYTE(temp);
+ data[1] = LOBYTE(temp);
+ temp = y;
+ temp <<= 4;
+ data[1] |= HIBYTE(temp);
+ data[2] = LOBYTE(temp);
+ data[2] |= direction;
+}
+
void map_start() {
- // Connect to map server
- if(open_session(iptostring(map_address), map_port)==SOCKET_ERROR) {
- warning("Unable to connect to map server");
- state = LOGIN;
- ok("Error", "Unable to connect to map server");
- return;
- }
-
- // 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);
-
- while((in_size<4)||(out_size>0))flush();
- RFIFOSKIP(4);
-
- while(in_size<2)flush();
-
- if(RFIFOW(0)==0x0073) {
- while(in_size<11)flush();
- x = get_x(RFIFOP(6));
- y = get_y(RFIFOP(6));
- //direction = get_direction(RFIFOP(6));
- log("Protocol", "Player position: (%d, %d), Direction: %d",
- x, y, direction);
- RFIFOSKIP(11);
- } else if(0x0081) {
- warning("Map server D/C");
- } else error("Unknown packet: map_start");
- // Send "map loaded"
- WFIFOW(0) = net_w_value(0x007d);
- WFIFOSET(2);
- while(out_size>0)flush();
-}
-
-/** Requests to walk */
+ // Connect to map server
+ if(open_session(iptostring(map_address), map_port)==SOCKET_ERROR) {
+ warning("Unable to connect to map server");
+ state = LOGIN;
+ ok("Error", "Unable to connect to map server");
+ return;
+ }
+
+ // 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);
+
+ while((in_size<4)||(out_size>0))flush();
+ RFIFOSKIP(4);
+
+ while(in_size<2)flush();
+
+ if(RFIFOW(0)==0x0073) {
+ while(in_size<11)flush();
+ x = get_x(RFIFOP(6));
+ y = get_y(RFIFOP(6));
+ //direction = get_direction(RFIFOP(6));
+ log("Protocol", "Player position: (%d, %d), Direction: %d",
+ x, y, direction);
+ RFIFOSKIP(11);
+ } else if(0x0081) {
+ warning("Map server D/C");
+ } else error("Unknown packet: map_start");
+ // Send "map loaded"
+ WFIFOW(0) = net_w_value(0x007d);
+ WFIFOSET(2);
+ while(out_size>0)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);
+ char temp[3];
+ set_coordinates(temp, x, y, direction);
+ WFIFOW(0) = net_w_value(0x0085);
+ memcpy(WFIFOP(2), temp, 3);
+ WFIFOSET(5);
}
-/** Request to speak */
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);
+ 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);
}
-/** Request action */
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);
+ WFIFOW(0) = net_w_value(0x0089);
+ WFIFOL(2) = net_l_value(id);
+ WFIFOB(6) = net_b_value(type);
+ WFIFOSET(7);
}
-
-/** Request to attack */
void attack(unsigned short x, unsigned short y, unsigned char direction) {
- int monster_id = 0;
-
- if(direction==SOUTH) {
- monster_id = find_monster(x, y+1);
- if(monster_id!=0)
- action(0, monster_id);
- } else if(direction==WEST) {
- monster_id = find_monster(x-1, y);
- if(monster_id!=0)
- action(0, monster_id);
- } else if(direction==NORTH) {
- monster_id = find_monster(x, y-1);
- if(monster_id!=0)
- action(0, monster_id);
- } else if(direction==EAST) {
- monster_id = find_monster(x+1, y);
- if(monster_id!=0)
- action(0, monster_id);
- }
+ int monster_id = 0;
+
+ if (direction == SOUTH) {
+ monster_id = find_monster(x, y + 1);
+ if (monster_id != 0)
+ action(0, monster_id);
+ } else if(direction == WEST) {
+ monster_id = find_monster(x - 1, y);
+ if (monster_id != 0)
+ action(0, monster_id);
+ } else if(direction == NORTH) {
+ monster_id = find_monster(x, y - 1);
+ if (monster_id != 0)
+ action(0, monster_id);
+ } else if(direction==EAST) {
+ monster_id = find_monster(x + 1, y);
+ if (monster_id != 0)
+ action(0, monster_id);
+ }
}
-
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 374024e3..3a46e91f 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -17,14 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
*/
+#ifndef _TMW_PROTOCOL_H
+#define _TMW_PROTOCOL_H
+
#ifdef WIN32
#pragma warning (disable:4312)
#endif
-
-#ifndef _TMW_PROTOCOL_H
-#define _TMW_PROTOCOL_H
#include "../main.h"
#include "../being.h"
@@ -38,21 +40,52 @@
#endif
+/** Packet length by id */
short get_length(short id);
-unsigned short get_x(char *data);
-unsigned short get_y(char *data);
-unsigned char get_direction(char *data);
-unsigned short get_src_x(char *data);
-unsigned short get_src_y(char *data);
+
+/** Decodes x coord */
+unsigned short get_x(const char *data);
+
+/** Decodes y coord */
+unsigned short get_y(const char *data);
+
+/** Decodes direction */
+unsigned char get_direction(const char *data);
+
+/** Decodes src x coord */
+unsigned short get_src_x(const char *data);
+
+/** Decodes src y coord */
+unsigned short get_src_y(const char *data);
+
+/** Decodes src direction */
unsigned char get_src_direction(char data);
-unsigned short get_dest_x(char *data);
-unsigned short get_dest_y(char *data);
+
+/** Decodes dest x coord */
+unsigned short get_dest_x(const char *data);
+
+/** Decodes dest y coord */
+unsigned short get_dest_y(const char *data);
+
+/** Decodes dest direction */
unsigned char get_dest_direction(char data);
+
+/** Encodes coords and direction in 3 bytes data */
void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction);
+
+/** Initialize connection with map server */
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 */
void attack(unsigned short x, unsigned short y, unsigned char direction);
+
+/** Request action */
void action(char type, int id);
#endif