diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-14 00:53:22 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-14 00:53:22 +0000 |
commit | 812103cea68f1da2004dd518c5ad3b448a0e1729 (patch) | |
tree | b4bc86a077385a219474bcb5bca727e0703ed52b /src/net | |
parent | 3628aae5ef1be719603d4aa8e1b209cf5e04520c (diff) | |
download | mana-812103cea68f1da2004dd518c5ad3b448a0e1729.tar.gz mana-812103cea68f1da2004dd518c5ad3b448a0e1729.tar.bz2 mana-812103cea68f1da2004dd518c5ad3b448a0e1729.tar.xz mana-812103cea68f1da2004dd518c5ad3b448a0e1729.zip |
Simplified logging for the sake of simplicity.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/network.cpp | 39 | ||||
-rw-r--r-- | src/net/network.h | 9 | ||||
-rw-r--r-- | src/net/protocol.cpp | 9 |
3 files changed, 35 insertions, 22 deletions
diff --git a/src/net/network.cpp b/src/net/network.cpp index 7124073c..8ad0fd85 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -41,15 +41,18 @@ SOCKADDR_IN addr; fd_set read_socket; fd_set write_socket; -/** Increase size of written data */ -void WFIFOSET(int len) { - if(out_size+len>=buffer_size) - warning("Output buffer full"); - else out_size+=len; +void WFIFOSET(int len) +{ + if (out_size + len >= buffer_size) { + log("Warning: Output buffer full"); + } + else { + out_size += len; + } } -/** Convert an address from int format to string */ -char *iptostring(int address) { +char *iptostring(int address) +{ short temp1, temp2; static char asciiIP[16]; @@ -59,8 +62,8 @@ char *iptostring(int address) { return asciiIP; } -/** Open a session with a server */ -SOCKET open_session(const char* address, short port) { +SOCKET open_session(const char* address, short port) +{ #ifdef WIN32 WSADATA wsda; #endif @@ -101,8 +104,8 @@ SOCKET open_session(const char* address, short port) { return sock; } -/** Close a session */ -void close_session() { +void close_session() +{ FD_CLR(sock,&read_socket); FD_CLR(sock,&write_socket); closesocket(sock); @@ -119,8 +122,8 @@ void close_session() { WSACleanup(); } -/** Send and receive data waiting in the buffers */ -void flush() { +void flush() +{ int ret = 0; void *buf = out; timeval time_out; @@ -152,14 +155,14 @@ void flush() { if (ret == SOCKET_ERROR) { error("Socket Error"); #ifdef WIN32 - log("Error", "Socket error: %i ", WSAGetLastError()); + log("Error: Socket error: %i ", WSAGetLastError()); if (WSAGetLastError() == 10053) - log("Error", "Packet size error"); + log("Error: Packet size error"); /** Probably the last packet you sent, was defined with * wrong size: WFIFOSET(size); */ #else - log("Error", "socket_error", "Undefined socket error"); + log("Error: Undefined socket error"); #endif } } @@ -171,9 +174,9 @@ void flush() { ret = recv(sock, in+in_size, RFIFOSPACE, 0); if(ret==SOCKET_ERROR) { #ifdef WIN32 - log("Error", "Socket error: %i ", WSAGetLastError()); + log("Error: Socket error: %i ", WSAGetLastError()); #else - log("Error", "socket_error", "Undefined socket error"); + log("Error: Undefined socket error"); #endif } else RFIFOSET(ret); // Set size of available data to read } diff --git a/src/net/network.h b/src/net/network.h index 2564c801..61fb5133 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -75,10 +75,19 @@ #define RFIFOSPACE (buffer_size-in_size) // Return input buffer size #define RFIFOSET(len) in_size+=len; +/** Increase size of written data */ void WFIFOSET(int len); + +/** Convert an address from int format to string */ char *iptostring(int address); + +/** Open a session with a server */ SOCKET open_session(const char* address, short port); + +/** Close a session */ void close_session(); + +/** Send and receive data waiting in the buffers */ void flush(); extern char *in, *out; // Input, output buffer diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp index bca630b1..40110144 100644 --- a/src/net/protocol.cpp +++ b/src/net/protocol.cpp @@ -152,10 +152,11 @@ void set_coordinates(char *data, unsigned short x, unsigned short y, data[2] |= direction; } -void map_start() { +void map_start() +{ // Connect to map server if (open_session(iptostring(map_address), map_port) == SOCKET_ERROR) { - warning("Unable to connect to map server"); + log("Warning: Unable to connect to map server"); throw "Unable to connect to map server"; return; } @@ -179,11 +180,11 @@ void map_start() { x = get_x(RFIFOP(6)); y = get_y(RFIFOP(6)); //direction = get_direction(RFIFOP(6)); - log("Protocol", "Player position: (%d, %d), Direction: %d", + log("Protocol: Player position: (%d, %d), Direction: %d", x, y, direction); RFIFOSKIP(11); } else if(0x0081) { - warning("Map server D/C"); + log("Warning: Map server D/C"); } else error("Unknown packet: map_start"); // Send "map loaded" WFIFOW(0) = net_w_value(0x007d); |