summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-04-05 20:22:00 +0300
committerAndrei Karas <akaras@inbox.ru>2015-04-05 20:22:00 +0300
commitbd44e8d0a94dd96e6f8eb0828b4f2b5de902ee83 (patch)
tree28bfbcce0f7f34db5a42c7a27dfdac3a75b80e14
parent84b6217136c8d59347ab9f28ec5e9e4d718d5058 (diff)
downloadplus-bd44e8d0a94dd96e6f8eb0828b4f2b5de902ee83.tar.gz
plus-bd44e8d0a94dd96e6f8eb0828b4f2b5de902ee83.tar.bz2
plus-bd44e8d0a94dd96e6f8eb0828b4f2b5de902ee83.tar.xz
plus-bd44e8d0a94dd96e6f8eb0828b4f2b5de902ee83.zip
add chat command for join chat room.
New chat command: /joinroom NAME
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/actions/commands.cpp17
-rw-r--r--src/actions/commands.h1
-rw-r--r--src/input/inputaction.h1
-rw-r--r--src/input/inputactionmap.h5
-rw-r--r--src/net/eathena/chathandler.cpp25
-rw-r--r--src/resources/chatobject.cpp68
-rw-r--r--src/resources/chatobject.h21
9 files changed, 128 insertions, 12 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 13d3e70aa..68edd4ded 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -588,6 +588,7 @@ SET(SRCS
resources/beinginfo.cpp
resources/beinginfo.h
resources/beingmenuitem.h
+ resources/chatobject.cpp
resources/chatobject.h
resources/db/chardb.cpp
resources/db/chardb.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 7e3efddf2..be74b9256 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -722,6 +722,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
resources/beinginfo.cpp \
resources/beinginfo.h \
resources/beingmenuitem.h \
+ resources/chatobject.cpp \
resources/chatobject.h \
resources/db/chardb.cpp \
resources/db/chardb.h \
diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp
index 76d94886c..18206b9a3 100644
--- a/src/actions/commands.cpp
+++ b/src/actions/commands.cpp
@@ -55,6 +55,7 @@
#include "net/serverfeatures.h"
#include "resources/iteminfo.h"
+#include "resources/chatobject.h"
#include "utils/chatutils.h"
#include "utils/gettext.h"
@@ -881,4 +882,20 @@ impHandler(createPublicChatRoom)
#endif
}
+impHandler(joinChatRoom)
+{
+#ifdef EATHENA_SUPPORT
+ const std::string args = event.args;
+ if (args.empty())
+ return false;
+ ChatObject *const chat = ChatObject::findByName(args);
+ if (!chat)
+ return false;
+ chatHandler->joinChat(chat, "");
+ return true;
+#else
+ return false;
+#endif
+}
+
} // namespace Actions
diff --git a/src/actions/commands.h b/src/actions/commands.h
index f5fa4344b..ef02a70eb 100644
--- a/src/actions/commands.h
+++ b/src/actions/commands.h
@@ -83,6 +83,7 @@ namespace Actions
decHandler(homunEmote);
decHandler(commandHomunEmote);
decHandler(createPublicChatRoom);
+ decHandler(joinChatRoom);
} // namespace Actions
#undef decHandler
diff --git a/src/input/inputaction.h b/src/input/inputaction.h
index 438075dcf..dba7a2a91 100644
--- a/src/input/inputaction.h
+++ b/src/input/inputaction.h
@@ -592,6 +592,7 @@ namespace InputAction
KICK_GUILD,
HAT,
CREATE_PUBLIC_ROOM,
+ JOIN_ROOM,
TOTAL
};
} // namespace InputAction
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index 78e23d819..f923e2000 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -4441,6 +4441,11 @@ static const InputActionData inputActionData[InputAction::TOTAL] = {
InputCondition::INGAME,
"createroom|createpublicroom",
true},
+ {"keyJoinRoom",
+ defaultAction(&Actions::joinChatRoom),
+ InputCondition::INGAME,
+ "joinroom",
+ true},
};
#undef defaultAction
diff --git a/src/net/eathena/chathandler.cpp b/src/net/eathena/chathandler.cpp
index eb7dfe375..77e87df71 100644
--- a/src/net/eathena/chathandler.cpp
+++ b/src/net/eathena/chathandler.cpp
@@ -661,6 +661,7 @@ void ChatHandler::processChatDisplay(Net::MessageIn &msg)
obj->currentUsers = msg.readInt16("current users");
obj->type = msg.readUInt8("type");
obj->title = msg.readString(len, "title");
+ obj->update();
Being *const dstBeing = actorManager->findBeing(obj->ownerId);
if (dstBeing)
@@ -680,14 +681,31 @@ void ChatHandler::joinChat(const ChatObject *const chat,
void ChatHandler::processChatRoomJoinAck(Net::MessageIn &msg)
{
- UNIMPLIMENTEDPACKET;
- const int count = msg.readInt16("len") - 8;
- msg.readInt32("chat id");
+ const int count = (msg.readInt16("len") - 8) / 28;
+ const int id = msg.readInt32("chat id");
+
+ // +++ ignore chat members for now
for (int f = 0; f < count; f ++)
{
msg.readInt32("role");
msg.readString(24, "name");
}
+
+ ChatObject *oldChat = ChatObject::findById(id);
+ if (!oldChat)
+ oldChat = new ChatObject;
+
+ PlayerInfo::setRoomName(oldChat->title);
+ chatWindow->joinRoom(true);
+ ChatObject *const obj = new ChatObject;
+ obj->ownerId = oldChat->ownerId;
+ obj->chatId = oldChat->chatId;
+ obj->maxUsers = oldChat->maxUsers;
+ obj->currentUsers = oldChat->currentUsers;
+ obj->type = oldChat->type;
+ obj->title = oldChat->title;
+ obj->update();
+ localPlayer->setChat(obj);
}
void ChatHandler::processChatRoomLeave(Net::MessageIn &msg)
@@ -863,6 +881,7 @@ void ChatHandler::processChatRoomCreateAck(Net::MessageIn &msg)
obj->currentUsers = 1;
obj->type = 1;
obj->title = mChatRoom;
+ obj->update();
localPlayer->setChat(obj);
break;
}
diff --git a/src/resources/chatobject.cpp b/src/resources/chatobject.cpp
new file mode 100644
index 000000000..fa2663614
--- /dev/null
+++ b/src/resources/chatobject.cpp
@@ -0,0 +1,68 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "resources/chatobject.h"
+
+std::map<std::string, ChatObject*> ChatObject::chatNameMap;
+std::map<int, ChatObject*> ChatObject::chatIdMap;
+
+ChatObject::ChatObject() :
+ ownerId(0),
+ chatId(0),
+ maxUsers(0),
+ currentUsers(0),
+ type(0),
+ title()
+{
+}
+
+ChatObject::~ChatObject()
+{
+ std::map<std::string, ChatObject*>::iterator it = chatNameMap.find(title);
+ if (it != chatNameMap.end())
+ chatNameMap.erase(it);
+ std::map<int, ChatObject*>::iterator it2 = chatIdMap.find(chatId);
+ if (it2 != chatIdMap.end())
+ chatIdMap.erase(it2);
+}
+
+void ChatObject::update()
+{
+ chatNameMap[title] = this;
+ chatIdMap[chatId] = this;
+}
+
+ChatObject *ChatObject::findByName(const std::string &name)
+{
+ std::map<std::string, ChatObject*>::iterator it = chatNameMap.find(name);
+ if (it == chatNameMap.end())
+ return nullptr;
+ else
+ return (*it).second;
+}
+
+ChatObject *ChatObject::findById(const int id)
+{
+ std::map<int, ChatObject*>::iterator it = chatIdMap.find(id);
+ if (it == chatIdMap.end())
+ return nullptr;
+ else
+ return (*it).second;
+}
diff --git a/src/resources/chatobject.h b/src/resources/chatobject.h
index b3945ec5f..431718e41 100644
--- a/src/resources/chatobject.h
+++ b/src/resources/chatobject.h
@@ -25,24 +25,27 @@
struct ChatObject final
{
- ChatObject() :
- ownerId(0),
- chatId(0),
- maxUsers(0),
- currentUsers(0),
- type(0),
- title()
- {
- }
+ ChatObject();
+
+ ~ChatObject();
A_DELETE_COPY(ChatObject)
+ void update();
+
+ static ChatObject *findByName(const std::string &name);
+
+ static ChatObject *findById(const int id);
+
int ownerId;
int chatId;
uint16_t maxUsers;
uint16_t currentUsers;
uint8_t type;
std::string title;
+
+ static std::map<std::string, ChatObject*> chatNameMap;
+ static std::map<int, ChatObject*> chatIdMap;
};
#endif // RESOURCES_CHATOBJECT_H