summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-04-16 16:01:28 +0000
committerDavid Athay <ko2fan@gmail.com>2008-04-16 16:01:28 +0000
commit401033859448e3706312192c9b6a85cf93b84a44 (patch)
tree067dd87ac4c97e9e9fc63b9fd0efc60644322791 /src
parent206191086403006db4472d849e9bcf3eaf7f15d0 (diff)
downloadmanaserv-401033859448e3706312192c9b6a85cf93b84a44.tar.gz
manaserv-401033859448e3706312192c9b6a85cf93b84a44.tar.bz2
manaserv-401033859448e3706312192c9b6a85cf93b84a44.tar.xz
manaserv-401033859448e3706312192c9b6a85cf93b84a44.zip
Added handling creating and leaving
parties. Fixed up some of the private channel stuff that remained.
Diffstat (limited to 'src')
-rw-r--r--src/chat-server/chatchannel.hpp6
-rw-r--r--src/chat-server/chatchannelmanager.cpp2
-rw-r--r--src/chat-server/chatclient.hpp7
-rw-r--r--src/chat-server/chathandler.cpp84
-rw-r--r--src/chat-server/chathandler.hpp60
-rw-r--r--src/chat-server/guild.cpp2
-rw-r--r--src/chat-server/guild.hpp6
-rw-r--r--src/chat-server/party.cpp46
-rw-r--r--src/chat-server/party.hpp60
-rw-r--r--src/defines.h6
-rw-r--r--src/game-server/gamehandler.cpp4
-rw-r--r--src/game-server/main-game.cpp4
12 files changed, 231 insertions, 56 deletions
diff --git a/src/chat-server/chatchannel.hpp b/src/chat-server/chatchannel.hpp
index 423bf46f..5fce1abb 100644
--- a/src/chat-server/chatchannel.hpp
+++ b/src/chat-server/chatchannel.hpp
@@ -84,12 +84,6 @@ class ChatChannel
{ return mPassword; }
/**
- * Returns whether this channel is private.
- */
- bool isPrivate() const
- { return !mPassword.empty(); }
-
- /**
* Sets the name of the channel.
*/
void setName(const std::string &channelName)
diff --git a/src/chat-server/chatchannelmanager.cpp b/src/chat-server/chatchannelmanager.cpp
index 36b8873b..03a1c78b 100644
--- a/src/chat-server/chatchannelmanager.cpp
+++ b/src/chat-server/chatchannelmanager.cpp
@@ -77,7 +77,7 @@ std::list<const ChatChannel*> ChatChannelManager::getPublicChannels()
i_end = mChatChannels.end();
i != i_end; ++i)
{
- if (!i->second.isPrivate())
+ if (!i->second.canJoin())
{
channels.push_back(&i->second);
}
diff --git a/src/chat-server/chatclient.hpp b/src/chat-server/chatclient.hpp
index f08573b2..d8c44ba3 100644
--- a/src/chat-server/chatclient.hpp
+++ b/src/chat-server/chatclient.hpp
@@ -30,6 +30,8 @@
#include "net/netcomputer.hpp"
class ChatChannel;
+class Guild;
+class Party;
/**
* A client connected to the chat server. Via this class, the chat server
@@ -42,12 +44,15 @@ class ChatClient : public NetComputer
* Constructor.
*/
ChatClient(ENetPeer *peer):
- NetComputer(peer)
+ NetComputer(peer),
+ party(0)
{
}
std::string characterName;
std::vector< ChatChannel * > channels;
+ std::vector< Guild* > guilds;
+ Party* party;
unsigned char accountLevel;
};
diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp
index e0171578..b058e60d 100644
--- a/src/chat-server/chathandler.cpp
+++ b/src/chat-server/chathandler.cpp
@@ -29,6 +29,7 @@
#include "chat-server/chatchannelmanager.hpp"
#include "chat-server/chatclient.hpp"
#include "chat-server/chathandler.hpp"
+#include "chat-server/party.hpp"
#include "net/connectionhandler.hpp"
#include "net/messagein.hpp"
#include "net/messageout.hpp"
@@ -81,7 +82,7 @@ void ChatHandler::tokenMatched(ChatClient *c, Pending *p)
msg.writeByte(ERRMSG_OK);
c->send(msg);
- // Insert the ChatClient and Character into the Player map
+ // Add chat client to player map
mPlayerMap.insert(std::pair<std::string, ChatClient*>(c->characterName, c));
}
@@ -188,6 +189,13 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message)
handleGuildQuit(computer, message);
break;
+ case PCMSG_PARTY_CREATE:
+ handlePartyCreation(computer, message);
+ break;
+
+ case PCMSG_PARTY_QUIT:
+ handlePartyQuit(computer, message);
+
default:
LOG_WARN("ChatHandler::processMessage, Invalid message type"
<< message.getId());
@@ -302,19 +310,6 @@ ChatHandler::handleRegisterChannelMessage(ChatClient &client, MessageIn &msg)
{
MessageOut reply(CPMSG_REGISTER_CHANNEL_RESPONSE);
- char channelType = msg.readByte();
- if (!channelType) // 0 public, 1 private
- {
- if (client.accountLevel != AL_ADMIN &&
- client.accountLevel != AL_GM)
- {
- // Removed the need for admin/gm rights to create public channels
- //reply.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
- //send message
- //return;
- }
- }
-
std::string channelName = msg.readString();
std::string channelAnnouncement = msg.readString();
std::string channelPassword = msg.readString();
@@ -387,27 +382,12 @@ ChatHandler::handleUnregisterChannelMessage(ChatClient &client, MessageIn &msg)
{
reply.writeByte(ERRMSG_INVALID_ARGUMENT);
}
- else if (channelId < (signed) MAX_PUBLIC_CHANNELS_RANGE)
+ else if (!channel->canJoin())
{
- // Public channel
- if (client.accountLevel == AL_ADMIN || client.accountLevel == AL_GM)
- {
- warnUsersAboutPlayerEventInChat(
- channel, "", CHAT_EVENT_LEAVING_PLAYER);
- if (chatChannelManager->removeChannel(channelId))
- reply.writeByte(ERRMSG_OK);
- else
- reply.writeByte(ERRMSG_FAILURE);
- }
- else
- {
- reply.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
- }
+ reply.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
}
else
{
- // Private channel
-
// We first see if the user is the admin (first user) of the channel
const ChatChannel::ChannelUsers &userList = channel->getUserList();
ChatChannel::ChannelUsers::const_iterator i = userList.begin();
@@ -596,6 +576,9 @@ ChatHandler::handleGuildCreation(ChatClient &client, MessageIn &msg)
// Send autocreated channel id
short channelId = joinGuildChannel(guildName, client);
reply.writeShort(channelId);
+
+ // Add new guild to chatclient
+ client.guilds.push_back(guild);
}
else
{
@@ -675,6 +658,8 @@ ChatHandler::handleGuildAcceptInvite(ChatClient &client, MessageIn &msg)
short id = joinGuildChannel(guild->getName(), client);
reply.writeShort(id);
+
+ client.guilds.push_back(guild);
}
else
{
@@ -700,11 +685,15 @@ ChatHandler::handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg)
// write a list of member names that belong to the guild
if (guild)
{
- reply.writeByte(ERRMSG_OK);
- reply.writeShort(guildId);
- for(int i = 0; i < guild->totalMembers(); ++i)
+ // make sure the requestor is in the guild
+ if (guild->checkInGuild(client.characterName))
{
- reply.writeString(guild->getMember(i));
+ reply.writeByte(ERRMSG_OK);
+ reply.writeShort(guildId);
+ for(int i = 0; i < guild->totalMembers(); ++i)
+ {
+ reply.writeString(guild->getMember(i));
+ }
}
}
else
@@ -800,8 +789,7 @@ void ChatHandler::sendGuildInvite(const std::string &invitedName,
std::map<std::string, ChatClient*>::iterator itr = mPlayerMap.find(invitedName);
if (itr == mPlayerMap.end())
{
- ChatClient *invited = itr->second;
- invited->send(msg);
+ itr->second->send(msg);
}
}
@@ -912,3 +900,25 @@ void ChatHandler::sendGuildListUpdate(const std::string &guildName,
}
}
}
+
+void ChatHandler::handlePartyCreation(ChatClient &client, MessageIn &msg)
+{
+ if (!client.party)
+ {
+ client.party = new Party();
+ client.party->addUser(client.characterName);
+ }
+}
+
+void ChatHandler::handlePartyQuit(ChatClient &client, MessageIn &msg)
+{
+ if (client.party)
+ {
+ client.party->removeUser(client.characterName);
+ if (client.party->numUsers() < 1)
+ {
+ delete client.party;
+ client.party = 0;
+ }
+ }
+}
diff --git a/src/chat-server/chathandler.hpp b/src/chat-server/chathandler.hpp
index 32197057..c558326b 100644
--- a/src/chat-server/chathandler.hpp
+++ b/src/chat-server/chathandler.hpp
@@ -52,9 +52,6 @@ class ChatHandler : public ConnectionHandler
unsigned char level;
};
- /**
- * Map the chat clients to the characters name
- */
std::map<std::string, ChatClient*> mPlayerMap;
public:
@@ -138,52 +135,109 @@ class ChatHandler : public ConnectionHandler
*/
void handleCommand(ChatClient &client, const std::string &command);
+ /**
+ * Deal with Chat messages.
+ */
void
handleChatMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with Announcement messages.
+ */
void
handleAnnounceMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with Private messages.
+ */
void
handlePrivMsgMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with channel registration.
+ */
void
handleRegisterChannelMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with channel unregistering.
+ */
void
handleUnregisterChannelMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with player entering channel.
+ */
void
handleEnterChannelMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with player leaving channel.
+ */
void
handleQuitChannelMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with listing all accessible channels.
+ */
void
handleListChannelsMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with listing all channel users in a channel.
+ */
void
handleListChannelUsersMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with disconnection.
+ */
void
handleDisconnectMessage(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with creating a guild.
+ */
void
handleGuildCreation(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with inviting a player to a guild.
+ */
void
handleGuildInvitation(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with accepting an invite to join a guild.
+ */
void
handleGuildAcceptInvite(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with returning all the guild members of a guild.
+ */
void
handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg);
+ /**
+ * Deal with leaving a guild.
+ */
void
handleGuildQuit(ChatClient &client, MessageIn &msg);
/**
+ * Deal with creating a party.
+ */
+ void
+ handlePartyCreation(ChatClient &client, MessageIn &msg);
+
+ /**
+ * Deal with Announcement messages.
+ */
+ void
+ handlePartyQuit(ChatClient &client, MessageIn &msg);
+
+ /**
* Tell the player to be more polite.
*/
void warnPlayerAboutBadWords(ChatClient &computer);
diff --git a/src/chat-server/guild.cpp b/src/chat-server/guild.cpp
index 95b09c43..1939d1d4 100644
--- a/src/chat-server/guild.cpp
+++ b/src/chat-server/guild.cpp
@@ -60,7 +60,7 @@ void Guild::addInvited(const std::string &playerName)
const std::string& Guild::getMember(int i) const
{
int x = 0;
- for (guildMembers::const_iterator itr = mMembers.begin();
+ for (GuildMembers::const_iterator itr = mMembers.begin();
itr != mMembers.end();
++itr, ++x)
{
diff --git a/src/chat-server/guild.hpp b/src/chat-server/guild.hpp
index 17f9efeb..42033a0e 100644
--- a/src/chat-server/guild.hpp
+++ b/src/chat-server/guild.hpp
@@ -32,7 +32,7 @@
class Guild
{
public:
- typedef std::list<std::string> guildMembers;
+ typedef std::list<std::string> GuildMembers;
/**
* Constructor.
@@ -106,8 +106,8 @@ class Guild
private:
short mId;
std::string mName;
- std::list<std::string> mMembers;
- std::list<std::string> mInvited;
+ GuildMembers mMembers;
+ GuildMembers mInvited;
};
#endif
diff --git a/src/chat-server/party.cpp b/src/chat-server/party.cpp
new file mode 100644
index 00000000..650903b6
--- /dev/null
+++ b/src/chat-server/party.cpp
@@ -0,0 +1,46 @@
+/*
+ * The Mana World Server
+ * Copyright 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: $
+ */
+
+#include "party.hpp"
+
+Party::Party()
+{
+
+}
+
+void Party::addUser(const std::string &name)
+{
+ if (std::find(mUsers.begin(), mUsers.end(), name) == mUsers.end())
+ {
+ mUsers.push_back(name);
+ }
+}
+
+void Party::removeUser(const std::string &name)
+{
+ PartyUsers::iterator itr = std::find(mUsers.begin(), mUsers.end(), name);
+ if (itr != mUsers.end())
+ {
+ mUsers.erase(itr);
+ }
+}
diff --git a/src/chat-server/party.hpp b/src/chat-server/party.hpp
new file mode 100644
index 00000000..31b39840
--- /dev/null
+++ b/src/chat-server/party.hpp
@@ -0,0 +1,60 @@
+/*
+ * The Mana World Server
+ * Copyright 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: $
+ */
+
+#ifndef _TMWSERV_PARTY_H_
+#define _TMWSERV_PARTY_H_
+
+#include <string>
+#include <vector>
+
+/**
+ * A party that contains 1 or more characters to play together
+ */
+class Party
+{
+public:
+ typedef std::vector<std::string> PartyUsers;
+
+ /** Constructor */
+ Party();
+
+ /**
+ * Add user to party
+ */
+ void addUser(const std::string &name);
+
+ /**
+ * Remove user from party
+ */
+ void removeUser(const std::string &name);
+
+ /**
+ * Return number of users in party
+ */
+ unsigned int numUsers() { return mUsers.size(); }
+
+private:
+ PartyUsers mUsers;
+};
+
+#endif
diff --git a/src/defines.h b/src/defines.h
index 1a19abd5..50a854a6 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -203,6 +203,12 @@ enum {
CPMSG_GUILD_INVITED = 0x0370, // S char name, S guild name, W id
CPMSG_GUILD_REJOIN = 0x0371, // S name, W guild, B rights, W channel
+ // Party
+ PCMSG_PARTY_CREATE = 0x03A0, // -
+ CPMSG_PARTY_CREATE_RESPONSE = 0x03A1, // B error
+ PCMSG_PARTY_QUIT = 0x03AA, // -
+ CPMSG_PARTY_QUIT_RESPONSE = 0x03AB, // B error
+
// Chat
CPMSG_ERROR = 0x0401, // B error
CPMSG_ANNOUNCEMENT = 0x0402, // S text
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index f9fcf5ec..07bf9ad1 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -135,11 +135,11 @@ static Character *findCharacterNear(Object *p, int id)
MapComposite *map = p->getMap();
Point const &ppos = p->getPosition();
// TODO: use a less arbitrary value.
- for (CharacterIterator i(map->getAroundPointIterator(ppos, 48)); i; ++i)
+ for (CharacterIterator i(map->getAroundPointIterator(ppos, 64)); i; ++i)
{
Character *o = *i;
if (o->getPublicID() != id) continue;
- return ppos.inRangeOf(o->getPosition(), 48) ? o : NULL;
+ return ppos.inRangeOf(o->getPosition(), 64) ? o : NULL;
}
return NULL;
}
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 5d6c0690..39727384 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -54,7 +54,7 @@
#define DEFAULT_MAPSDB_FILE "maps.xml"
#define DEFAULT_MONSTERSDB_FILE "monsters.xml"
-utils::Timer worldTimer(100, false); /**< Timer for world tics set to 100 ms */
+utils::Timer worldTimer(150, false); /**< Timer for world tics set to 100 ms */
int worldTime = 0; /**< Current world time in 100ms ticks */
bool running = true; /**< Determines if server keeps running */
@@ -262,7 +262,7 @@ int main(int argc, char *argv[])
#ifdef PACKAGE_VERSION
LOG_INFO("The Mana World Game Server v" << PACKAGE_VERSION);
#endif
-
+
// Parse command line options
parseOptions(argc, argv);