summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--accountserver.cbp4
-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
14 files changed, 247 insertions, 56 deletions
diff --git a/ChangeLog b/ChangeLog
index 2bc968d..4e514f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-04-16 David Athay <ko2fan@gmail.com>
+
+ * accountserver.cbp, src/chat-server/party.cpp,
+ src/chat-server/chathandler.hpp,
+ src/chat-server/chatchannelmanager.cpp,
+ src/chat-server/chatclient.hpp, src/chat-server/guild.cpp,
+ src/chat-server/party.hpp, src/chat-server/guild.hpp,
+ src/chat-server/chatchannel.hpp, src/chat-server/chathandler.cpp,
+ src/defines.h, src/game-server/gamehandler.cpp,
+ src/game-server/main-game.cpp: Added handling creating and leaving
+ parties. Fixed up some of the private channel stuff that remained.
+
2008-04-15 David Athay <ko2fan@gmail.com>
* src/chat-server/chathandler.cpp: Fixed getting channel userlist.
diff --git a/accountserver.cbp b/accountserver.cbp
index bbb125b..2e2ef00 100644
--- a/accountserver.cbp
+++ b/accountserver.cbp
@@ -71,12 +71,15 @@
<Unit filename="src/chat-server/chatchannel.hpp" />
<Unit filename="src/chat-server/chatchannelmanager.cpp" />
<Unit filename="src/chat-server/chatchannelmanager.hpp" />
+ <Unit filename="src/chat-server/chatclient.hpp" />
<Unit filename="src/chat-server/chathandler.cpp" />
<Unit filename="src/chat-server/chathandler.hpp" />
<Unit filename="src/chat-server/guild.cpp" />
<Unit filename="src/chat-server/guild.hpp" />
<Unit filename="src/chat-server/guildmanager.cpp" />
<Unit filename="src/chat-server/guildmanager.hpp" />
+ <Unit filename="src/chat-server/party.cpp" />
+ <Unit filename="src/chat-server/party.hpp" />
<Unit filename="src/common/configuration.cpp" />
<Unit filename="src/common/configuration.hpp" />
<Unit filename="src/common/inventorydata.hpp" />
@@ -129,6 +132,7 @@
<Extensions>
<code_completion />
<debugger />
+ <envvars />
</Extensions>
</Project>
</CodeBlocks_project_file>
diff --git a/src/chat-server/chatchannel.hpp b/src/chat-server/chatchannel.hpp
index 423bf46..5fce1ab 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 36b8873..03a1c78 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 f08573b..d8c44ba 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 e017157..b058e60 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 3219705..c558326 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 95b09c4..1939d1d 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 17f9efe..42033a0 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 0000000..650903b
--- /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 0000000..31b3984
--- /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 1a19abd..50a854a 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 f9fcf5e..07bf9ad 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 5d6c069..3972738 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);