summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/account-server/accounthandler.cpp2
-rw-r--r--src/account-server/dalstorage.cpp28
-rw-r--r--src/account-server/dalstorage.hpp2
-rw-r--r--src/account-server/main-account.cpp14
-rw-r--r--src/chat-server/chatchannelmanager.cpp16
-rw-r--r--src/chat-server/chathandler.cpp268
-rw-r--r--src/chat-server/chathandler.hpp48
-rw-r--r--src/chat-server/guild.cpp (renamed from src/account-server/guild.cpp)48
-rw-r--r--src/chat-server/guild.hpp (renamed from src/account-server/guild.hpp)30
-rw-r--r--src/chat-server/guildmanager.cpp (renamed from src/account-server/guildmanager.cpp)56
-rw-r--r--src/chat-server/guildmanager.hpp (renamed from src/account-server/guildmanager.hpp)14
-rw-r--r--src/defines.h72
-rw-r--r--src/game-server/character.hpp4
-rw-r--r--src/game-server/gamehandler.cpp46
-rw-r--r--src/game-server/main-game.cpp5
15 files changed, 326 insertions, 327 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp
index 4e203535..50e9456e 100644
--- a/src/account-server/accounthandler.cpp
+++ b/src/account-server/accounthandler.cpp
@@ -29,8 +29,6 @@
#include "account-server/accountclient.hpp"
#include "account-server/character.hpp"
#include "account-server/dalstorage.hpp"
-#include "account-server/guild.hpp"
-#include "account-server/guildmanager.hpp"
#include "account-server/serverhandler.hpp"
#include "chat-server/chathandler.hpp"
#include "common/configuration.hpp"
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp
index de6c7452..e03c81ed 100644
--- a/src/account-server/dalstorage.cpp
+++ b/src/account-server/dalstorage.cpp
@@ -27,10 +27,9 @@
#include "point.h"
#include "account-server/account.hpp"
-#include "account-server/guild.hpp"
-#include "account-server/guildmanager.hpp"
#include "account-server/dalstoragesql.hpp"
#include "chat-server/chatchannel.hpp"
+#include "chat-server/guild.hpp"
#include "common/configuration.hpp"
#include "dal/dalexcept.h"
#include "dal/dataproviderfactory.h"
@@ -394,26 +393,6 @@ Character *DALStorage::getCharacter(int id, Account *owner)
#if 0
/**
- * Gets a character by character name.
- */
-Character *DALStorage::getCharacter(const std::string &name)
-{
- // look for the character in the list first.
- Characters::iterator it_end = mCharacters.end(),
- it = std::find_if(mCharacters.begin(), it_end, character_by_name(name));
-
- if (it != it_end)
- return *it;
-
- // the account was not in the list, look for it in the database.
- std::ostringstream sql;
- sql << "select * from " << CHARACTERS_TBL_NAME << " where name = '" << name << "';";
- return getCharacterBySQL(sql.str());
-}
-#endif
-
-#if 0
-/**
* Return the list of all Emails addresses.
*/
std::list<std::string>
@@ -1053,8 +1032,6 @@ void DALStorage::removeGuildMember(int guildId, const std::string &memberName)
}
}
-// Guild members should not be stored by name in the database.
-#if 0
/**
* get a list of guilds
*/
@@ -1104,7 +1081,7 @@ std::list<Guild*> DALStorage::getGuildList()
{
Character *character = getCharacter(memberInfo(j,0));
character->addGuild((*itr)->getName());
- (*itr)->addMember(character);
+ (*itr)->addMember(character->getName());
}
}
}
@@ -1115,7 +1092,6 @@ std::list<Guild*> DALStorage::getGuildList()
return guilds;
}
-#endif
std::string DALStorage::getQuestVar(int id, std::string const &name)
{
diff --git a/src/account-server/dalstorage.hpp b/src/account-server/dalstorage.hpp
index ec754238..0ac988e6 100644
--- a/src/account-server/dalstorage.hpp
+++ b/src/account-server/dalstorage.hpp
@@ -92,7 +92,6 @@ class DALStorage
*/
Character *getCharacter(int id, Account *owner);
-#if 0
/**
* Gets a character by character name.
*
@@ -101,7 +100,6 @@ class DALStorage
* @return the character associated to the name
*/
Character *getCharacter(const std::string &name);
-#endif
/**
* Add a new account.
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp
index e0d11c28..6c0fb3a0 100644
--- a/src/account-server/main-account.cpp
+++ b/src/account-server/main-account.cpp
@@ -33,11 +33,11 @@
#endif
#include "account-server/accounthandler.hpp"
-#include "account-server/guildmanager.hpp"
#include "account-server/serverhandler.hpp"
#include "account-server/dalstorage.hpp"
#include "chat-server/chatchannelmanager.hpp"
#include "chat-server/chathandler.hpp"
+#include "chat-server/guildmanager.hpp"
#include "common/configuration.hpp"
#include "net/connectionhandler.hpp"
#include "net/messageout.hpp"
@@ -150,11 +150,6 @@ static void initialize()
// Initialize the Chat channels manager
chatChannelManager = new ChatChannelManager;
-#if 0
- // Initialise the guild manager
- guildManager = new GuildManager;
-#endif
-
// --- Initialize the global handlers
// FIXME: Make the global handlers global vars or part of a bigger
// singleton or a local variable in the event-loop
@@ -194,9 +189,6 @@ static void deinitialize()
// Destroy Managers
delete chatChannelManager;
-#if 0
- delete guildManager;
-#endif
// Get rid of persistent data storage
delete storage;
@@ -293,8 +285,10 @@ static void parseOptions(int argc, char *argv[])
*/
int main(int argc, char *argv[])
{
+#ifdef PACKAGE_VERSION
LOG_INFO("The Mana World Account+Chat Server v" << PACKAGE_VERSION);
-
+#endif
+
// Parse Command Line Options
parseOptions(argc, argv);
diff --git a/src/chat-server/chatchannelmanager.cpp b/src/chat-server/chatchannelmanager.cpp
index fe4a48d9..11fa059f 100644
--- a/src/chat-server/chatchannelmanager.cpp
+++ b/src/chat-server/chatchannelmanager.cpp
@@ -46,17 +46,10 @@ ChatChannelManager::registerPublicChannel(const std::string &channelName,
const std::string &channelAnnouncement,
const std::string &channelPassword)
{
- /* FIXME: This code is ill-designed. If the highest ID is already in use,
- then it is impossible to create new channels, even if there are some
- unused IDs. */
int channelId = 1;
for (ChatChannelIterator i = mChatChannels.begin(),
end = mChatChannels.end(); i != end; ++i)
{
- // Don't allow channels with the same name
- if (i->second.getName() == channelName)
- return 0;
-
// We seek the highest channelId in the public range
if (channelId <= i->first &&
i->first < MAX_PUBLIC_CHANNELS_RANGE)
@@ -65,7 +58,7 @@ ChatChannelManager::registerPublicChannel(const std::string &channelName,
}
}
- // Too much channels registered
+ // Too many channels registered
if (channelId >= MAX_PUBLIC_CHANNELS_RANGE)
return 0;
@@ -84,21 +77,20 @@ ChatChannelManager::registerPrivateChannel(const std::string &channelName,
const std::string &channelAnnouncement,
const std::string &channelPassword)
{
- // FIXME: see above.
int channelId = MAX_PUBLIC_CHANNELS_RANGE;
for (ChatChannelIterator i = mChatChannels.begin(),
end = mChatChannels.end(); i != end; ++i)
{
- if (i->second.getName() == channelName) return 0;
// We seek the highest channelId in the private range
if (channelId <= i->first)
channelId = i->first + 1;
}
- // Too much channels registered
- if (channelId >= MAX_PRIVATE_CHANNELS_RANGE) return 0;
+ // Too many channels registered
+ if (channelId >= MAX_PRIVATE_CHANNELS_RANGE)
+ return 0;
// Register Channel
mChatChannels.insert(std::make_pair(channelId,
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index 0cc91acc..d4db3a74 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -24,9 +24,8 @@
#include <list>
#include "defines.h"
-#include "account-server/guild.hpp"
-#include "account-server/guildmanager.hpp"
-#include "account-server/serverhandler.hpp"
+#include "chat-server/guild.hpp"
+#include "chat-server/guildmanager.hpp"
#include "chat-server/chatchannelmanager.hpp"
#include "chat-server/chatclient.hpp"
#include "chat-server/chathandler.hpp"
@@ -162,6 +161,26 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
case PCMSG_DISCONNECT:
handleDisconnectMessage(computer, message);
break;
+
+ case PCMSG_GUILD_CREATE:
+ handleGuildCreation(computer, message);
+ break;
+
+ case PCMSG_GUILD_INVITE:
+ handleGuildInvitation(computer, message);
+ break;
+
+ case PCMSG_GUILD_ACCEPT:
+ handleGuildAcceptInvite(computer, message);
+ break;
+
+ case PCMSG_GUILD_GET_MEMBERS:
+ handleGuildRetrieveMembers(computer, message);
+ break;
+
+ case PCMSG_GUILD_QUIT:
+ handleGuildQuit(computer, message);
+ break;
default:
LOG_WARN("ChatHandler::processMessage, Invalid message type"
@@ -312,13 +331,11 @@ ChatHandler::handleRegisterChannelMessage(ChatClient &client, MessageIn &msg)
{
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
-#if 0
else if (guildManager->doesExist(channelName))
{
// Channel already exists
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
-#endif
else
{
// We attempt to create a new channel
@@ -386,28 +403,6 @@ ChatHandler::handleUnregisterChannelMessage(ChatClient &client, MessageIn &msg)
else
reply.writeByte(ERRMSG_FAILURE);
}
-/* The chat server should not access directly to the objects of the account
- server, so that they can be splitted later, if needed. */
-#if 0
- else if (guildManager->doesExist(channelName))
- {
- Guild *guild = guildManager->findByName(channelName);
- if (guild->checkLeader(character.get()))
- {
- // TODO: b_lindeijer: I think it would be better if guild
- // channels were removed in response to a guild being
- // removed, as opposed to removing a guild because its
- // channel disappears.
- chatChannelManager->removeChannel(channelId);
- guildManager->removeGuild(guild->getId());
- reply.writeByte(ERRMSG_OK);
- }
- else
- {
- reply.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
- }
- }
-#endif
else
{
reply.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
@@ -455,14 +450,6 @@ void ChatHandler::handleEnterChannelMessage(ChatClient &client, MessageIn &msg)
short channelId = chatChannelManager->getChannelId(channelName);
ChatChannel *channel = chatChannelManager->getChannel(channelId);
-#if 0
- // TODO: b_lindeijer: Currently, the client has to join its guild channels
- // explicitly by sending 'enter channel' messages. This should be
- // changed to implicitly joining relevant guild channels right after
- // login.
- Guild *guild = guildManager->findByName(channelName);
-#endif
-
if (!channelId || !channel)
{
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
@@ -473,25 +460,10 @@ void ChatHandler::handleEnterChannelMessage(ChatClient &client, MessageIn &msg)
// Incorrect password (should probably have its own return value)
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
-#if 0
- else if (guild && !guild->checkInGuild(client.characterName))
- {
- // Player tried to join a guild channel of a guild he's not a member of
- reply.writeByte(ERRMSG_INVALID_ARGUMENT);
- }
-#endif
else
{
if (channel->addUser(&client))
{
-#if 0
- // In the case of a guild, send user joined message.
- if (guild)
- {
- sendUserJoined(channel, client.characterName);
- }
-#endif
-
reply.writeByte(ERRMSG_OK);
// The user entered the channel, now give him the channel
// id, the announcement string and the user list.
@@ -547,20 +519,6 @@ ChatHandler::handleQuitChannelMessage(ChatClient &client, MessageIn &msg)
warnUsersAboutPlayerEventInChat(channel,
client.characterName,
CHAT_EVENT_LEAVING_PLAYER);
-
-#if 0
- // TODO: b_lindeijer: Clients aren't supposed to quit guild
- // channels explicitly, this should rather happen
- // implicitly. See similar note at handling 'enter channel'
- // messages.
- const std::string &channelName = channel->getName();
-
- if (guildManager->doesExist(channelName))
- {
- // Send a user left message
- sendUserLeft(channel, client.characterName);
- }
-#endif
}
client.send(reply);
@@ -592,15 +550,10 @@ ChatHandler::handleListChannelUsersMessage(ChatClient &client, MessageIn &msg)
{
MessageOut reply(CPMSG_LIST_CHANNELUSERS_RESPONSE);
- // TODO: b_lindeijer: Since it only makes sense to ask for the list of
- // users in a channel you're in, this message should really take
- // a channel id instead.
- std::string channelName = msg.readString();
-
- int channelId = chatChannelManager->getChannelId(channelName);
+ int channelId = msg.readLong();
ChatChannel *channel = chatChannelManager->getChannel(channelId);
- reply.writeString(channelName);
+ reply.writeLong(channelId);
if (channel)
{
@@ -626,6 +579,162 @@ ChatHandler::handleDisconnectMessage(ChatClient &client, MessageIn &msg)
}
void
+ChatHandler::handleGuildCreation(ChatClient &client, MessageIn &msg)
+{
+ MessageOut reply(CPMSG_GUILD_CREATE_RESPONSE);
+
+ // Check if guild already exists and if so, return error
+ std::string guildName = msg.readString();
+ if (!guildManager->doesExist(guildName))
+ {
+ // Guild doesnt already exist so create it
+ guildManager->createGuild(guildName, client.characterName);
+ reply.writeByte(ERRMSG_OK);
+ Guild *guild = guildManager->findByName(guildName);
+ reply.writeShort(guild->getId());
+ reply.writeString(guildName);
+ }
+ else
+ {
+ reply.writeByte(ERRMSG_ALREADY_TAKEN);
+ }
+
+ client.send(reply);
+}
+
+void
+ChatHandler::handleGuildInvitation(ChatClient &client, MessageIn &msg)
+{
+ MessageOut reply(CPMSG_GUILD_INVITE_RESPONSE);
+ MessageOut invite(CPMSG_GUILD_INVITED);
+
+ // send an invitation from sender to character to join guild
+ int guildId = msg.readShort();
+ std::string character = msg.readString();
+
+ // get the chat client and the guild
+ ChatClient *invitedClient = mPlayerMap[character];
+ Guild *guild = guildManager->findById(guildId);
+
+ if (invitedClient && guild)
+ {
+ // check permissions of inviter
+ if (guild->checkLeader(client.characterName))
+ {
+ // send the name of the inviter and the name of the guild
+ // that the character has been invited to join
+ std::string senderName = client.characterName;
+ std::string guildName = guild->getName();
+ invite.writeString(senderName);
+ invite.writeString(guildName);
+ invite.writeShort(guildId);
+ invitedClient->send(invite);
+ reply.writeByte(ERRMSG_OK);
+
+ // add member to list of invited members to the guild
+ guild->addInvited(character);
+ }
+ else
+ {
+ reply.writeByte(ERRMSG_FAILURE);
+ }
+ }
+ else
+ {
+ reply.writeByte(ERRMSG_FAILURE);
+ }
+
+ client.send(reply);
+}
+
+void
+ChatHandler::handleGuildAcceptInvite(ChatClient &client, MessageIn &msg)
+{
+ MessageOut reply(CPMSG_GUILD_ACCEPT_RESPONSE);
+ short guildId = msg.readShort();
+
+ // check guild exists and that member was invited
+ // then add them as guild member
+ // and remove from invite list
+ Guild *guild = guildManager->findById(guildId);
+ if (guild)
+ {
+ if (guild->checkInvited(client.characterName))
+ {
+ guild->addMember(client.characterName);
+ reply.writeByte(ERRMSG_OK);
+ reply.writeShort(guild->getId());
+ reply.writeString(guild->getName());
+ }
+ else
+ {
+ reply.writeByte(ERRMSG_FAILURE);
+ }
+ }
+ else
+ {
+ reply.writeByte(ERRMSG_FAILURE);
+ }
+
+ client.send(reply);
+}
+
+void
+ChatHandler::handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg)
+{
+ MessageOut reply(CPMSG_GUILD_GET_MEMBERS_RESPONSE);
+ short guildId = msg.readShort();
+ Guild *guild = guildManager->findById(guildId);
+
+ // check for valid guild
+ // write a list of member names that belong to the guild
+ if (guild)
+ {
+ reply.writeByte(ERRMSG_OK);
+ for(int i = 0; i < guild->totalMembers(); ++i)
+ {
+ reply.writeString(guild->getMember(i));
+ }
+ }
+ else
+ {
+ reply.writeByte(ERRMSG_FAILURE);
+ }
+
+ client.send(reply);
+}
+
+void
+ChatHandler::handleGuildQuit(ChatClient &client, MessageIn &msg)
+{
+ MessageOut reply(CPMSG_GUILD_QUIT_RESPONSE);
+ short guildId = msg.readShort();
+ Guild *guild = guildManager->findById(guildId);
+
+ // check for valid guild
+ // check the member is in the guild
+ // remove the member from the guild
+ if (guild)
+ {
+ if (guild->checkInGuild(client.characterName))
+ {
+ reply.writeByte(ERRMSG_OK);
+ guild->removeMember(client.characterName);
+ }
+ else
+ {
+ reply.writeByte(ERRMSG_FAILURE);
+ }
+ }
+ else
+ {
+ reply.writeByte(ERRMSG_FAILURE);
+ }
+
+ client.send(reply);
+}
+
+void
ChatHandler::sayToPlayer(ChatClient &computer, const std::string &playerName,
const std::string &text)
{
@@ -668,23 +777,6 @@ void ChatHandler::sendInChannel(ChatChannel *channel, MessageOut &msg)
}
}
-void ChatHandler::sendGuildEnterChannel(const MessageOut &msg,
- const std::string &name)
-{
- // TODO: b_lindeijer: This method is just an inefficient way to send a
- // message to a player with a certain name. Would be good to get
- // rid of it.
- for (NetComputers::iterator i = clients.begin(), i_end = clients.end();
- i != i_end; ++i)
- {
- if (static_cast< ChatClient * >(*i)->characterName == name)
- {
- (*i)->send(msg);
- break;
- }
- }
-}
-
void ChatHandler::sendGuildInvite(const std::string &invitedName,
const std::string &inviterName,
const std::string &guildName)
diff --git a/src/chat-server/chathandler.hpp b/src/chat-server/chathandler.hpp
index 1b44772d..30f83b94 100644
--- a/src/chat-server/chathandler.hpp
+++ b/src/chat-server/chathandler.hpp
@@ -51,6 +51,11 @@ class ChatHandler : public ConnectionHandler
std::string character;
unsigned char level;
};
+
+ /**
+ * Map the chat clients to the characters name
+ */
+ std::map<std::string, ChatClient*> mPlayerMap;
public:
@@ -72,20 +77,6 @@ class ChatHandler : public ConnectionHandler
char eventId);
/**
- * Send chat and guild info to chat client, so that they can join the
- * correct channels.
- */
- void sendGuildEnterChannel(const MessageOut &msg,
- const std::string &name);
-
- /**
- * Send guild invite.
- */
- void sendGuildInvite(const std::string &invitedName,
- const std::string &inviterName,
- const std::string &guildName);
-
- /**
* Called by TokenCollector when a client wrongly connected.
*/
void deletePendingClient(ChatClient *);
@@ -120,6 +111,20 @@ class ChatHandler : public ConnectionHandler
* Send messages for each guild the character belongs to.
*/
void sendGuildRejoin(ChatClient &computer);
+
+ /**
+ * Send chat and guild info to chat client, so that they can join the
+ * correct channels.
+ */
+ void sendGuildEnterChannel(const MessageOut &msg,
+ const std::string &name);
+
+ /**
+ * Send guild invite.
+ */
+ void sendGuildInvite(const std::string &invitedName,
+ const std::string &inviterName,
+ const std::string &guildName);
private:
/**
@@ -156,6 +161,21 @@ class ChatHandler : public ConnectionHandler
void
handleDisconnectMessage(ChatClient &client, MessageIn &msg);
+
+ void
+ handleGuildCreation(ChatClient &client, MessageIn &msg);
+
+ void
+ handleGuildInvitation(ChatClient &client, MessageIn &msg);
+
+ void
+ handleGuildAcceptInvite(ChatClient &client, MessageIn &msg);
+
+ void
+ handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg);
+
+ void
+ handleGuildQuit(ChatClient &client, MessageIn &msg);
/**
* Tell the player to be more polite.
diff --git a/src/account-server/guild.cpp b/src/chat-server/guild.cpp
index d2173a03..95b09c43 100644
--- a/src/account-server/guild.cpp
+++ b/src/chat-server/guild.cpp
@@ -17,14 +17,10 @@
* with The Mana World; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id$
+ * $Id: guild.cpp 3549 2007-08-30 16:20:33Z gmelquio $
*/
-
-#if 0
#include "guild.hpp"
-#include "account-server/characterdata.hpp"
-#include "account-server/storage.hpp"
Guild::Guild(const std::string &name) :
mName(name)
@@ -35,33 +31,33 @@ Guild::~Guild()
{
}
-void Guild::addMember(CharacterData* player)
+void Guild::addMember(const std::string &playerName)
{
- mMembers.push_back(player);
+ mMembers.push_back(playerName);
}
-void Guild::removeMember(CharacterData* player)
+void Guild::removeMember(const std::string &playerName)
{
- mMembers.remove(player);
+ mMembers.remove(playerName);
}
-bool Guild::checkLeader(CharacterData *player)
+bool Guild::checkLeader(const std::string &playerName)
{
- CharacterData *leader = mMembers.front();
- return leader == player;
+ std::string leaderName = mMembers.front();
+ return leaderName == playerName;
}
-bool Guild::checkInvited(const std::string &name)
+bool Guild::checkInvited(const std::string &playerName)
{
- return std::find(mInvited.begin(), mInvited.end(), name) != mInvited.end();
+ return std::find(mInvited.begin(), mInvited.end(), playerName) != mInvited.end();
}
-void Guild::addInvited(const std::string &name)
+void Guild::addInvited(const std::string &playerName)
{
- mInvited.push_back(name);
+ mInvited.push_back(playerName);
}
-std::string Guild::getMember(int i) const
+const std::string& Guild::getMember(int i) const
{
int x = 0;
for (guildMembers::const_iterator itr = mMembers.begin();
@@ -70,23 +66,13 @@ std::string Guild::getMember(int i) const
{
if (x == i)
{
- CharacterData *player = (*itr);
- return player->getName();
+ return (*itr);
}
}
- return "";
+ return NULL;
}
-bool Guild::checkInGuild(const std::string &name)
+bool Guild::checkInGuild(const std::string &playerName)
{
- for (guildMembers::iterator itr = mMembers.begin(); itr != mMembers.end(); ++itr)
- {
- CharacterData *player = (*itr);
- if (player->getName() == name)
- {
- return true;
- }
- }
- return false;
+ return std::find(mMembers.begin(), mMembers.end(), playerName) != mMembers.end();
}
-#endif
diff --git a/src/account-server/guild.hpp b/src/chat-server/guild.hpp
index c361c374..dd54d8cc 100644
--- a/src/account-server/guild.hpp
+++ b/src/chat-server/guild.hpp
@@ -17,24 +17,22 @@
* with The Mana World; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id$
+ * $Id: guild.hpp 3549 2007-08-30 16:20:33Z gmelquio $
*/
-#ifndef _TMWSERV_ACCOUNTSERVER_GUILD_H_
-#define _TMWSERV_ACCOUNTSERVER_GUILD_H_
+#ifndef _TMWSERV_CHATSERVER_GUILD_H_
+#define _TMWSERV_CHATSERVER_GUILD_H_
#include <string>
#include <list>
-class Character;
-
/**
* A guild and its members.
*/
class Guild
{
public:
- typedef std::list<Character *> guildMembers;
+ typedef std::list<std::string> guildMembers;
/**
* Constructor.
@@ -49,17 +47,17 @@ class Guild
/**
* Add a member to the guild.
*/
- void addMember(Character *player);
+ void addMember(const std::string &playerName);
/**
* Remove a member from the guild.
*/
- void removeMember(Character *player);
+ void removeMember(const std::string &playerName);
/**
* Check player is the leader of the guild.
*/
- bool checkLeader(Character *player);
+ bool checkLeader(const std::string &playerName);
/**
* Set the ID of the guild.
@@ -70,12 +68,12 @@ class Guild
/**
* Check if player has been invited to the guild.
*/
- bool checkInvited(const std::string &name);
+ bool checkInvited(const std::string &playerName);
/**
* Add a player to the invite list.
*/
- void addInvited(const std::string &name);
+ void addInvited(const std::string &playerName);
/**
* Returns the name of the guild.
@@ -98,17 +96,21 @@ class Guild
/**
* Get a member in the guild.
*/
- std::string getMember(int i) const;
+ const std::string& getMember(int i) const;
/**
* Find member by name.
*/
- bool checkInGuild(const std::string &name);
+ bool checkInGuild(const std::string &playerName);
+
+ /**
+ * Return the ID of the guild leader.
+ */
private:
short mId;
std::string mName;
- std::list<Character *> mMembers;
+ std::list<std::string> mMembers;
std::list<std::string> mInvited;
};
diff --git a/src/account-server/guildmanager.cpp b/src/chat-server/guildmanager.cpp
index 5bdb341c..fc3580f1 100644
--- a/src/account-server/guildmanager.cpp
+++ b/src/chat-server/guildmanager.cpp
@@ -17,21 +17,17 @@
* with The Mana World; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id$
+ * $Id: guildmanager.cpp 3549 2007-08-30 16:20:33Z gmelquio $
*/
-#if 0
#include "guildmanager.hpp"
-
-#include "account-server/characterdata.hpp"
-#include "account-server/guild.hpp"
-#include "account-server/storage.hpp"
+#include "guild.hpp"
+#include "account-server/dalstorage.hpp"
GuildManager::GuildManager()
{
// Load stored guilds from db
- Storage &store = Storage::instance("tmw");
- mGuilds = store.getGuildList();
+ mGuilds = storage->getGuildList();
}
GuildManager::~GuildManager()
@@ -41,19 +37,19 @@ GuildManager::~GuildManager()
{
delete *itr;
}
+ mGuilds.clear();
}
-short GuildManager::createGuild(const std::string &name, CharacterData *player)
+short GuildManager::createGuild(const std::string &name, const std::string &playerName)
{
Guild *guild = new Guild(name);
// Add guild to db
- Storage &store = Storage::instance("tmw");
- store.addGuild(guild);
+ storage->addGuild(guild);
// Make sure to add guild to mGuilds before searching for it to add the
// player
mGuilds.push_back(guild);
- addGuildMember(guild->getId(), player);
+ addGuildMember(guild->getId(), playerName);
return guild->getId();
}
@@ -63,28 +59,27 @@ void GuildManager::removeGuild(short guildId)
Guild *guild = findById(guildId);
if (!guild)
return;
- Storage &store = Storage::instance("tmw");
- store.removeGuild(guild);
+ storage->removeGuild(guild);
+ mGuilds.remove(guild);
+ delete guild;
}
-void GuildManager::addGuildMember(short guildId, CharacterData *player)
+void GuildManager::addGuildMember(short guildId, const std::string &playerName)
{
Guild *guild = findById(guildId);
if (!guild)
return;
- Storage &store = Storage::instance("tmw");
- store.addGuildMember(guildId, player->getName());
- guild->addMember(player);
+ storage->addGuildMember(guildId, playerName);
+ guild->addMember(playerName);
}
-void GuildManager::removeGuildMember(short guildId, CharacterData *player)
+void GuildManager::removeGuildMember(short guildId, const std::string &playerName)
{
Guild *guild = findById(guildId);
if (!guild)
return;
- Storage &store = Storage::instance("tmw");
- store.removeGuildMember(guildId, player->getName());
- guild->removeMember(player);
+ storage->removeGuildMember(guildId, playerName);
+ guild->removeMember(playerName);
if(guild->totalMembers() == 0)
{
removeGuild(guildId);
@@ -93,10 +88,12 @@ void GuildManager::removeGuildMember(short guildId, CharacterData *player)
Guild *GuildManager::findById(short id)
{
- for (std::list<Guild*>::iterator itr = mGuilds.begin();
- itr != mGuilds.end(); ++itr)
+ Guild *guild;
+ for (std::list<Guild*>::iterator itr = mGuilds.begin(),
+ itr_end = mGuilds.end();
+ itr != itr_end; ++itr)
{
- Guild *guild = (*itr);
+ guild = (*itr);
if (guild->getId() == id)
{
return guild;
@@ -107,10 +104,12 @@ Guild *GuildManager::findById(short id)
Guild *GuildManager::findByName(const std::string &name)
{
- for (std::list<Guild*>::iterator itr = mGuilds.begin();
- itr != mGuilds.end(); ++itr)
+ Guild *guild;
+ for (std::list<Guild*>::iterator itr = mGuilds.begin(),
+ itr_end = mGuilds.end();
+ itr != itr_end; ++itr)
{
- Guild *guild = (*itr);
+ guild = (*itr);
if (guild->getName() == name)
{
return guild;
@@ -123,4 +122,3 @@ bool GuildManager::doesExist(const std::string &name)
{
return findByName(name) != NULL;
}
-#endif
diff --git a/src/account-server/guildmanager.hpp b/src/chat-server/guildmanager.hpp
index f9f55312..594a2991 100644
--- a/src/account-server/guildmanager.hpp
+++ b/src/chat-server/guildmanager.hpp
@@ -17,12 +17,14 @@
* with The Mana World; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id$
+ * $Id: guildmanager.hpp 3549 2007-08-30 16:20:33Z gmelquio $
*/
+#ifndef TMW_CHATSERVER_GUILDMANAGER_H
+#define TMW_CHATSERVER_GUILDMANAGER_H
#include <list>
+#include <string>
-class Character;
class Guild;
/**
@@ -44,7 +46,7 @@ class GuildManager
/**
* Creates a guild.
*/
- short createGuild(const std::string &name, Character *player);
+ short createGuild(const std::string &name, const std::string &playerName);
/**
* Removes a guild.
@@ -54,12 +56,12 @@ class GuildManager
/**
* Adds a member to a guild.
*/
- void addGuildMember(short guildId, Character *player);
+ void addGuildMember(short guildId, const std::string &playerName);
/**
* Removes a member from a guild.
*/
- void removeGuildMember(short guildId, Character *player);
+ void removeGuildMember(short guildId, const std::string &playerName);
/**
* Returns the guild with the given id. O(n)
@@ -89,3 +91,5 @@ class GuildManager
};
extern GuildManager *guildManager;
+
+#endif
diff --git a/src/defines.h b/src/defines.h
index d78d6d9e..f8ee5ea1 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -187,23 +187,19 @@ enum {
GPMSG_USE_RESPONSE = 0x0301, // B error
GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*
-#if 0
// Guild
- PGMSG_GUILD_CREATE = 0x0350, // S name
- GPMSG_GUILD_CREATE_RESPONSE = 0x0351, // B error, W id
- PGMSG_GUILD_INVITE = 0x0352, // W id, S name
- GPMSG_GUILD_INVITE_RESPONSE = 0x0353, // B error
- PGMSG_GUILD_ACCEPT = 0x0354, // S name
- GPMSG_GUILD_ACCEPT_RESPONSE = 0x0355, // B error
- PGMSG_GUILD_GET_MEMBERS = 0x0356, // W id
- GPMSG_GUILD_GET_MEMBERS_RESPONSE = 0x0357, // S names
- GPMSG_GUILD_JOINED = 0x0358, // W id, S name
- GPMSG_GUILD_LEFT = 0x0359, // W id
- PGMSG_GUILD_QUIT = 0x0360, // W id
- GPMSG_GUILD_QUIT_RESPONSE = 0x0361, // B error, W id
-#endif
-
- CPMSG_GUILD_INVITED = 0x0370, // S name, S name
+ PCMSG_GUILD_CREATE = 0x0350, // S name
+ CPMSG_GUILD_CREATE_RESPONSE = 0x0351, // B error, W id, S name
+ PCMSG_GUILD_INVITE = 0x0352, // W id, S name
+ CPMSG_GUILD_INVITE_RESPONSE = 0x0353, // B error
+ PCMSG_GUILD_ACCEPT = 0x0354, // W id
+ CPMSG_GUILD_ACCEPT_RESPONSE = 0x0355, // B error, W id, S name, W leader
+ PCMSG_GUILD_GET_MEMBERS = 0x0356, // W id
+ CPMSG_GUILD_GET_MEMBERS_RESPONSE = 0x0357, // S names
+ PCMSG_GUILD_QUIT = 0x0360, // W id
+ CPMSG_GUILD_QUIT_RESPONSE = 0x0361, // B error
+
+ CPMSG_GUILD_INVITED = 0x0370, // S char name, S guild name, W id
CPMSG_GUILD_REJOIN = 0x0371, // S name, W id, W rights
// Chat
@@ -215,21 +211,22 @@ enum {
PCMSG_ANNOUNCE = 0x0411, // S text
PCMSG_PRIVMSG = 0x0412, // S user, S text
// -- Channeling
- PCMSG_REGISTER_CHANNEL = 0x0413, // B pub/priv, S name, S announcement, S password
- CPMSG_REGISTER_CHANNEL_RESPONSE = 0x0414, // B error, W id
- PCMSG_UNREGISTER_CHANNEL = 0x0415, // W channel
- CPMSG_UNREGISTER_CHANNEL_RESPONSE = 0x0416, // B error
- CPMSG_CHANNEL_EVENT = 0x0418, // W channel, B event, S user
- PCMSG_ENTER_CHANNEL = 0x0419, // S channel, S password
- CPMSG_ENTER_CHANNEL_RESPONSE = 0x0420, // B error, W channel
- PCMSG_QUIT_CHANNEL = 0x0421, // W channel
- CPMSG_QUIT_CHANNEL_RESPONSE = 0x0422, // B error
- PCMSG_LIST_CHANNELS = 0x0423, // -
- CPMSG_LIST_CHANNELS_RESPONSE = 0x0424, // W number of channels, S channels
- CPMSG_USERJOINED = 0x0425, // W channel, S name
- CPMSG_USERLEFT = 0x0426, // W channel, S name
- PCMSG_LIST_CHANNELUSERS = 0x0427, // S channel
- CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0428, // S users
+ PCMSG_REGISTER_CHANNEL = 0x0420, // B pub/priv, S name, S announcement, S password
+ CPMSG_REGISTER_CHANNEL_RESPONSE = 0x0421, // B error, W id
+ PCMSG_UNREGISTER_CHANNEL = 0x0422, // W channel
+ CPMSG_UNREGISTER_CHANNEL_RESPONSE = 0x0423, // B error
+ CPMSG_CHANNEL_EVENT = 0x0430, // W channel, B event, S user
+ PCMSG_ENTER_CHANNEL = 0x0440, // S channel, S password
+ CPMSG_ENTER_CHANNEL_RESPONSE = 0x0441, // B error, W channel
+ CPMSG_JOINED_CHANNEL = 0x0442, // S channel, W channel id
+ PCMSG_QUIT_CHANNEL = 0x0443, // W channel
+ CPMSG_QUIT_CHANNEL_RESPONSE = 0x0444, // B error
+ PCMSG_LIST_CHANNELS = 0x0445, // -
+ CPMSG_LIST_CHANNELS_RESPONSE = 0x0446, // W number of channels, S channels
+ CPMSG_USERJOINED = 0x0450, // W channel, S name
+ CPMSG_USERLEFT = 0x0451, // W channel, S name
+ PCMSG_LIST_CHANNELUSERS = 0x0460, // S channel
+ CPMSG_LIST_CHANNELUSERS_RESPONSE = 0x0461, // S users
// Inter-server
GAMSG_REGISTER = 0x0500, // S address, W port, { W map id }*
@@ -245,19 +242,6 @@ enum {
GAMSG_BAN_PLAYER = 0x550, // L id, W duration
GAMSG_STATISTICS = 0x560, // { W map id, W thing nb, W monster nb, W player nb, { L character id }* }*
-#if 0
- GAMSG_GUILD_CREATE = 0x0550, // S name
- AGMSG_GUILD_CREATE_RESPONSE = 0x0551, // B error, W id
- GAMSG_GUILD_INVITE = 0x0552, // W id, S name
- AGMSG_GUILD_INVITE_RESPONSE = 0x0553, // B error
- GAMSG_GUILD_ACCEPT = 0x0554, // S name
- AGMSG_GUILD_ACCEPT_RESPONSE = 0x0555, // B error
- GAMSG_GUILD_GET_MEMBERS = 0x0556, // W id
- AGMSG_GUILD_GET_MEMBERS_RESPONSE = 0x0557, // S names
- GAMSG_GUILD_QUIT = 0x0558, // W id
- AGMSG_GUILD_QUIT_RESPONSE = 0x0559, // B error
-#endif
-
XXMSG_INVALID = 0x7FFF
};
diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp
index b90d2b3c..05834f7d 100644
--- a/src/game-server/character.hpp
+++ b/src/game-server/character.hpp
@@ -275,8 +275,8 @@ class Character : public Being
Character(Character const &);
Character &operator=(Character const &);
- static const float EXPCURVE_EXPONENT = 3.0f; // should maybe be obtained
- static const float EXPCURVE_FACTOR = 10.0f; // from the config file
+ static const float EXPCURVE_EXPONENT = 5.0f; // should maybe be obtained
+ static const float EXPCURVE_FACTOR = 3.0f; // from the config file
static const float LEVEL_SKILL_PRECEDENCE_FACTOR = 0.75f; // I am taking suggestions for a better name
static const int CHARPOINTS_PER_LEVELUP = 5;
static const int CORRECTIONPOINTS_PER_LEVELUP = 2;
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index 249745f4..f9fcf5ec 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -431,52 +431,6 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
computer.character->respawn(); // plausibility check is done by character class
} break;
-
-// The following messages should be handled by the chat server, not the game server.
-#if 0
-
- case PGMSG_GUILD_CREATE:
- {
- std::string name = message.readString();
- int characterId = computer.character->getDatabaseID();
- messageMap[characterId] = computer.character;
- accountHandler->playerCreateGuild(characterId, name);
- } break;
-
- case PGMSG_GUILD_INVITE:
- {
- short guildId = message.readShort();
- std::string member = message.readString();
- int characterId = computer.character->getDatabaseID();
- messageMap[characterId] = computer.character;
- accountHandler->playerInviteToGuild(characterId, guildId, member);
- } break;
-
- case PGMSG_GUILD_ACCEPT:
- {
- std::string guildName = message.readString();
- int characterId = computer.character->getDatabaseID();
- messageMap[characterId] = computer.character;
- accountHandler->playerAcceptInvite(characterId, guildName);
- } break;
-
- case PGMSG_GUILD_GET_MEMBERS:
- {
- short guildId = message.readShort();
- int characterId = computer.character->getDatabaseID();
- messageMap[characterId] = computer.character;
- accountHandler->getGuildMembers(characterId, guildId);
- } break;
-
- case PGMSG_GUILD_QUIT:
- {
- short guildId = message.readShort();
- int characterId = computer.character->getDatabaseID();
- messageMap[characterId] = computer.character;
- accountHandler->quitGuild(characterId, guildId);
- } break;
-#endif
-
default:
LOG_WARN("Invalid message type");
result.writeShort(XXMSG_INVALID);
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 4694e4b2..5d6c0690 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -259,9 +259,10 @@ void parseOptions(int argc, char *argv[])
int main(int argc, char *argv[])
{
int elapsedWorldTicks;
-
+#ifdef PACKAGE_VERSION
LOG_INFO("The Mana World Game Server v" << PACKAGE_VERSION);
-
+#endif
+
// Parse command line options
parseOptions(argc, argv);