summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-04-01 00:14:51 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-04-01 00:14:51 +0000
commit05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c (patch)
tree921b18da0dc52e7562f0c6a02e5343f9b582cf64 /src
parent78c72d1463735ad6e3a176f89d3c41a5ed71fc40 (diff)
downloadmana-05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c.tar.gz
mana-05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c.tar.bz2
mana-05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c.tar.xz
mana-05f71c98af1bc9d9aabf3e8e3dc78cae75675e1c.zip
* The client will now only attempt to load .tmx or .tmx.gz files.
* When unable to connect to char server, report IP to which it can't connect. * Cleaned up logger a bit.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp24
-rw-r--r--src/gui/char_select.cpp1
-rw-r--r--src/gui/char_server.cpp8
-rw-r--r--src/gui/skill.cpp1
-rw-r--r--src/log.cpp45
-rw-r--r--src/log.h53
-rw-r--r--src/map.cpp2
-rw-r--r--src/net/win2mac.h7
-rw-r--r--src/resources/mapreader.cpp16
9 files changed, 84 insertions, 73 deletions
diff --git a/src/game.cpp b/src/game.cpp
index b7fd9f86..19a4c88f 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -125,19 +125,23 @@ void game() {
void do_init()
{
- /*tiledMap = Map::load(map_path);
- std::cout << map_path << std::endl;*/
std::string path(map_path);
+ std::string pathDir = path.substr(0, path.rfind("."));
- std::string pathDir = path.substr(0, path.rfind(".") + 1);
- pathDir.insert(pathDir.size(), "tmx");
-
- //tiledMap = Map::load("data/maps/new_3-1.tmx.gz");
- //std::cout << pathDir << std::endl;
- tiledMap = Map::load(map_path);
+ // Try .tmx map file
+ pathDir.insert(pathDir.size(), ".tmx");
+ tiledMap = Map::load(pathDir);
- if (!tiledMap) {
- logger.error("Could not find map file");
+ if (!tiledMap)
+ {
+ // Try .tmx.gz map file
+ pathDir.insert(pathDir.size(), ".gz");
+ tiledMap = Map::load(pathDir);
+
+ if (!tiledMap)
+ {
+ logger.error("Could not find map file!");
+ }
}
// Start playing background music
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 41e27a89..d8071ac2 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -104,7 +104,6 @@ CharSelectDialog::CharSelectDialog():
selectButton->requestFocus();
setLocationRelativeTo(getParent());
-
}
CharSelectDialog::~CharSelectDialog()
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index e3835df7..057de3c7 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -152,12 +152,14 @@ void char_server() {
void server_char_server(int serverIndex) {
int ret;
state = LOGIN;
+ const char *ipstring = iptostring(server_info[serverIndex].address);
// Connect to char server
- ret = open_session(iptostring(server_info[serverIndex].address),
- server_info[serverIndex].port);
+ ret = open_session(ipstring, server_info[serverIndex].port);
if (ret == SOCKET_ERROR) {
- new OkDialog("Error", "Unable to connect to char server");
+ std::string str = std::string("Unable to connect to char server ") +
+ std::string(ipstring);
+ new OkDialog("Error", str);
return;
}
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index c5aaab45..c342582f 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -175,4 +175,3 @@ void SkillDialog::setSkill(int id, int lv, int sp)
}
}
}
-
diff --git a/src/log.cpp b/src/log.cpp
index e1db8d4f..df92e49e 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -24,27 +24,30 @@
#include <windows.h>
#endif
-FILE* logfile;
+#include <sstream>
-Logger::Logger(std::string logFilename)
+Logger::Logger(const std::string &logFilename)
{
logFile.open(logFilename.c_str(), std::ios_base::trunc);
- if ( !logFile.is_open() )
+
+ if (!logFile.is_open())
{
- std::cout << "Warning: error while opening log file." << std::endl;
+ std::cout << "Warning: error while opening log file.\n";
}
-
}
Logger::~Logger()
{
- logFile.close();
+ if (logFile.is_open())
+ {
+ logFile.close();
+ }
}
void Logger::log(const char *log_text, ...)
{
- if ( logFile.is_open() )
+ if (logFile.is_open())
{
char* buf = new char[1024];
va_list ap;
@@ -59,18 +62,19 @@ void Logger::log(const char *log_text, ...)
time(&t);
// Print the log entry
- logFile << "[";
- logFile << ((((t / 60) / 60) % 24 < 10) ? "0" : "");
- logFile << (int)(((t / 60) / 60) % 24);
- logFile << ":";
- logFile << (((t / 60) % 60 < 10) ? "0" : "");
- logFile << (int)((t / 60) % 60);
- logFile << ":";
- logFile << ((t % 60 < 10) ? "0" : "");
- logFile << (int)(t % 60);
- logFile << "] ";
+ std::stringstream timeStr;
+ timeStr << "[";
+ timeStr << ((((t / 60) / 60) % 24 < 10) ? "0" : "");
+ timeStr << (int)(((t / 60) / 60) % 24);
+ timeStr << ":";
+ timeStr << (((t / 60) % 60 < 10) ? "0" : "");
+ timeStr << (int)((t / 60) % 60);
+ timeStr << ":";
+ timeStr << ((t % 60 < 10) ? "0" : "");
+ timeStr << (int)(t % 60);
+ timeStr << "] ";
- logFile << buf << std::endl;
+ logFile << timeStr.str() << buf << std::endl;
// Delete temporary buffer
delete[] buf;
@@ -83,9 +87,8 @@ void Logger::error(const std::string &error_text)
#ifdef WIN32
MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
#else
- log("Error :");
- log(error_text.c_str());
+ std::cerr << "Error: " << error_text << std::endl;
+ log("Error: %s", error_text.c_str());
#endif
exit(1);
}
-
diff --git a/src/log.h b/src/log.h
index 64da662b..d73f4c99 100644
--- a/src/log.h
+++ b/src/log.h
@@ -23,7 +23,6 @@
#define _LOG_H
#include <stdlib.h>
-#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <string>
@@ -35,34 +34,30 @@
*/
class Logger
{
-public:
-
-/**
- * Constructor :
- * Initializes log file by opening it for writing.
- */
-Logger(std::string logFilename);
-
-/**
- * Destructor
- */
-~Logger();
-
-/**
- * Enters a message in the log. The message will be timestamped.
- */
-void log(const char *log_text, ...);
-
-/**
- * Log an error and quit. The error will pop-up in Windows and will be printed
- * to standard error everywhere else.
- */
-void error(const std::string &error_text);
-
-private:
-
-std::ofstream logFile;
-
+ public:
+ /**
+ * Constructor, opens log file for writing.
+ */
+ Logger(const std::string &logFilename);
+
+ /**
+ * Destructor, closes log file.
+ */
+ ~Logger();
+
+ /**
+ * Enters a message in the log. The message will be timestamped.
+ */
+ void log(const char *log_text, ...);
+
+ /**
+ * Log an error and quit. The error will pop-up in Windows and will be
+ * printed to standard error everywhere else.
+ */
+ void error(const std::string &error_text);
+
+ private:
+ std::ofstream logFile;
};
#endif
diff --git a/src/map.cpp b/src/map.cpp
index 60190f6f..df9aafc5 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -112,6 +112,8 @@ Map::~Map()
Map *Map::load(const std::string &mapFile)
{
+ logger.log("Map::load(%s)", mapFile.c_str());
+
if (mapFile.find(".tmx", 0) != std::string::npos)
{
// New map file format assumed
diff --git a/src/net/win2mac.h b/src/net/win2mac.h
index 851a328a..8159f4a3 100644
--- a/src/net/win2mac.h
+++ b/src/net/win2mac.h
@@ -1,3 +1,6 @@
+#ifndef _TMW_MAC_H
+#define _TMW_MAC_H
+
#include <stdio.h>
#define UInt16 unsigned short int
@@ -6,10 +9,8 @@
#define INT32 long int
#define SWAP( a, b ) { char c; c=a; a=b; b=c; }
-#ifndef _MAC_H
-#define _MAC_H
UInt32 DR_SwapFourBytes(UInt32 dw);
UInt16 DR_SwapTwoBytes(UInt16 w);
char* SwapChar(char charlist[]);
-#endif
+#endif
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index c656edba..cf18e4bb 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -56,21 +56,27 @@ int Tileset::getFirstGid()
Map *MapReader::readMap(const std::string &filename)
{
- logger.log("Attempting to parse XML map data");
-
std::string name = /*std::string("data/") +*/ filename;
+
+ // Check that file exists before trying to parse it
+ std::fstream fin;
+ fin.open(name.c_str(), std::ios::in);
+ if (!fin.is_open()) {
+ logger.log("No such file!");
+ return NULL;
+ }
+ fin.close();
+
xmlDocPtr doc = xmlParseFile(name.c_str());
if (doc) {
- logger.log("Looking for root node");
xmlNodePtr node = xmlDocGetRootElement(doc);
if (!node || !xmlStrEqual(node->name, BAD_CAST "map")) {
- logger.log("Warning: No map file (%s)!", filename.c_str());
+ logger.log("Warning: Not a map file (%s)!", filename.c_str());
return NULL;
}
- logger.log("Loading map from XML tree");
return readMap(node, filename);
xmlFreeDoc(doc);
} else {