summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--The Mana World.dev20
-rw-r--r--src/Makefile.am2
-rw-r--r--src/game.cpp8
-rw-r--r--src/gui/char_select.cpp8
-rw-r--r--src/gui/char_server.cpp8
-rw-r--r--src/gui/gui.cpp2
-rw-r--r--src/gui/login.cpp12
-rw-r--r--src/gui/updatewindow.cpp8
-rw-r--r--src/main.cpp66
-rw-r--r--src/main.h22
-rw-r--r--src/net/network.cpp13
12 files changed, 98 insertions, 79 deletions
diff --git a/ChangeLog b/ChangeLog
index 3cb5ec1b..c6e41ea1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-09-26 Eugenio Favalli <elvenprogrammer@gmail.com>
+
+ * The Mana World.dev, src/Makefile.am, src/game.cpp,
+ src/gui/char_select.cpp, src/gui/char_server.cpp, src/gui/gui.cpp,
+ src/gui/login.cpp, src/gui/updatewindow.cpp, src/main.cpp, src/main.h,
+ src/net/network.cpp: Added a nicer handling of when you get disconnected
+ from the server.
+
2005-09-25 Bjørn Lindeijer <bjorn@lindeijer.nl>
* src/openglgraphics.cpp: Fixed taking OpenGL screenshots and in
diff --git a/The Mana World.dev b/The Mana World.dev
index f682790d..3119e3bb 100644
--- a/The Mana World.dev
+++ b/The Mana World.dev
@@ -1,7 +1,7 @@
[Project]
FileName=The Mana World.dev
Name=tmw
-UnitCount=171
+UnitCount=173
Type=0
Ver=1
ObjFiles=
@@ -32,19 +32,19 @@ CompilerSettings=0010001001001001001101
[VersionInfo]
Major=0
Minor=0
-Release=16
+Release=17
Build=0
LanguageID=1033
CharsetID=1252
CompanyName=The Mana World Development Team
-FileVersion=0.0.16
+FileVersion=0.0.17
FileDescription=The Mana World
InternalName=tmw.exe
LegalCopyright=2004-2005 (C)
LegalTrademarks=
OriginalFilename=tmw.exe
ProductName=The Mana World MMORPG
-ProductVersion=0.0.16
+ProductVersion=0.0.17
AutoIncBuildNr=0
[Unit8]
@@ -1767,20 +1767,20 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
-[Unit172]
-FileName=src\resources\imagewriter.cpp
+[Unit173]
+FileName=src\gui\error.h
CompileCpp=1
-Folder=resources
+Folder=gui/header
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
-[Unit173]
-FileName=src\resources\imagewriter.h
+[Unit172]
+FileName=src\gui\error.cpp
CompileCpp=1
-Folder=resources
+Folder=gui/source
Compile=1
Link=1
Priority=1000
diff --git a/src/Makefile.am b/src/Makefile.am
index 48ab6e02..16504926 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,8 @@ tmw_SOURCES = graphic/spriteset.cpp \
gui/confirm_dialog.h \
gui/equipmentwindow.cpp \
gui/equipmentwindow.h \
+ gui/error.cpp \
+ gui/error.h \
gui/focushandler.cpp \
gui/focushandler.h \
gui/gui.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index f2c68e24..6897c036 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -151,7 +151,7 @@ class DeathNoticeListener : public gcn::ActionListener {
class ExitListener : public gcn::ActionListener {
void action(const std::string &eventId) {
if (eventId == "yes") {
- state = EXIT;
+ state = EXIT_STATE;
}
exitConfirm = NULL;
}
@@ -377,7 +377,7 @@ void game()
int gameTime = tick_time;
- while (state != EXIT)
+ while (state == GAME_STATE)
{
// Handle all necessary game logic
while (get_elapsed_time(gameTime) > 0)
@@ -522,7 +522,7 @@ void do_input()
// Quit by pressing Enter if the exit confirm is there
if (exitConfirm)
{
- state = EXIT;
+ state = EXIT_STATE;
}
// Close the Browser if opened
else if (helpWindow->isVisible())
@@ -826,7 +826,7 @@ void do_input()
// Quit event
else if (event.type == SDL_QUIT)
{
- state = EXIT;
+ state = EXIT_STATE;
}
// Push input to GUI when not used
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 0c03a6b0..fd0ccdc9 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -139,7 +139,7 @@ void CharSelectDialog::action(const std::string& eventId)
serverCharSelect();
}
else if (eventId == "cancel") {
- state = EXIT;
+ state = EXIT_STATE;
}
else if (eventId == "new") {
if (n_character == 0) {
@@ -241,7 +241,7 @@ void CharSelectDialog::serverCharSelect()
map_address = msg.readLong();
map_port = msg.readShort();
player_info = char_info[0];
- state = GAME;
+ state = GAME_STATE;
logger->log("CharSelect: Map: %s", map_path.c_str());
logger->log("CharSelect: Server: %s:%d", iptostring(map_address),
@@ -278,7 +278,7 @@ void CharSelectDialog::serverCharSelect()
break;
}
close_session();
- state = LOGIN;
+ state = LOGIN_STATE;
}
// Todo: add other packets
@@ -492,6 +492,6 @@ void charSelectInputHandler(SDL_KeyboardEvent *keyEvent)
{
if (keyEvent->keysym.sym == SDLK_ESCAPE)
{
- state = EXIT;
+ state = EXIT_STATE;
}
}
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index 5c371469..a8f99d8f 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -107,7 +107,7 @@ void ServerSelectDialog::action(const std::string& eventId)
server_char_server(serverList->getSelected());
}
else if (eventId == "cancel") {
- state = LOGIN;
+ state = LOGIN_STATE;
}
}
@@ -128,14 +128,14 @@ void charServerInputHandler(SDL_KeyboardEvent *keyEvent)
{
if (keyEvent->keysym.sym == SDLK_ESCAPE)
{
- state = LOGIN;
+ state = LOGIN_STATE;
}
}
void server_char_server(int serverIndex)
{
int ret;
- state = LOGIN;
+ state = LOGIN_STATE;
const char *ipstring = iptostring(server_info[serverIndex]->address);
// Connect to char server
@@ -217,7 +217,7 @@ void server_char_server(int serverIndex)
msg.readByte(); // unknown
}
- state = CHAR_SELECT;
+ state = CHAR_SELECT_STATE;
logger->log("CharServer: Player: %s (Packet ID: %x, Length: %d)",
char_info[0]->name.c_str(), msg.getId(), msg.getLength());
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 6edcd1a4..afe2019d 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -230,7 +230,7 @@ void Gui::mousePress(int mx, int my, int button)
int tilex = mx / 32 + camera_x;
int tiley = my / 32 + camera_y;
- if (state == GAME && tiledMap->getWalk(tilex, tiley)) {
+ if (state == GAME_STATE && tiledMap->getWalk(tilex, tiley)) {
walk(tilex, tiley, 0);
player_node->setDestination(tilex, tiley);
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index f5dc4f1e..83a20f8b 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -240,7 +240,7 @@ void LoginDialog::action(const std::string& eventId)
}
else if (eventId == "cancel")
{
- state = EXIT;
+ state = EXIT_STATE;
}
else if (eventId == "register")
{
@@ -315,7 +315,7 @@ void loginInputHandler(SDL_KeyboardEvent *keyEvent)
{
if (keyEvent->keysym.sym == SDLK_ESCAPE)
{
- state = EXIT;
+ state = EXIT_STATE;
}
}
@@ -329,7 +329,7 @@ int attemptLogin(const std::string& user, const std::string& pass)
(short)config.getValue("port", 0));
if (ret == -1) {
- state = LOGIN;
+ state = LOGIN_STATE;
wrongLoginNotice = new OkDialog("Error",
"Unable to connect to login server");
return LOGIN_NO_CONNECTION;
@@ -378,7 +378,7 @@ int attemptLogin(const std::string& user, const std::string& pass)
server_info[i]->port);
}
- state = CHAR_SERVER;
+ state = CHAR_SERVER_STATE;
skip(msg.getLength());
ret = LOGIN_OK;
@@ -409,11 +409,11 @@ int attemptLogin(const std::string& user, const std::string& pass)
break;
}
skip(msg.getLength());
- state = LOGIN;
+ state = LOGIN_STATE;
}
else {
skip(msg.getLength());
- state = LOGIN;
+ state = LOGIN_STATE;
ret = LOGIN_UNKNOWN_ERROR;
}
// Todo: add other packets, also encrypted
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 5007e5f1..9e6a1b7b 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -138,14 +138,14 @@ void UpdaterWindow::action(const std::string& eventId)
// Skip the updating process
if (mDownloadStatus == UPDATE_COMPLETE)
{
- state = EXIT;
+ state = EXIT_STATE;
}
else {
mDownloadStatus = UPDATE_ERROR;
}
}
else if (eventId == "play") {
- state = LOGIN;
+ state = LOGIN_STATE;
}
}
@@ -201,7 +201,7 @@ int UpdaterWindow::updateProgress(void *ptr,
uw->setLabel(progressString.str().c_str());
uw->setProgress(progress);
- if (state != UPDATE || uw->mDownloadStatus == UPDATE_ERROR) {
+ if (state != UPDATE_STATE || uw->mDownloadStatus == UPDATE_ERROR) {
// If the action was canceled return an error code to stop the mThread
return -1;
}
@@ -311,7 +311,7 @@ void updateInputHandler(SDL_KeyboardEvent *keyEvent)
{
if (keyEvent->keysym.sym == SDLK_ESCAPE)
{
- state = EXIT;
+ state = EXIT_STATE;
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 69158784..ec33a595 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -56,6 +56,7 @@
#include "gui/login.h"
#include "gui/ok_dialog.h"
#include "gui/updatewindow.h"
+#include "gui/error.h"
#include "net/protocol.h"
@@ -101,7 +102,7 @@ Uint32 nextFrame(Uint32 interval, void *param)
class MapStartErrorListener : public gcn::ActionListener {
void action(const std::string &eventId) {
if (eventId == "ok") {
- state = LOGIN;
+ state = LOGIN_STATE;
}
}
} mapStartErrorListener;
@@ -112,7 +113,7 @@ class MapStartErrorListener : public gcn::ActionListener {
class InitWarningListener : public gcn::ActionListener {
void action(const std::string &eventId) {
if (eventId == "ok") {
- state = LOGIN;
+ state = LOGIN_STATE;
}
}
} initWarningListener;
@@ -270,7 +271,7 @@ void init_engine()
hairset = new Spriteset(hairImg, 40, 40);
gui = new Gui(graphics);
- state = UPDATE; /**< Initial game state */
+ state = UPDATE_STATE; /**< Initial game state */
// Initialize sound engine
try {
@@ -384,7 +385,8 @@ int main(int argc, char *argv[])
parseOptions(argc, argv, options);
- if (options.printHelp) {
+ if (options.printHelp)
+ {
printHelp();
return 0;
}
@@ -405,27 +407,24 @@ int main(int argc, char *argv[])
SDL_Event event;
- if (options.skipUpdate && state != ERROR) {
- state = LOGIN;
+ if (options.skipUpdate && state != ERROR)
+ {
+ state = LOGIN_STATE;
}
unsigned int oldstate = !state; // We start with a status change.
Window *currentDialog = NULL;
void (*inputHandler)(SDL_KeyboardEvent*) = NULL;
- Image *login_wallpaper = ResourceManager::getInstance()->
- getImage("graphics/images/login_wallpaper.png");
- if (!login_wallpaper) {
- logger->error("Couldn't load login_wallpaper.png");
- }
+ Image *login_wallpaper = NULL;
- while (state != EXIT)
+ while (state != EXIT_STATE)
{
// Handle SDL events
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
- state = EXIT;
+ state = EXIT_STATE;
break;
case SDL_KEYDOWN:
@@ -437,18 +436,29 @@ int main(int argc, char *argv[])
guiInput->pushInput(event);
}
-
+
gui->logic();
+
+ if (!login_wallpaper)
+ {
+ login_wallpaper = ResourceManager::getInstance()->
+ getImage("graphics/images/login_wallpaper.png");
+ if (!login_wallpaper)
+ {
+ logger->error("Couldn't load login_wallpaper.png");
+ }
+ }
graphics->drawImage(login_wallpaper, 0, 0);
gui->draw();
graphics->updateScreen();
if (state != oldstate) {
- if (oldstate == UPDATE) {
+ if (oldstate == UPDATE_STATE) {
ResourceManager::getInstance()->
searchAndAddArchives("/updates", ".zip", 0);
}
+
oldstate = state;
if (currentDialog) {
@@ -456,22 +466,22 @@ int main(int argc, char *argv[])
}
switch (state) {
- case LOGIN:
+ case LOGIN_STATE:
logger->log("State: LOGIN");
currentDialog = new LoginDialog();
inputHandler = loginInputHandler;
break;
- case CHAR_SERVER:
+ case CHAR_SERVER_STATE:
logger->log("State: CHAR_SERVER");
currentDialog = new ServerSelectDialog();
inputHandler = charServerInputHandler;
break;
- case CHAR_SELECT:
+ case CHAR_SELECT_STATE:
logger->log("State: CHAR_SELECT");
currentDialog = new CharSelectDialog();
inputHandler = charSelectInputHandler;
break;
- case GAME:
+ case GAME_STATE:
sound.fadeOutMusic(1000);
currentDialog = NULL;
@@ -489,22 +499,28 @@ int main(int argc, char *argv[])
new OkDialog("Error", err, &mapStartErrorListener);
}
break;
- case UPDATE:
+ case UPDATE_STATE:
+ logger->log("State: UPDATE");
sound.playMusic(TMW_DATADIR "data/music/Magick - Real.ogg");
currentDialog = new UpdaterWindow();
inputHandler = updateInputHandler;
break;
- case ERROR:
- // Hmm, does this look like an endless loop?
+ case ERROR_STATE:
+ logger->log("State: ERROR");
+ currentDialog = new ErrorDialog("You got disconnected from the server");
+ inputHandler = errorInputHandler;
break;
default:
- state = EXIT;
+ state = EXIT_STATE;
break;
}
}
}
-
- fclose(nullFile);
+
+ if (nullFile)
+ {
+ fclose(nullFile);
+ }
logger->log("State: EXIT");
exit_engine();
PHYSFS_deinit();
diff --git a/src/main.h b/src/main.h
index 54846e70..5f404b10 100644
--- a/src/main.h
+++ b/src/main.h
@@ -31,20 +31,16 @@ class Sound;
#define TMW_DATADIR ""
#endif
-#ifdef ERROR
-#undef ERROR
-#endif
-
enum {
- EXIT,
- LOGIN,
- CHAR_SERVER,
- CHAR_SELECT,
- CHAR_NEW,
- CHAR_DEL,
- GAME,
- ERROR,
- UPDATE
+ EXIT_STATE,
+ LOGIN_STATE,
+ CHAR_SERVER_STATE,
+ CHAR_SELECT_STATE,
+ CHAR_NEW_STATE,
+ CHAR_DEL_STATE,
+ GAME_STATE,
+ ERROR_STATE,
+ UPDATE_STATE
};
/* length definitions for several char[]s in order
diff --git a/src/net/network.cpp b/src/net/network.cpp
index d5a6579b..2d48fc8c 100644
--- a/src/net/network.cpp
+++ b/src/net/network.cpp
@@ -30,6 +30,7 @@
#include "messagein.h"
#include "../log.h"
+#include "../main.h"
/** Warning: buffers and other variables are shared,
so there can be only one connection active at a time */
@@ -215,10 +216,8 @@ void flush()
int ret = SDLNet_TCP_Recv(sock, in + in_size, buffer_size - in_size);
if (ret <= 0)
{
- logger->log("Warning: unknown error when receiving data");
- logger->log("SDLNet_GetError(): %s", SDLNet_GetError());
- // The client disconnected, notify it somewhere
- logger->error("Disconnected from server");
+ logger->log("Error in SDLNet_TCP_Recv(): %s", SDLNet_GetError());
+ state = ERROR_STATE;
return;
}
else {
@@ -232,10 +231,8 @@ void flush()
int ret = SDLNet_TCP_Send(sock, (char*)out, out_size);
if (ret < (int)out_size)
{
- // It is likely that the server disconnected
- std::stringstream ss;
- ss << "Error in SDLNet_TCP_Send(): " << SDLNet_GetError();
- logger->error(ss.str());
+ logger->log("Error in SDLNet_TCP_Send(): %s", SDLNet_GetError());
+ state = ERROR_STATE;
return;
}
out_size -= ret;