diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/account-server/accounthandler.cpp | 2 | ||||
-rw-r--r-- | src/account-server/dalstorage.hpp | 4 | ||||
-rw-r--r-- | src/account-server/serverhandler.cpp | 15 | ||||
-rw-r--r-- | src/chat-server/chathandler.cpp | 2 | ||||
-rw-r--r-- | src/common/transaction.hpp (renamed from src/account-server/transaction.hpp) | 19 | ||||
-rw-r--r-- | src/defines.h | 1 | ||||
-rw-r--r-- | src/game-server/accountconnection.cpp | 9 | ||||
-rw-r--r-- | src/game-server/accountconnection.hpp | 5 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 43 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 75 |
10 files changed, 167 insertions, 8 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index a1280e35..425a42ac 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -28,9 +28,9 @@ #include "account-server/character.hpp" #include "account-server/dalstorage.hpp" #include "account-server/serverhandler.hpp" -#include "account-server/transaction.hpp" #include "chat-server/chathandler.hpp" #include "common/configuration.hpp" +#include "common/transaction.hpp" #include "net/connectionhandler.hpp" #include "net/messagein.hpp" #include "net/messageout.hpp" diff --git a/src/account-server/dalstorage.hpp b/src/account-server/dalstorage.hpp index 131cf819..8ff796af 100644 --- a/src/account-server/dalstorage.hpp +++ b/src/account-server/dalstorage.hpp @@ -25,9 +25,9 @@ #include <map> #include <vector> -#include "dal/dataprovider.h" +#include "../dal/dataprovider.h" -#include "transaction.hpp" +#include "../common/transaction.hpp" class Account; class Character; diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 23f2cd32..f5409b6a 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -30,6 +30,7 @@ #include "account-server/character.hpp" #include "account-server/dalstorage.hpp" #include "chat-server/post.hpp" +#include "common/transaction.hpp" #include "net/connectionhandler.hpp" #include "net/messageout.hpp" #include "net/netcomputer.hpp" @@ -465,6 +466,20 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) result.writeByte(ERRMSG_OK); } break; + case GAMSG_TRANSACTION: + { + LOG_DEBUG("TRANSACTION"); + int id = msg.readLong(); + int action = msg.readLong(); + std::string message = msg.readString(); + + Transaction trans; + trans.mCharacterId = id; + trans.mAction = action; + trans.mMessage = message; + storage->addTransaction(trans); + } break; + default: LOG_WARN("ServerHandler::processMessage, Invalid message type: " << msg.getId()); diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp index 555c1a06..8def67fc 100644 --- a/src/chat-server/chathandler.cpp +++ b/src/chat-server/chathandler.cpp @@ -27,11 +27,11 @@ #include "defines.h" #include "account-server/character.hpp" #include "account-server/dalstorage.hpp" -#include "account-server/transaction.hpp" #include "chat-server/guildmanager.hpp" #include "chat-server/chatchannelmanager.hpp" #include "chat-server/chatclient.hpp" #include "chat-server/chathandler.hpp" +#include "common/transaction.hpp" #include "net/connectionhandler.hpp" #include "net/messagein.hpp" #include "net/messageout.hpp" diff --git a/src/account-server/transaction.hpp b/src/common/transaction.hpp index fa007dfb..21a00de8 100644 --- a/src/account-server/transaction.hpp +++ b/src/common/transaction.hpp @@ -43,6 +43,25 @@ enum TRANS_CHANNEL_LIST, TRANS_CHANNEL_USERLIST, TRANS_CHANNEL_TOPIC, + TRANS_CMD_BAN, + TRANS_CMD_DROP, + TRANS_CMD_ITEM, + TRANS_CMD_MONEY, + TRANS_CMD_SETGROUP, + TRANS_CMD_SPAWN, + TRANS_CMD_WARP, + TRANS_ITEM_PICKUP, + TRANS_ITEM_USED, + TRANS_ITEM_DROP, + TRANS_ITEM_MOVE, + TRANS_ATTACK_TARGET, + TRANS_ACTION_CHANGE, + TRANS_TRADE_REQUEST, + TRANS_TRADE_END, + TRANS_TRADE_MONEY, + TRANS_TRADE_ITEM, + TRANS_ATTR_INCREASE, + TRANS_ATTR_DECREASE, }; #endif diff --git a/src/defines.h b/src/defines.h index b03d2bbd..e4421e0c 100644 --- a/src/defines.h +++ b/src/defines.h @@ -259,6 +259,7 @@ enum { CGMSG_POST_RESPONSE = 0x05A1, // L receiver id, { S sender name, S letter, W num attachments { W attachment item id, W quantity } } GCMSG_STORE_POST = 0x05A5, // L sender id, S receiver name, S letter, { W attachment item id, W quantity } CGMSG_STORE_POST_RESPONSE = 0x05A6, // L id, B error + GAMSG_TRANSACTION = 0x0600, // L character id, L action, S message XXMSG_INVALID = 0x7FFF }; diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index a69c5eae..10bc6b46 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -376,3 +376,12 @@ void AccountConnection::updateOnlineStatus(int charId, bool online) mSyncBuffer->writeByte(online ? 0x01 : 0x00); syncChanges(); } + +void AccountConnection::sendTransaction(int id, int action, const std::string &message) +{ + MessageOut msg(GAMSG_TRANSACTION); + msg.writeLong(id); + msg.writeLong(action); + msg.writeString(message); + send(msg); +} diff --git a/src/game-server/accountconnection.hpp b/src/game-server/accountconnection.hpp index 6e7bd1b5..da42ea97 100644 --- a/src/game-server/accountconnection.hpp +++ b/src/game-server/accountconnection.hpp @@ -153,6 +153,11 @@ class AccountConnection : public Connection */ void updateOnlineStatus(int charId, bool online); + /** + * Send transaction to account server + */ + void sendTransaction(int id, int action, const std::string &message); + protected: /** * Processes server messages. diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 3c716da5..3e61fe8f 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -34,6 +34,8 @@ #include "monstermanager.hpp" #include "state.hpp" +#include "../common/transaction.hpp" + #include "../utils/string.hpp" static void say(const std::string error, Character *player) @@ -132,6 +134,7 @@ static void handleHelp(Character *player, std::string &args) say("@reload", player); say("@setgroup <character> <AL level>", player); say("@announce <message>", player); + say("@history <number of transactions>", player); } } else @@ -220,6 +223,10 @@ static void handleWarp(Character *player, std::string &args) // now warp the player GameState::warp(other, map, x, y); + + // log transaction + std::string msg = "User warped to " + xstr + "x" + ystr; + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_WARP, msg); } static void handleItem(Character *player, std::string &args) @@ -293,6 +300,11 @@ static void handleItem(Character *player, std::string &args) // insert the item into the inventory Inventory(other).insert(ic->getDatabaseID(), value); + + // log transaction + std::stringstream str; + str << "User created item " << ic->getDatabaseID(); + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_ITEM, str.str()); } static void handleDrop(Character *player, std::string &args) @@ -344,6 +356,11 @@ static void handleDrop(Character *player, std::string &args) item->setMap(player->getMap()); item->setPosition(player->getPosition()); GameState::insertSafe(item); + + // log transaction + std::stringstream str; + str << "User created item " << ic->getDatabaseID(); + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_DROP, str.str()); } static void handleMoney(Character *player, std::string &args) @@ -391,6 +408,10 @@ static void handleMoney(Character *player, std::string &args) // change how much money the player has Inventory(other).changeMoney(value); + + // log transaction + std::string msg = "User created " + valuestr + " money"; + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_MONEY, msg); } static void handleSpawn(Character *player, std::string &args) @@ -451,6 +472,10 @@ static void handleSpawn(Character *player, std::string &args) // The map is full. Break out. break; } + + // log transaction + std::string msg = "User created monster " + monster->getName(); + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_SPAWN, msg); } } @@ -562,6 +587,10 @@ static void handleBan(Character *player, std::string &args) // ban the player accountHandler->banCharacter(other, length); + + // log transaction + std::string msg = "User banned " + other->getName(); + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_BAN, msg); } static void handleSetGroup(Character *player, std::string &args) @@ -628,6 +657,10 @@ static void handleSetGroup(Character *player, std::string &args) // change the player's account level accountHandler->changeAccountLevel(other, level); + + // log transaction + std::string msg = "User changed account level of " + other->getName() + " to " + levelstr; + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_SETGROUP, msg); } static void handleAttribute(Character *player, std::string &args) @@ -750,7 +783,10 @@ static void handleRights(Character *player) say(str.str(), player); } - +static void handleHistory(Character *player, std::string args) +{ + // TODO: Get args number of transactions and show them to the player +} void CommandHandler::handleCommand(Character *player, const std::string &command) @@ -842,6 +878,11 @@ void CommandHandler::handleCommand(Character *player, if (checkPermission(player, AL_ADMIN)) handleAnnounce(player, args); } + else if (type == "history") + { + if (checkPermission(player, AL_ADMIN)) + handleHistory(player, args); + } else { say("Command not found. Enter @help to view the list of available commands.", player); diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index 675a0fc0..7caa7191 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -24,6 +24,7 @@ #include "game-server/gamehandler.hpp" +#include "common/transaction.hpp" #include "game-server/accountconnection.hpp" #include "game-server/buysell.hpp" #include "game-server/commandhandler.hpp" @@ -195,6 +196,8 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) break; } GameState::sayAround(computer.character, say); + std::string msg = computer.character->getName() + " said " + say; + accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_MSG_PUBLIC, msg); } break; case PGMSG_NPC_TALK: @@ -242,6 +245,12 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) Inventory(computer.character) .insert(ic->getDatabaseID(), item->getAmount()); GameState::remove(item); + // log transaction + std::stringstream str; + str << "User picked up item " << ic->getDatabaseID() + << " at " << opos.x << "x" << opos.y; + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_ITEM_PICKUP, str.str()); break; } } @@ -257,6 +266,12 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) if (ic->use(computer.character)) { inv.removeFromSlot(slot, 1); + // log transaction + std::stringstream str; + str << "User used item " << ic->getDatabaseID() + << " from slot " << slot; + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_ITEM_USED, str.str()); } } } break; @@ -277,7 +292,15 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) // The map is full. Put back into inventory. inv.insert(ic->getDatabaseID(), amount - nb); delete item; + break; } + // log transaction + Point pt = computer.character->getPosition(); + std::stringstream str; + str << "User dropped item " << ic->getDatabaseID() + << " at " << pt.x << "x" << pt.y; + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_ITEM_DROP, str.str()); } } break; @@ -307,6 +330,12 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) int slot2 = message.readByte(); int amount = message.readByte(); Inventory(computer.character).move(slot1, slot2, amount); + // log transaction + std::stringstream str; + str << "User moved item " + << " from slot " << slot1 << " to slot " << slot2; + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_ITEM_MOVE, str.str()); } break; case PGMSG_ATTACK: @@ -346,6 +375,13 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) break; } + // log transaction + std::stringstream str; + str << "User changed action from " << current + << " to " << action; + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_ACTION_CHANGE, str.str()); + } break; case PGMSG_DIRECTION_CHANGE: @@ -398,6 +434,12 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) } new Trade(computer.character, q); + + // log transaction + std::string str; + str = "User requested trade with " + q->getName(); + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_TRADE_REQUEST, str); } break; case PGMSG_TRADE_CANCEL: @@ -405,6 +447,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_TRADE_ADD_ITEM: case PGMSG_TRADE_SET_MONEY: { + std::stringstream str; Trade *t = computer.character->getTrading(); if (!t) break; @@ -415,14 +458,28 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) break; case PGMSG_TRADE_ACCEPT : t->accept(computer.character); + // log transaction + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_TRADE_END, "User finished trading"); break; case PGMSG_TRADE_SET_MONEY: - t->setMoney(computer.character, message.readLong()); - break; + { + int money = message.readLong(); + t->setMoney(computer.character, money); + // log transaction + str << "User added " << money << " money to trade."; + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_TRADE_MONEY, str.str()); + } break; case PGMSG_TRADE_ADD_ITEM: + { int slot = message.readByte(); t->addItem(computer.character, slot, message.readByte()); - break; + // log transaction + str << "User add item from slot " << slot; + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_TRADE_ITEM, str.str()); + } break; } } break; @@ -452,6 +509,12 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) computer.character->getCorrectionPoints(), attribute, computer.character->getAttribute(attribute)); + + // log transaction + std::stringstream str; + str << "User increased attribute " << attribute; + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_ATTR_INCREASE, str.str()); } } break; @@ -472,6 +535,12 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) computer.character->getCorrectionPoints(), attribute, computer.character->getAttribute(attribute)); + + // log transaction + std::stringstream str; + str << "User decreased attribute " << attribute; + accountHandler->sendTransaction(computer.character->getDatabaseID(), + TRANS_ATTR_DECREASE, str.str()); } } break; |