summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorHello=) <hello@themanaworld.org>2024-03-29 04:23:18 +0300
committerHello=) <hello@themanaworld.org>2024-03-29 04:23:18 +0300
commit08cd08587be5c8d2ce42ae417098c524f683c6ad (patch)
tree727aa239372a77e9ca3d72fe761940bb49e8d2d8 /main.cpp
parentdb0b1da0060f5eb4b2af040c22ea9373d36970af (diff)
downloadguildbot-08cd08587be5c8d2ce42ae417098c524f683c6ad.tar.gz
guildbot-08cd08587be5c8d2ce42ae417098c524f683c6ad.tar.bz2
guildbot-08cd08587be5c8d2ce42ae417098c524f683c6ad.tar.xz
guildbot-08cd08587be5c8d2ce42ae417098c524f683c6ad.zip
Move actual top level from src/ to top: just one single dir is pointless.
Reported-By: NetSysFire
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp153
1 files changed, 153 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..56f7815
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,153 @@
+/*
+ * File: main.cpp
+ * Author: dipesh
+ *
+ * Created on July 31, 2010, 6:04 PM
+ */
+
+#include <stdlib.h>
+#include <iostream>
+#include <string>
+#include <SDL.h>
+
+#include "logindata.h"
+#include "game.h"
+#include "main.h"
+#include "automation.h"
+
+#include "net/charserverhandler.h"
+#include "net/loginhandler.h"
+#include "net/maploginhandler.h"
+#include "net/messagein.h"
+#include "net/messageout.h"
+#include "net/network.h"
+#include "net/nethandler.h"
+#include "serverinfo.h"
+
+#if defined WIN32
+#include "Windows.h"
+#include "Winbase.h"
+#include "utils/specialfolder.h"
+#endif
+
+unsigned char state = LOGIN_STATE;
+unsigned char oldstate;
+std::string errorMessage;
+char n_server, n_character;
+
+class SERVER_INFO;
+SERVER_INFO **server_info;
+
+std::string main_username = "test";
+std::string main_pw = "test";
+std::string main_host = "127.0.0.1";
+int main_charno = 1; //character slot
+
+int main_port = 6901;
+
+int charID[3];
+int world;
+std::string char_name;
+std::string mLocalDataDir;
+
+LoginData loginData;
+
+void init_engine()
+{
+
+ if (SDL_Init(SDL_INIT_TIMER) < 0) {
+ std::cerr << "Could not initialize SDL: " <<
+ SDL_GetError() << std::endl;
+ exit(1);
+ }
+
+ atexit(SDL_Quit);
+ mLocalDataDir = ".";
+
+#if defined WIN32
+ mLocalDataDir = getSpecialFolderLocation(CSIDL_LOCAL_APPDATA);
+ mLocalDataDir += "/ManaGuild";
+#endif
+}
+
+int main(int argc, char **argv)
+{
+ Automation::getAutomationHandler()->loadMembers();
+
+ init_engine();
+ SDLNet_Init();
+ Network *network = NetHandler::getNetInstance()->getNetwork();
+ Game *game = new Game();
+
+ while (state != EXIT_STATE)
+ {
+ network->flush();
+ network->dispatchMessages();
+
+ if (network->getState() == Network::ERROR_BROKE)
+ {
+ state = ERROR_STATE;
+ errorMessage = "Got disconnected from server!";
+ }
+
+ if (state != oldstate)
+ {
+ oldstate = state;
+
+ switch (oldstate)
+ {
+ // Those states that don't cause a network disconnect
+ case ACCOUNT_STATE:
+ case CHAR_SELECT_STATE:
+ case GAME_STATE:
+ break;
+
+ default:
+ network->disconnect();
+ network->clearHandlers();
+ break;
+ }
+
+ switch (state)
+ {
+ case LOGIN_STATE:
+ state = ACCOUNT_STATE;
+ break;
+ case ACCOUNT_STATE:
+ loginData.hostname = main_host;
+ loginData.port = main_port;
+ loginData.password = main_pw;
+ loginData.username = main_username;
+ NetHandler::getNetInstance()->accountLogin(&loginData);
+ break;
+ case CHAR_SERVER_STATE:
+ {
+ SERVER_INFO *si = server_info[world];
+ loginData.hostname = iptostring(si->address);
+ loginData.port = si->port;
+ NetHandler::getNetInstance()->charLogin(&loginData);
+ break;
+ }
+ case CHAR_SELECT_STATE:
+ NetHandler::getNetInstance()->attemptCharSelect();
+ break;
+ case CONNECTING_STATE:
+ NetHandler::getNetInstance()->mapLogin(&loginData);
+ break;
+ case GAME_STATE:
+ game->logic();
+ break;
+ case ERROR_STATE:
+ state = EXIT_STATE; //LOGIN_STATE
+ break;
+ default:
+ state = EXIT_STATE;
+ break;
+ }
+ }
+ }
+
+ delete game;
+ return (EXIT_SUCCESS);
+}
+