summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-26 09:42:43 -0600
committerJared Adams <jaxad0127@gmail.com>2009-03-26 09:42:43 -0600
commit9e4a8ea095a1a0613d7b128f4e29c69643137b07 (patch)
tree82dfb0a17dfc3439554efc77a3d18bf5165cebc3 /src
parentcdcadf6e99a6deaa5b929cdec9736ab1fb280f65 (diff)
downloadmana-9e4a8ea095a1a0613d7b128f4e29c69643137b07.tar.gz
mana-9e4a8ea095a1a0613d7b128f4e29c69643137b07.tar.bz2
mana-9e4a8ea095a1a0613d7b128f4e29c69643137b07.tar.xz
mana-9e4a8ea095a1a0613d7b128f4e29c69643137b07.zip
Add ChannelTab for chat channels
This fixes TMWServ compilation form the previous commit.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/channel.cpp9
-rw-r--r--src/channel.h14
-rw-r--r--src/commandhandler.cpp19
-rw-r--r--src/gui/chat.cpp12
-rw-r--r--src/gui/chat.h5
-rw-r--r--src/gui/widgets/channeltab.cpp70
-rw-r--r--src/gui/widgets/channeltab.h54
-rw-r--r--src/gui/widgets/chattab.cpp38
-rw-r--r--src/gui/widgets/chattab.h11
-rw-r--r--src/net/tmwserv/chathandler.cpp15
-rw-r--r--src/net/tmwserv/guildhandler.cpp8
12 files changed, 216 insertions, 41 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 6914fb5c..964ca076 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,8 @@ tmw_CXXFLAGS = -DPKG_DATADIR=\""$(pkgdatadir)/"\" \
tmw_SOURCES = gui/widgets/avatar.cpp \
gui/widgets/avatar.h \
+ gui/widgets/channeltab.cpp \
+ gui/widgets/channeltab.h \
gui/widgets/chattab.cpp \
gui/widgets/chattab.h \
gui/widgets/dropdown.cpp \
diff --git a/src/channel.cpp b/src/channel.cpp
index f5a0dd2a..0cd850a9 100644
--- a/src/channel.cpp
+++ b/src/channel.cpp
@@ -19,9 +19,16 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
#include "channel.h"
+#ifdef TMWSERV_SUPPORT
+#include "net/tmwserv/chatserver/chatserver.h"
+#include "net/tmwserv/gameserver/player.h"
+#else
+#include "net/messageout.h"
+#include "net/ea/protocol.h"
+#endif
+
Channel::Channel(short id,
const std::string &name,
const std::string &announcement) :
diff --git a/src/channel.h b/src/channel.h
index c094aedc..d9f72c12 100644
--- a/src/channel.h
+++ b/src/channel.h
@@ -19,8 +19,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifndef CHANNEL_H
+#define CHANNEL_H
+
#include <string>
+#include "gui/widgets/channeltab.h"
+
class Channel
{
public:
@@ -64,8 +69,17 @@ class Channel
void setAnnouncement(const std::string &channelAnnouncement)
{ mAnnouncement = channelAnnouncement; }
+ ChannelTab *getTab() { return mTab; }
+
+ protected:
+ friend class ChannelTab;
+ void setTab(ChannelTab *tab) { mTab = tab; }
+
private:
unsigned short mId;
std::string mName;
std::string mAnnouncement;
+ ChannelTab *mTab;
};
+
+#endif // CHANNEL_H
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index e5f26444..1156cb38 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -26,6 +26,7 @@
#include "game.h"
#include "localplayer.h"
+#include "gui/widgets/channeltab.h"
#include "gui/chat.h"
#ifdef TMWSERV_SUPPORT
@@ -410,12 +411,14 @@ void CommandHandler::handleListChannels()
void CommandHandler::handleListUsers()
{
- Net::ChatServer::getUserList(chatWindow->getFocused());
+ Net::ChatServer::getUserList(chatWindow->getFocused()->getCaption());
}
void CommandHandler::handleTopic(const std::string &args)
{
- if (Channel *channel = channelManager->findByName(chatWindow->getFocused()))
+ ChannelTab *tab = dynamic_cast<ChannelTab*>(chatWindow->getFocused());
+ Channel *channel = tab ? tab->getChannel() : NULL;
+ if (channel)
{
Net::ChatServer::setChannelTopic(channel->getId(), args);
}
@@ -427,7 +430,9 @@ void CommandHandler::handleTopic(const std::string &args)
void CommandHandler::handleQuit()
{
- if (Channel *channel = channelManager->findByName(chatWindow->getFocused()))
+ ChannelTab *tab = dynamic_cast<ChannelTab*>(chatWindow->getFocused());
+ Channel *channel = tab ? tab->getChannel() : NULL;
+ if (channel)
{
Net::ChatServer::quitChannel(channel->getId());
}
@@ -439,7 +444,9 @@ void CommandHandler::handleQuit()
void CommandHandler::handleOp(const std::string &args)
{
- if (Channel *channel = channelManager->findByName(chatWindow->getFocused()))
+ ChannelTab *tab = dynamic_cast<ChannelTab*>(chatWindow->getFocused());
+ Channel *channel = tab ? tab->getChannel() : NULL;
+ if (channel)
{
// set the user mode 'o' to op a user
if (args != "")
@@ -455,7 +462,9 @@ void CommandHandler::handleOp(const std::string &args)
void CommandHandler::handleKick(const std::string &args)
{
- if (Channel *channel = channelManager->findByName(chatWindow->getFocused()))
+ ChannelTab *tab = dynamic_cast<ChannelTab*>(chatWindow->getFocused());
+ Channel *channel = tab ? tab->getChannel() : NULL;
+ if (channel)
{
if (args != "")
{
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 5c15580d..8961b704 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -34,6 +34,7 @@
#include "../configuration.h"
#include "../localplayer.h"
+#include "../utils/dtor.h"
#include "../utils/stringutils.h"
#ifdef TMWSERV_SUPPORT
@@ -94,6 +95,7 @@ ChatWindow::~ChatWindow()
config.setValue("ReturnToggles", mReturnToggles ? "1" : "0");
delete mRecorder;
#endif
+ delete_all(mTabs);
delete mItemLinkHandler;
}
@@ -140,13 +142,15 @@ void ChatWindow::logic()
void ChatWindow::chatLog(std::string line, int own, std::string channelName,
bool ignoreRecord)
{
- if(channelName.empty())
+ ChatTab *tab;
+ if(!channelName.empty())
+ tab = findTab(channelName);
+ else
#ifdef TMWSERV_SUPPORT
- channelName = getFocused();
+ tab = getFocused();
#else
- channelName = "General";
+ tab = findTab("General");
#endif
- ChatTab *tab = findTab(channelName);
tab->chatLog(line, own, ignoreRecord);
}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index fa63cedd..89bb033e 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -178,11 +178,6 @@ class ChatWindow : public Window,
/** Add the tab to the window */
void addTab(ChatTab *tab);
- /** Called to output text to a specific channel */
- void sendToChannel(short channel,
- const std::string &user,
- const std::string &msg);
-
/**
* Passes the text to the current tab as input
*
diff --git a/src/gui/widgets/channeltab.cpp b/src/gui/widgets/channeltab.cpp
new file mode 100644
index 00000000..f8c92a6e
--- /dev/null
+++ b/src/gui/widgets/channeltab.cpp
@@ -0,0 +1,70 @@
+/*
+ * The Mana World
+ * Copyright (C) 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <guichan/widgets/label.hpp>
+
+#include "channeltab.h"
+
+#include "../browserbox.h"
+#include "../chatinput.h"
+#include "../itemlinkhandler.h"
+#include "../recorder.h"
+#include "../scrollarea.h"
+
+#include "../../beingmanager.h"
+#include "../../commandhandler.h"
+#include "../../channel.h"
+#include "../../configuration.h"
+#include "../../game.h"
+#include "../../localplayer.h"
+
+#ifdef TMWSERV_SUPPORT
+#include "../../net/tmwserv/chatserver/chatserver.h"
+#include "../../net/tmwserv/gameserver/player.h"
+#else
+#include "../../party.h"
+#include "../../net/messageout.h"
+#include "../../net/ea/protocol.h"
+#endif
+
+#include "../../resources/iteminfo.h"
+#include "../../resources/itemdb.h"
+
+#include "../../utils/dtor.h"
+#include "../../utils/gettext.h"
+#include "../../utils/strprintf.h"
+#include "../../utils/stringutils.h"
+
+ChannelTab::ChannelTab(Channel *channel) : ChatTab(channel->getName()),
+ mChannel(channel)
+{
+ channel->setTab(this);
+}
+
+ChannelTab::~ChannelTab()
+{
+}
+
+void ChannelTab::sendChat(std::string &msg) {
+#ifdef TMSERV_SUPPORT
+ Net::ChatServer::chat(getId(), msg);
+#endif
+}
diff --git a/src/gui/widgets/channeltab.h b/src/gui/widgets/channeltab.h
new file mode 100644
index 00000000..149eb5ec
--- /dev/null
+++ b/src/gui/widgets/channeltab.h
@@ -0,0 +1,54 @@
+/*
+ * The Mana World
+ * Copyright (C) 2009 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef CHANNELTAB_H
+#define CHANNELTAB_H
+
+#include "chattab.h"
+
+class Channel;
+
+/**
+ * A tab for a chat channel.
+ */
+class ChannelTab : public ChatTab
+{
+ public:
+ /**
+ * Constructor.
+ */
+ ChannelTab(Channel *channel);
+
+ /**
+ * Destructor.
+ */
+ ~ChannelTab();
+
+ Channel *getChannel() { return mChannel; }
+
+ protected:
+ void sendChat(std::string &msg);
+
+ private:
+ Channel *mChannel;
+};
+
+#endif // CHANNELTAB_H
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 746518ad..ff856361 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -211,6 +211,11 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord)
chatWindow->mRecorder->record(line.substr(3));
}
+void ChatTab::chatLog(std::string &nick, std::string &msg)
+{
+ chatLog(nick + ": " + msg, nick == player_node->getName() ? BY_PLAYER : BY_OTHER, false);
+}
+
void ChatTab::chatSend(std::string &msg)
{
trim(msg);
@@ -273,23 +278,7 @@ void ChatTab::chatSend(std::string &msg)
// Prepare ordinary message
if (msg[0] != '/')
{
-#ifdef TMWSERV_SUPPORT
- Net::GameServer::Player::say(msg);
- /*Channel *channel = channelManager->findByName(getFocused());
- if (channel)
- {
- Net::ChatServer::chat(channel->getId(), msg);
- }*/
-#else
- msg = player_node->getName() + " : " + msg;
-
- MessageOut outMsg(chatWindow->mNetwork);
- outMsg.writeInt16(CMSG_CHAT_MESSAGE);
- // Added + 1 in order to let eAthena parse admin commands correctly
- outMsg.writeInt16(msg.length() + 4 + 1);
- outMsg.writeString(msg, msg.length() + 1);
- return;
-#endif
+ sendChat(msg);
}
else
{
@@ -310,3 +299,18 @@ void ChatTab::clearText()
{
mTextOutput->clearRows();
}
+
+void ChatTab::sendChat(std::string &msg) {
+#ifdef TMWSERV_SUPPORT
+ Net::GameServer::Player::say(msg);
+#else
+ msg = player_node->getName() + " : " + msg;
+
+ MessageOut outMsg(chatWindow->mNetwork);
+ outMsg.writeInt16(CMSG_CHAT_MESSAGE);
+ // Added + 1 in order to let eAthena parse admin commands correctly
+ outMsg.writeInt16(msg.length() + 4 + 1);
+ outMsg.writeString(msg, msg.length() + 1);
+ return;
+#endif
+}
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index dd660884..d102d7a0 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -59,6 +59,14 @@ class ChatTab : public Tab
void chatLog(std::string line, int own, bool ignoreRecord);
/**
+ * Adds the text to the message list
+ *
+ * @param msg The message text which is to be sent.
+ *
+ */
+ void chatLog(std::string &nick, std::string &msg);
+
+ /**
* Determines whether the message is a command or message, then
* sends the given message to the game server to be said, or to the
* command handler
@@ -81,6 +89,9 @@ class ChatTab : public Tab
protected:
friend class ChatWindow;
+
+ void sendChat(std::string &msg);
+
ScrollArea *mScrollArea;
BrowserBox *mTextOutput;
//Recorder *mRecorder;
diff --git a/src/net/tmwserv/chathandler.cpp b/src/net/tmwserv/chathandler.cpp
index 2dfb4b5e..5a0730a6 100644
--- a/src/net/tmwserv/chathandler.cpp
+++ b/src/net/tmwserv/chathandler.cpp
@@ -21,7 +21,7 @@
#include "chathandler.h"
-#include <SDL_types.h>
+//#include <SDL_types.h>
#include <string>
#include <iostream>
@@ -34,6 +34,7 @@
#include "../../channel.h"
#include "../../channelmanager.h"
+#include "../../gui/widgets/channeltab.h"
#include "../../gui/chat.h"
#include "../../gui/guildwindow.h"
@@ -131,7 +132,7 @@ void ChatHandler::handleEnterChannelResponse(MessageIn &msg)
std::string announcement = msg.readString();
Channel *channel = new Channel(channelId, channelName, announcement);
channelManager->addChannel(channel);
- chatWindow->createNewChannelTab(channelName);
+ chatWindow->addTab(new ChannelTab(channel));
chatWindow->chatLog("Topic: " + announcement, BY_CHANNEL, channelName);
std::string user;
@@ -181,8 +182,8 @@ void ChatHandler::handlePrivateMessage(MessageIn &msg)
if (!chatWindow->tabExists(userNick))
{
- chatWindow->createNewChannelTab(userNick);
-
+ // TODO: proper whisper tabs
+ //chatWindow->createNewChannelTab(userNick);
}
chatWindow->chatLog(userNick + ": " + chatMsg, BY_OTHER, userNick);
}
@@ -199,7 +200,8 @@ void ChatHandler::handleChatMessage(MessageIn &msg)
std::string userNick = msg.readString();
std::string chatMsg = msg.readString();
- chatWindow->sendToChannel(channelId, userNick, chatMsg);
+ Channel *channel = channelManager->findById(channelId);
+ channel->getTab()->chatLog(userNick, chatMsg);
}
void ChatHandler::handleQuitChannelResponse(MessageIn &msg)
@@ -207,8 +209,9 @@ void ChatHandler::handleQuitChannelResponse(MessageIn &msg)
if(msg.readInt8() == ERRMSG_OK)
{
short channelId = msg.readInt16();
+ Channel *channel = channelManager->findById(channelId);
// remove the chat tab
- chatWindow->removeChannel(channelId);
+ chatWindow->removeTab(channel->getTab());
}
}
diff --git a/src/net/tmwserv/guildhandler.cpp b/src/net/tmwserv/guildhandler.cpp
index b3ddec6c..5927f175 100644
--- a/src/net/tmwserv/guildhandler.cpp
+++ b/src/net/tmwserv/guildhandler.cpp
@@ -28,8 +28,9 @@
#include "chatserver/chatserver.h"
#include "chatserver/guild.h"
-#include "../../gui/guildwindow.h"
+#include "../../gui/widgets/channeltab.h"
#include "../../gui/chat.h"
+#include "../../gui/guildwindow.h"
#include "../../guild.h"
#include "../../log.h"
#include "../../localplayer.h"
@@ -208,7 +209,8 @@ void GuildHandler::handleMessage(MessageIn &msg)
Guild *guild = player_node->getGuild(guildId);
if (guild)
{
- chatWindow->removeChannel(guild->getName());
+ Channel *channel = channelManager->findByName(guild->getName());
+ chatWindow->removeTab(channel->getTab());
guildWindow->removeTab(guildId);
player_node->removeGuild(guildId);
}
@@ -235,6 +237,6 @@ void GuildHandler::joinedGuild(MessageIn &msg)
// COMMENT: Should this go here??
Channel *channel = new Channel(channelId, guildName, announcement);
channelManager->addChannel(channel);
- chatWindow->createNewChannelTab(guildName);
+ chatWindow->addTab(new ChannelTab(channel));
chatWindow->chatLog("Topic: " + announcement, BY_CHANNEL, guildName);
}