summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/account-server/dalstorage.cpp5
-rw-r--r--src/chat-server/chathandler.cpp64
-rw-r--r--src/chat-server/chathandler.hpp25
-rw-r--r--src/chat-server/guild.hpp4
-rw-r--r--src/chat-server/guildmanager.cpp26
-rw-r--r--src/chat-server/guildmanager.hpp6
6 files changed, 105 insertions, 25 deletions
diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp
index 72d1d899..785e8943 100644
--- a/src/account-server/dalstorage.cpp
+++ b/src/account-server/dalstorage.cpp
@@ -396,8 +396,9 @@ Character *DALStorage::getCharacter(int id, Account *owner)
*/
Character *DALStorage::getCharacter(const std::string &name)
{
- // TODO: Get character, this most likely needs to find the account first.
- return NULL;
+ std::ostringstream sql;
+ sql << "select * from " << CHARACTERS_TBL_NAME << " where name = \"" << name << "\";";
+ return getCharacterBySQL(sql.str(), NULL);
}
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index ea5b353c..65e5ccab 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -122,7 +122,7 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
std::string magic_token = message.readString(MAGIC_TOKEN_LENGTH);
mTokenCollector.addPendingClient(magic_token, &computer);
-// sendGuildRejoin(computer);
+ sendGuildRejoin(computer);
return;
}
@@ -598,6 +598,11 @@ ChatHandler::handleGuildCreation(ChatClient &client, MessageIn &msg)
reply.writeByte(ERRMSG_OK);
reply.writeShort(guild->getId());
reply.writeString(guildName);
+ reply.writeByte(true);
+
+ // Send autocreated channel id
+ short channelId = joinGuildChannel(guildName, client);
+ reply.writeShort(channelId);
}
else
{
@@ -670,6 +675,10 @@ ChatHandler::handleGuildAcceptInvite(ChatClient &client, MessageIn &msg)
reply.writeByte(ERRMSG_OK);
reply.writeShort(guild->getId());
reply.writeString(guild->getName());
+ reply.writeByte(false);
+
+ short id = joinGuildChannel(guild->getName(), client);
+ reply.writeShort(id);
}
else
{
@@ -799,17 +808,13 @@ void ChatHandler::sendGuildInvite(const std::string &invitedName,
}
}
-#if 0
void ChatHandler::sendGuildRejoin(ChatClient &client)
{
- // Get character based on name.
- CharacterPtr character = serverHandler->getCharacter(client.characterName);
-
// Get list of guilds and check what rights they have.
- std::vector<std::string> guilds = character->getGuilds();
+ std::vector<Guild*> guilds = guildManager->getGuilds(client.characterName);
for (unsigned int i = 0; i != guilds.size(); ++i)
{
- Guild *guild = guildManager->findByName(guilds[i]);
+ Guild *guild = guilds[i];
short leader = 0;
if (!guild)
{
@@ -819,15 +824,25 @@ void ChatHandler::sendGuildRejoin(ChatClient &client)
{
leader = 1;
}
+
+ std::string guildName = guild->getName();
+
+ // Tell the client what guilds the character belongs to and their permissions
MessageOut msg(CPMSG_GUILD_REJOIN);
- msg.writeString(guild->getName());
+ msg.writeString(guildName);
msg.writeShort(guild->getId());
- msg.writeShort(leader);
+ msg.writeByte(leader);
+
+ // get channel id of guild channel
+ short channelId = joinGuildChannel(guildName, client);
+
+ // send the channel id for the autojoined channel
+ msg.writeShort(channelId);
+
client.send(msg);
- serverHandler->enterChannel(guild->getName(), character.get());
+
}
}
-#endif
void ChatHandler::sendUserJoined(ChatChannel *channel, const std::string &name)
{
@@ -844,3 +859,30 @@ void ChatHandler::sendUserLeft(ChatChannel *channel, const std::string &name)
msg.writeString(name);
sendInChannel(channel, msg);
}
+
+int ChatHandler::joinGuildChannel(const std::string &guildName, ChatClient &client)
+{
+ // Automatically make the character join the guild chat channel
+ // COMMENT: I think it shouldn't need to go through channelId to
+ // get the channel pointer. Also need to change this to registering
+ // a generic channel, rather than public, once public and private
+ // are merged
+ short channelId = chatChannelManager->getChannelId(guildName);
+ ChatChannel *channel = chatChannelManager->getChannel(channelId);
+ if (!channel)
+ {
+ // Channel doesnt exist so create it
+ channelId = chatChannelManager->registerPublicChannel(guildName,
+ "Guild Channel", "");
+ channel = chatChannelManager->getChannel(channelId);
+ }
+
+ // Add user to the channel
+ if (channel->addUser(&client))
+ {
+ // Send an CPMSG_UPDATE_CHANNEL to warn other clients a user went
+ // in the channel.
+ warnUsersAboutPlayerEventInChat(channel, client.characterName,
+ CHAT_EVENT_NEW_PLAYER);
+ }
+}
diff --git a/src/chat-server/chathandler.hpp b/src/chat-server/chathandler.hpp
index 30f83b94..c5d225fd 100644
--- a/src/chat-server/chathandler.hpp
+++ b/src/chat-server/chathandler.hpp
@@ -51,7 +51,7 @@ class ChatHandler : public ConnectionHandler
std::string character;
unsigned char level;
};
-
+
/**
* Map the chat clients to the characters name
*/
@@ -111,14 +111,14 @@ 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.
*/
@@ -161,19 +161,19 @@ 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);
@@ -213,6 +213,15 @@ class ChatHandler : public ConnectionHandler
void sendUserLeft(ChatChannel *channel, const std::string &name);
/**
+ * Retrieves the guild channel or creates one automatically
+ * Automatically makes client join it
+ * @param The name of the guild (and therefore the channel)
+ * @param The client to join the channel
+ * @return Returns the channel Id
+ */
+ int joinGuildChannel(const std::string &name, ChatClient &client);
+
+ /**
* Container for pending clients and pending connections.
*/
TokenCollector<ChatHandler, ChatClient *, Pending *> mTokenCollector;
diff --git a/src/chat-server/guild.hpp b/src/chat-server/guild.hpp
index dd54d8cc..17f9efeb 100644
--- a/src/chat-server/guild.hpp
+++ b/src/chat-server/guild.hpp
@@ -102,10 +102,6 @@ class Guild
* Find member by name.
*/
bool checkInGuild(const std::string &playerName);
-
- /**
- * Return the ID of the guild leader.
- */
private:
short mId;
diff --git a/src/chat-server/guildmanager.cpp b/src/chat-server/guildmanager.cpp
index 2c669e27..12965f1c 100644
--- a/src/chat-server/guildmanager.cpp
+++ b/src/chat-server/guildmanager.cpp
@@ -122,3 +122,29 @@ bool GuildManager::doesExist(const std::string &name)
{
return findByName(name) != NULL;
}
+
+std::vector<Guild*> GuildManager::getGuilds(const std::string &name)
+{
+ Guild *guild;
+ std::vector<Guild*> guildList;
+
+ // Iterate through all guilds, get the number of members
+ // Check if any of the members match the specified name
+ // Add the guild to the list if they match, and return
+ // the list of all guilds the user with that name belongs to
+ for (std::list<Guild*>::iterator itr = mGuilds.begin(),
+ itr_end = mGuilds.end();
+ itr != itr_end; ++itr)
+ {
+ guild = (*itr);
+ for (int i = 0; i < guild->totalMembers(); ++i)
+ {
+ if (guild->getMember(i) == name)
+ {
+ guildList.push_back(guild);
+ break;
+ }
+ }
+ }
+ return guildList;
+}
diff --git a/src/chat-server/guildmanager.hpp b/src/chat-server/guildmanager.hpp
index 2788f999..810b26c8 100644
--- a/src/chat-server/guildmanager.hpp
+++ b/src/chat-server/guildmanager.hpp
@@ -24,6 +24,7 @@
#include <list>
#include <string>
+#include <vector>
class Guild;
@@ -86,6 +87,11 @@ class GuildManager
*/
bool doesExist(const std::string &name);
+ /**
+ * Return the guilds a character is in
+ */
+ std::vector<Guild*> getGuilds(const std::string &name);
+
private:
std::list<Guild*> mGuilds;
};