summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-02-14 00:53:22 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-02-14 00:53:22 +0000
commit812103cea68f1da2004dd518c5ad3b448a0e1729 (patch)
treeb4bc86a077385a219474bcb5bca727e0703ed52b /src
parent3628aae5ef1be719603d4aa8e1b209cf5e04520c (diff)
downloadmana-client-812103cea68f1da2004dd518c5ad3b448a0e1729.tar.gz
mana-client-812103cea68f1da2004dd518c5ad3b448a0e1729.tar.bz2
mana-client-812103cea68f1da2004dd518c5ad3b448a0e1729.tar.xz
mana-client-812103cea68f1da2004dd518c5ad3b448a0e1729.zip
Simplified logging for the sake of simplicity.
Diffstat (limited to 'src')
-rw-r--r--src/gui/char_select.cpp8
-rw-r--r--src/gui/char_server.cpp2
-rw-r--r--src/gui/login.cpp10
-rw-r--r--src/gui/setup.cpp2
-rw-r--r--src/log.cpp43
-rw-r--r--src/log.h18
-rw-r--r--src/main.cpp55
-rw-r--r--src/map.cpp4
-rw-r--r--src/net/network.cpp39
-rw-r--r--src/net/network.h9
-rw-r--r--src/net/protocol.cpp9
-rw-r--r--src/resources/image.cpp8
-rw-r--r--src/resources/resourcemanager.cpp19
13 files changed, 91 insertions, 135 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 5032b196..9cf20f94 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -211,11 +211,11 @@ void CharSelectDialog::serverCharSelect()
flush();
}
- log("CharSelect", "Packet ID: %x, Length: %d, Packet_in_size %d",
+ log("CharSelect: Packet ID: %x, Length: %d, Packet_in_size %d",
RFIFOW(0),
get_length(RFIFOW(0)),
RFIFOW(2));
- log("CharSelect", "In_size: %d", in_size);
+ log("CharSelect: In_size: %d", in_size);
if (RFIFOW(0) == 0x0071) {
while (in_size < 28) {
@@ -229,8 +229,8 @@ void CharSelectDialog::serverCharSelect()
map_port = RFIFOW(26);
state = GAME;
- log("CharSelect", "Map: %s", map_name);
- log("CharSelect", "Server: %s:%d", iptostring(map_address), map_port);
+ log("CharSelect: Map: %s", map_name);
+ log("CharSelect: Server: %s:%d", iptostring(map_address), map_port);
RFIFOSKIP(28);
close_session();
}
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index c0f1c523..a0988b5a 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -195,7 +195,7 @@ void server_char_server(int serverIndex) {
}
state = CHAR_SELECT;
- log("CharServer", "Player: %s (Packet ID: %x, Length: %d",
+ log("CharServer: Player: %s (Packet ID: %x, Length: %d",
char_info->name, RFIFOW(0), RFIFOW(2));
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 5496c01b..3c58cde9 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -105,7 +105,7 @@ void LoginDialog::action(const std::string& eventId)
{
if (eventId == "ok") {
const std::string user = userField->getText();
- log("Network", "Username is %s", user.c_str());
+ log("Network: Username is %s", user.c_str());
// Store config settings
config.setValue("remember", keepCheck->isMarked());
@@ -191,8 +191,8 @@ void server_login(const std::string& user, const std::string& pass) {
while ((in_size < 23) || (out_size > 0)) {
flush();
}
- log("Network", "Packet ID: %x", RFIFOW(0));
- log("Network", "Packet length: %d", get_packet_length(RFIFOW(0)));
+ log("Network: Packet ID: %x", RFIFOW(0));
+ log("Network: Packet length: %d", get_packet_length(RFIFOW(0)));
if (RFIFOW(0) == 0x0069) {
while (in_size < RFIFOW(2)) {
@@ -211,10 +211,10 @@ void server_login(const std::string& user, const std::string& pass) {
server_info[i].port = RFIFOW(47 + 32 * i + 4);
state = CHAR_SERVER;
}
- log("Network", "Server: %s (%s:%d)", server_info[0].name,
+ log("Network: Server: %s (%s:%d)", server_info[0].name,
iptostring(server_info[0].address),
server_info[0].port);
- log("Network", "Users: %d", server_info[0].online_users);
+ log("Network: Users: %d", server_info[0].online_users);
RFIFOSKIP(RFIFOW(2));
}
else if (RFIFOW(0) == 0x006a) {
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 6305d56a..151c3ab6 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -187,7 +187,7 @@ void Setup::action(const std::string& eventId)
}
catch (const char *err) {
new OkDialog(this, "Sound Engine", err);
- warning(err);
+ log("Warning: %s", err);
}
} else {
config.setValue("sound", 0);
diff --git a/src/log.cpp b/src/log.cpp
index 4a66a223..e2f0ac36 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -37,7 +37,7 @@ void init_log()
}
}
-void log(const char *category, const char *log_text, ...)
+void log(const char *log_text, ...)
{
if (logfile)
{
@@ -55,14 +55,14 @@ void log(const char *category, const char *log_text, ...)
// Print the log entry
fprintf(logfile,
- "[%s%d:%s%d:%s%d] %s: %s\n",
+ "[%s%d:%s%d:%s%d] %s\n",
(((t / 60) / 60) % 24 < 10) ? "0" : "",
(int)(((t / 60) / 60) % 24),
((t / 60) % 60 < 10) ? "0" : "",
(int)((t / 60) % 60),
(t % 60 < 10) ? "0" : "",
(int)(t % 60),
- category, buf
+ buf
);
// Flush the log file
@@ -73,34 +73,9 @@ void log(const char *category, const char *log_text, ...)
}
}
-void log(const std::string &text)
-{
- if (logfile)
- {
- // Get the current system time
- time_t t;
- time(&t);
-
- // Print the log entry
- fprintf(logfile,
- "[%s%d:%s%d:%s%d] %s\n",
- (((t / 60) / 60) % 24 < 10) ? "0" : "",
- (int)(((t / 60) / 60) % 24),
- ((t / 60) % 60 < 10) ? "0" : "",
- (int)((t / 60) % 60),
- (t % 60 < 10) ? "0" : "",
- (int)(t % 60),
- text.c_str()
- );
-
- // Flush the log file
- fflush(logfile);
- }
-}
-
void error(const std::string &error_text)
{
- log("Error", error_text.c_str());
+ log(error_text.c_str());
#ifdef WIN32
MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
@@ -109,13 +84,3 @@ void error(const std::string &error_text)
#endif
exit(1);
}
-
-void warning(const char *warning_text)
-{
- log("Warning", warning_text);
-}
-
-void status(const char *status_text)
-{
- log("Status", status_text);
-}
diff --git a/src/log.h b/src/log.h
index 9d9cfb72..e85ddd6b 100644
--- a/src/log.h
+++ b/src/log.h
@@ -34,15 +34,9 @@
void init_log();
/**
- * Enters a message in the log with a certain category. The message will be
- * timestamped.
- */
-void log(const char *category, const char *log_text, ...);
-
-/**
* Enters a message in the log. The message will be timestamped.
*/
-void log(const std::string &text);
+void log(const char *log_text, ...);
/**
* Log an error and quit. The error will pop-up in Windows and will be printed
@@ -50,14 +44,4 @@ void log(const std::string &text);
*/
void error(const std::string &error_text);
-/**
- * Shortcut to log a warning.
- */
-void warning(const char *warning_text);
-
-/**
- * Shortcut to log a status update.
- */
-void status(const char *status_text);
-
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 7d46a764..743b365f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -202,7 +202,7 @@ void init_engine()
}
#ifndef USE_OPENGL
if ((int)config.getValue("hwaccel", 0)) {
- std::cout << "Attempting to use hardware acceleration.\n";
+ log("Attempting to use hardware acceleration.");
displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
}
else {
@@ -226,28 +226,27 @@ void init_engine()
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
#endif
-#ifdef __DEBUG
const SDL_VideoInfo *vi = SDL_GetVideoInfo();
- std::cout << "It is " << ((vi->hw_available) ? "" : "not") <<
- " possible to create hardware surfaces.\n";
- std::cout << "There is " << ((vi->wm_available) ? "a" : "no") <<
- " window manager available.\n";
- std::cout << "Hardware to hardware blits are " <<
- ((vi->blit_hw) ? "" : "not") << " accelerated.\n";
- std::cout << "Hardware to hardware colorkey blits are " <<
- ((vi->blit_hw_CC) ? "" : "not") << " accelerated.\n";
- std::cout << "Hardware to hardware alpha blits are " <<
- ((vi->blit_hw_A) ? "" : "not") << " accelerated.\n";
- std::cout << "Software to hardware blits are " <<
- ((vi->blit_sw) ? "" : "not") << " accelerated.\n";
- std::cout << "Software to hardware colorkey blits are " <<
- ((vi->blit_sw_CC) ? "" : "not") << " accelerated.\n";
- std::cout << "Software to hardware alpha blits are " <<
- ((vi->blit_sw_A) ? "" : "not") << " accelerated.\n";
- std::cout << "Color fills are " <<
- ((vi->blit_fill) ? "" : "not") << " accelerated.\n";
- std::cout << "Available video memory: " << vi->video_mem << "\n";
-#endif
+
+ log("Possible to create hardware surfaces: %s",
+ ((vi->hw_available) ? "yes" : "no "));
+ log("Window manager available: %s",
+ ((vi->hw_available) ? "yes" : "no"));
+ log("Accelerated hardware to hardware blits: %s",
+ ((vi->blit_hw) ? "yes" : "no"));
+ log("Accelerated hardware to hardware colorkey blits: %s",
+ ((vi->blit_hw_CC) ? "yes" : "no"));
+ log("Accelerated hardware to hardware alpha blits: %s",
+ ((vi->blit_hw_A) ? "yes" : "no"));
+ log("Accelerated software to hardware blits: %s",
+ ((vi->blit_sw) ? "yes" : "no"));
+ log("Accelerated software to hardware colorkey blits: %s",
+ ((vi->blit_sw_CC) ? "yes" : "no"));
+ log("Accelerated software to hardware alpha blits: %s",
+ ((vi->blit_sw_A) ? "yes" : "no"));
+ log("Accelerated color fills: %s",
+ ((vi->blit_fill) ? "yes" : "no"));
+ log("Available video memory: %d", vi->video_mem);
//vfmt Pixel format of the video device
@@ -290,7 +289,7 @@ void init_engine()
catch (const char *err) {
state = ERROR;
new OkDialog("Sound Engine", err, &initWarningListener);
- warning(err);
+ log("Warning: %s", err);
}
}
@@ -323,20 +322,20 @@ int main(int argc, char *argv[]) {
switch (state) {
case LOGIN:
- status("LOGIN");
+ log("State: LOGIN");
login();
break;
case CHAR_SERVER:
- status("CHAR_SERVER");
+ log("State: CHAR_SERVER");
char_server();
break;
case CHAR_SELECT:
- status("CHAR_SELECT");
+ log("State: CHAR_SELECT");
charSelect();
break;
case GAME:
sound.stopBgm();
- status("GAME");
+ log("State: GAME");
try {
map_start();
game();
@@ -358,7 +357,7 @@ int main(int argc, char *argv[]) {
break;
}
}
- status("EXIT");
+ log("State: EXIT");
exit_engine();
return 0;
}
diff --git a/src/map.cpp b/src/map.cpp
index 39b73091..76fba34a 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -104,7 +104,7 @@ bool Map::load(const std::string &mapFile)
FILE *file = fopen(mapFile.c_str(), "r");
if (!file) {
- warning(mapFile.c_str());
+ log("Warning: %s", mapFile.c_str());
return false;
}
@@ -151,7 +151,7 @@ bool loadXmlMap(const std::string &mapFile)
xmlDocPtr doc = xmlReadFile(mapFile.c_str(), NULL, 0);
if (!doc) {
- warning(mapFile.c_str());
+ log("Warning: %s", mapFile.c_str());
return false;
}
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);
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index dc5df41c..da0be097 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -40,9 +40,7 @@ Image::~Image()
Image* Image::load(const std::string &filePath, int flags)
{
- std::stringstream msg;
- msg << "Image::load(" << filePath << ")";
- log(msg.str());
+ log("Image::load(%s)", filePath.c_str());
// Attempt to use SDL_Image to load the file.
SDL_Surface *tmpImage = IMG_Load(filePath.c_str());
@@ -59,8 +57,8 @@ Image* Image::load(const std::string &filePath, int flags)
// Check if the file was opened and return the appropriate value.
if (!image) {
- log("Error", "Image load failed : %s", IMG_GetError());
- //log("Error", "Image load failed : %s", filePath.c_str());
+ log("Error: Image load failed: %s", IMG_GetError());
+ //log("Error: Image load failed: %s", filePath.c_str());
return NULL;
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 582bc613..0d6412d8 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -62,11 +62,8 @@ ResourceManager::~ResourceManager()
}
resources.clear();
- std::stringstream msg;
- msg << "ResourceManager::~ResourceManager() cleaned up " <<
- danglingReferences << " references to " << danglingResources <<
- " resources";
- log(msg.str());
+ log("ResourceManager::~ResourceManager() cleaned up %d references to %d"
+ " resources", danglingReferences, danglingResources);
}
Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
@@ -100,10 +97,10 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
switch (type)
{
case MAP:
- warning("Map resource not supported.");
+ log("Warning: Map resource not supported.");
break;
case MUSIC:
- warning("Music resource not supported.");
+ log("Warning: Music resource not supported.");
break;
case IMAGE:
// Attempt to create and load our image object.
@@ -111,16 +108,16 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
reinterpret_cast<Resource*>(Image::load(filePath, flags));
break;
case SCRIPT:
- warning("Script resource not supported.");
+ log("Warning: Script resource not supported.");
break;
case TILESET:
- warning("Tileset resource not supported.");
+ log("Warning: Tileset resource not supported.");
break;
case SOUND_EFFECT:
- warning("Sound FX resource not supported.");
+ log("Warning: Sound FX resource not supported.");
break;
default:
- warning("Unknown resource type");
+ log("Warning: Unknown resource type");
break;
}