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/net/nethandler.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/net/nethandler.cpp~')
-rw-r--r-- | src/net/nethandler.cpp~ | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/src/net/nethandler.cpp~ b/src/net/nethandler.cpp~ new file mode 100644 index 0000000..d6f031e --- /dev/null +++ b/src/net/nethandler.cpp~ @@ -0,0 +1,183 @@ +#include "nethandler.h" +#include "network.h" +#include "protocol.h" +#include "messageout.h" + +#include "loginhandler.h" +#include "chathandler.h" +#include "charserverhandler.h" +#include "maploginhandler.h" + +#include "../log.h" +#include "../main.h" +#include "../game.h" + +static NetHandler *NetInstance = NULL; +static Network *mNetwork = NULL; +MessageHandler *mChatHandler = NULL; + +LoginHandler loginHandler; +CharServerHandler charServerHandler; +MapLoginHandler mapLoginHandler; + +NetHandler::NetHandler() +{ + NetInstance = this; +} + +NetHandler::~NetHandler() +{ + delete mNetwork; + + if (mChatHandler != NULL) + delete mChatHandler; + + delete NetInstance; +} + +void NetHandler::clean_up() +{ + delete mNetwork; + + if (mChatHandler != NULL) // fix a crash caused by map server D/C + delete mChatHandler; + + mNetwork = new Network(); +} + +NetHandler *NetHandler::getNetInstance() +{ + return NetInstance; +} + +Network *NetHandler::getNetwork() +{ + if (mNetwork == NULL) + mNetwork = new Network(); + + return mNetwork; +} + +void NetHandler::loadHandlers() +{ + mChatHandler = new ChatHandler(); + mNetwork->registerHandler(mChatHandler); +} + +// All code related to login, from main.cpp + +void NetHandler::accountLogin(LoginData *loginData) +{ + /* + logger->log("Trying to connect to account server..."); + logger->log("Username is %s", loginData->username.c_str());*/ + mNetwork->connect(loginData->hostname, loginData->port); + mNetwork->registerHandler(&loginHandler); + loginHandler.setLoginData(loginData); + + // Send login infos + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x0064); + outMsg.writeInt32(0); // client version + outMsg.writeString(loginData->username, 24); + outMsg.writeString(loginData->password, 24); + outMsg.writeInt8(0); // unknown +} + +void NetHandler::charLogin(LoginData *loginData) +{ + /*logger->log("Trying to connect to char server..."); + + logger->log("Server: %s (%s:%d)", + server_info[0]->name.c_str(), + loginData->hostname.c_str(), + loginData->port);*/ + + mNetwork->connect(loginData->hostname, loginData->port); + mNetwork->registerHandler(&charServerHandler); + charServerHandler.setLoginData(loginData); + + // Send login infos + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x0065); + outMsg.writeInt32(loginData->account_ID); + outMsg.writeInt32(loginData->session_ID1); + outMsg.writeInt32(loginData->session_ID2); + outMsg.writeInt16(0); // unknown + outMsg.writeInt8(loginData->sex); + + // We get 4 useless bytes before the real answer comes in + mNetwork->skip(4); +} + +void NetHandler::mapLogin(LoginData *loginData) +{ + MessageOut outMsg(mNetwork); + + /*logger->log("Trying to connect to map server..."); + logger->log("Map: %s", map_path.c_str());*/ + + mNetwork->connect(loginData->hostname, loginData->port); + mNetwork->registerHandler(&mapLoginHandler); + + // Send login infos + outMsg.writeInt16(0x0072); + outMsg.writeInt32(loginData->account_ID); + outMsg.writeInt32(charID[main_charno]); + outMsg.writeInt32(loginData->session_ID1); + outMsg.writeInt32(loginData->session_ID2); + outMsg.writeInt8(loginData->sex); + + // We get 4 useless bytes before the real answer comes in + mNetwork->skip(4); +} + +// add a few of the packets that need to be sent. +void NetHandler::attemptCharSelect() +{ + /*logger->log("CharServer: Character Select: %s", + char_name.c_str());*/ + // Request character selection + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x0066); + outMsg.writeInt8(main_charno); +} + +void NetHandler::mapLoaded() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_MAP_LOADED); +} + +void NetHandler::privateMessage(std::string name, std::string msg) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CHAT_WHISPER); + outMsg.writeInt16(static_cast<short>(msg.length() + 28)); + outMsg.writeString(name, 24); + outMsg.writeString(msg, static_cast<int>(msg.length())); +} + +void NetHandler::publicMessage(std::string msg) +{ + std::string mes = std::string("guild") + " : " + msg; + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CHAT_MESSAGE); + outMsg.writeInt16(static_cast<short>(mes.length() + 4 + 1)); + outMsg.writeString(mes, static_cast<int>(mes.length() + 1)); +} + +void NetHandler::sit() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_PLAYER_CHANGE_ACT); + outMsg.writeInt32(0); + outMsg.writeInt8(2); +} + +void NetHandler::ping(int tick) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CLIENT_PING); + outMsg.writeInt32(tick); +}
\ No newline at end of file |