diff options
author | Hello=) <hello@themanaworld.org> | 2024-03-28 03:58:45 +0300 |
---|---|---|
committer | Hello=) <hello@themanaworld.org> | 2024-03-28 03:58:45 +0300 |
commit | db0b1da0060f5eb4b2af040c22ea9373d36970af (patch) | |
tree | dc2bdc0478c341bf4368fee4993c20e52f2d41c1 /src/main.cpp | |
download | guildbot-db0b1da0060f5eb4b2af040c22ea9373d36970af.tar.gz guildbot-db0b1da0060f5eb4b2af040c22ea9373d36970af.tar.bz2 guildbot-db0b1da0060f5eb4b2af040c22ea9373d36970af.tar.xz guildbot-db0b1da0060f5eb4b2af040c22ea9373d36970af.zip |
Initial commit of Guild Bot, as seen in:
$ sha256sum guildsrc.zip
ef61469ab59ce3f5dd3289505e89bd5b84e3a82b89cda90d25ae3c41f7464beb guildsrc.zip
Verification shown its source 100% match to currently running version on TMWA.
The following changes were made VS version found in guildsrc.zip:
1) src/build and src/dist content completely removed.
Rationale: build-time artifacts; binaries contained login/password.
2) Executable flag (+x) removed from src/automation.cpp and src/main.cpp.
Rationale: executable CPP sources are weird thing. No change to file content.
3) src/main.cpp changes: 3 lines:
std::string main_username = "test";
std::string main_pw = "test";
std::string main_host = "127.0.0.1";
Rationale: avoid leaking real production credentials and ensure experimenters
dont hammer real TMW prod server by experiments.
Effort been made to preserve original file timestamps, etc. However toplevel src/
dir date adjusted to date of mentioned changes.
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..56f7815 --- /dev/null +++ b/src/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); +} + |