refactoring chat-system

This commit is contained in:
doitux
2009-08-17 23:20:58 +00:00
parent 75007aa80e
commit 91c4304b78
17 changed files with 138 additions and 592 deletions
+14 -17
View File
@@ -2,12 +2,16 @@
isEmpty( PREFIX ):PREFIX = /usr
TEMPLATE = app
CODECFORSRC = UTF-8
CONFIG += qt thread embed_manifest_exe exceptions rtti stl warn_on
CONFIG += qt \
thread \
embed_manifest_exe \
exceptions \
rtti \
stl \
warn_on \
# ####Uncomment this for RELEASE on Linux/Unix/BSD (only for static Qt)
#QTPLUGIN += qjpeg qgif
# QTPLUGIN += qjpeg qgif
UI_DIR = uics
MOC_DIR = mocs
OBJECTS_DIR = obj
@@ -26,8 +30,8 @@ INCLUDEPATH += . \
src/engine/network_engine \
src/config \
src/third_party/tinyxml \
src/third_party/asn1 \
src/gui/qt \
src/third_party/asn1 \
src/gui/qt \
src/gui/qt/connecttoserverdialog \
src/core \
src/gui/qt/sound \
@@ -37,7 +41,6 @@ INCLUDEPATH += . \
src/gui/qt/gametable \
src/gui/qt/gametable/startsplash \
src/gui/qt/gametable/log \
src/gui/qt/gametable/chat \
src/gui/qt/aboutpokerth \
src/gui/qt/createnetworkgamedialog \
src/gui/qt/createinternetgamedialog \
@@ -54,7 +57,6 @@ INCLUDEPATH += . \
src/gui/qt/changecompleteblindsdialog \
src/gui/qt/mymessagedialog \
src/gui/qt/gamelobbydialog \
src/gui/qt/gamelobbydialog/lobbychat \
src/gui/qt/timeoutmsgbox
DEPENDPATH += . \
src \
@@ -74,7 +76,6 @@ DEPENDPATH += . \
src/gui/qt/gametable \
src/gui/qt/gametable/startsplash \
src/gui/qt/gametable/log \
src/gui/qt/gametable/chat \
src/gui/qt/aboutpokerth \
src/gui/qt/connecttoserverdialog \
src/gui/qt/createinternetgamedialog \
@@ -94,7 +95,6 @@ DEPENDPATH += . \
src/gui/qt/changecompleteblindsdialog \
src/gui/qt/mymessagedialog \
src/gui/qt/gamelobbydialog \
src/gui/qt/gamelobbydialog/lobbychat \
src/gui/qt/timeoutmsgbox
# Input
@@ -156,7 +156,6 @@ HEADERS += src/game.h \
src/gui/qt/gametable/mylefttabwidget.h \
src/gui/qt/gametable/startsplash/startsplash.h \
src/gui/qt/gametable/log/log.h \
src/gui/qt/gametable/chat/chat.h \
src/gui/qt/guiwrapper.h \
src/gui/qt/aboutpokerth/aboutpokerthimpl.h \
src/gui/qt/connecttoserverdialog/connecttoserverdialogimpl.h \
@@ -178,7 +177,6 @@ HEADERS += src/game.h \
src/gui/qt/changecompleteblindsdialog/changecompleteblindsdialogimpl.h \
src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h \
src/gui/qt/gamelobbydialog/mygamelisttreewidget.h \
src/gui/qt/gamelobbydialog/lobbychat/lobbychat.h \
src/gui/qt/timeoutmsgbox/timeoutmsgboximpl.h \
src/gui/qt/mymessagedialog/mymessagedialogimpl.h \
src/gui/qttoolsinterface.h \
@@ -225,7 +223,6 @@ SOURCES += src/pokerth.cpp \
src/gui/qt/gametable/mylefttabwidget.cpp \
src/gui/qt/gametable/startsplash/startsplash.cpp \
src/gui/qt/gametable/log/log.cpp \
src/gui/qt/gametable/chat/chat.cpp \
src/gui/qt/aboutpokerth/aboutpokerthimpl.cpp \
src/gui/qt/connecttoserverdialog/connecttoserverdialogimpl.cpp \
src/gui/qt/createnetworkgamedialog/createnetworkgamedialogimpl.cpp \
@@ -247,7 +244,6 @@ SOURCES += src/pokerth.cpp \
src/gui/qt/mymessagedialog/mymessagedialogimpl.cpp \
src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp \
src/gui/qt/gamelobbydialog/mygamelisttreewidget.cpp \
src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp \
src/gui/qt/timeoutmsgbox/timeoutmsgboximpl.cpp \
src/net/common/net_helper_client.cpp \
src/core/common/loghelper_client.cpp \
@@ -401,7 +397,7 @@ unix:!mac {
BSD = $$find(UNAME, "BSD")
kFreeBSD = $$find(UNAME, "kFreeBSD")
LIBS += -lpokerth_lib \
-lpokerth_protocol
-lpokerth_protocol
LIBS += $$BOOST_LIBS
LIBS += -lSDL_mixer \
-lcurl
@@ -409,7 +405,7 @@ unix:!mac {
else:LIBS += -lgnutls-openssl \
-lgcrypt
TARGETDEPS += ./lib/libpokerth_lib.a \
./lib/libpokerth_protocol.a
./lib/libpokerth_protocol.a
# #### My release static libs
# LIBS += -lgcrypt_static -lgpg-error_static -lgnutls-openssl_static -lgnutls_static -lSDL_mixer_static -lSDL -lmikmod -lcurl
@@ -437,7 +433,8 @@ mac {
# on Intel-Mac you have to comment this line out or build will fail.
# QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk/
LIBPATH += lib
LIBS += -lpokerth_lib -lpokerth_protocol
LIBS += -lpokerth_lib \
-lpokerth_protocol
# Qt static (path is standard for self-compiling qt)
# LIBS += /usr/local/Trolltech/Qt-4.2.3/lib/libQtCore.a
+1 -1
View File
@@ -3,7 +3,7 @@
TEMPLATE = lib
CODECFORSRC = UTF-8
CONFIG += staticlib thread exceptions rtti stl warn_on
CONFIG += staticlib thread exceptions rtti stl warn_on debug
UI_DIR = uics
TARGET = lib/pokerth_lib
+2 -1
View File
@@ -6,7 +6,8 @@ CONFIG += staticlib \
exceptions \
rtti \
stl \
warn_on
warn_on \
debug
UI_DIR = uics
TARGET = lib/pokerth_protocol
MOC_DIR = mocs
+1 -1
View File
@@ -7,7 +7,7 @@ isEmpty( PREFIX ){
TEMPLATE = app
CODECFORSRC = UTF-8
CONFIG += thread console embed_manifest_exe exceptions rtti stl warn_on
CONFIG += thread console embed_manifest_exe exceptions rtti stl warn_on debug
UI_DIR = uics
TARGET = bin/pokerth_server
+34 -35
View File
@@ -21,29 +21,34 @@
#include "session.h"
#include "configfile.h"
#include "gametablestylereader.h"
#include "gamelobbydialogimpl.h"
#include <iostream>
using namespace std;
ChatTools::ChatTools(QLineEdit* l, ConfigFile *c, int notifyMode, QTextBrowser *b, QTreeWidget *t) : nickAutoCompletitionCounter(0), myLineEdit(l), myNickTreeWidget(t), myNickStringList(NULL), myTextBrowser(b), myNotifyMode(notifyMode), myConfig(c), myNick("")
ChatTools::ChatTools(QLineEdit* l, ConfigFile *c, ChatType ct, QTextBrowser *b, QTreeWidget *t, gameLobbyDialogImpl *lo) : nickAutoCompletitionCounter(0), myLineEdit(l), myNickTreeWidget(t), myNickStringList(NULL), myTextBrowser(b), myChatType(ct), myConfig(c), myNick(""), myLobby(lo)
{
myNick = QString::fromUtf8(myConfig->readConfigString("MyName").c_str());
}
ChatTools::~ChatTools()
{
}
void ChatTools::sendMessage() {
fillChatLinesHistory(myLineEdit->text());
if(mySession) {
mySession->sendGameChatMessage(myLineEdit->text().toUtf8().constData());
if(myLineEdit->text().size() && mySession) {
fillChatLinesHistory(myLineEdit->text());
if(myChatType == INGAME_CHAT) {
mySession->sendGameChatMessage(myLineEdit->text().toUtf8().constData());
}
else {
mySession->sendLobbyChatMessage(myLineEdit->text().toUtf8().constData());
}
myLineEdit->setText("");
}
else { cout << "Session is not valid" << endl;}
}
void ChatTools::receiveMessage(QString playerName, QString message) {
@@ -53,37 +58,39 @@ void ChatTools::receiveMessage(QString playerName, QString message) {
message = message.replace("<","&lt;");
message = message.replace(">","&gt;");
//refresh myNick if it was changed during runtime
myNick = QString::fromUtf8(myConfig->readConfigString("MyName").c_str());
QString tempMsg;
QString nickString;
if(message.contains(myNick, Qt::CaseInsensitive)) {
if(myNick == "") { nickString = QString::fromUtf8(myConfig->readConfigString("MyName").c_str()); }
else { nickString = myNick; }
if(message.contains(nickString, Qt::CaseInsensitive)) {
switch (myNotifyMode) {
case 0: tempMsg = message;
switch (myChatType) {
case INET_LOBBY_CHAT: {
tempMsg = QString("<span style=\"font-weight:bold;\">"+message+"</span>");
//play beep sound only in INET-lobby-chat
// TODO dont play when message is from yourself
if(myLobby->isVisible() && myConfig->readConfigInt("PlayLobbyChatNotification")) {
myLobby->getMyW()->getMySDLPlayer()->playSound("lobbychatnotify",0);
}
}
break;
// lobby
case 1: tempMsg = QString("<span style=\"font-weight:bold;\">"+message+"</span>");
case LAN_LOBBY_CHAT: tempMsg = QString("<span style=\"font-weight:bold;\">"+message+"</span>");
break;
// ingame
case 2: tempMsg = QString("<span style=\"color:#"+myStyle->getChatTextNickNotifyColor()+";\">"+message+"</span>");
case INGAME_CHAT: tempMsg = QString("<span style=\"color:#"+myStyle->getChatTextNickNotifyColor()+";\">"+message+"</span>");
break;
default:;
default: tempMsg = message;
}
}
else {
switch (myNotifyMode) {
case 0: tempMsg = message;
switch (myChatType) {
case INET_LOBBY_CHAT: tempMsg = QString("<span style=\"font-weight:normal;\">"+message+"</span>");
break;
// lobby
case 1: tempMsg = QString("<span style=\"font-weight:normal;\">"+message+"</span>");
case LAN_LOBBY_CHAT: tempMsg = QString("<span style=\"font-weight:normal;\">"+message+"</span>");
break;
// ingame
case 2: tempMsg = QString("<span style=\"color:#"+myStyle->getChatLogTextColor()+";\">"+message+"</span>");
case INGAME_CHAT: tempMsg = QString("<span style=\"color:#"+myStyle->getChatLogTextColor()+";\">"+message+"</span>");
break;
default:;
default: tempMsg = message;
}
}
@@ -132,7 +139,6 @@ void ChatTools::nickAutoCompletition() {
if(nickAutoCompletitionCounter == 0) {
if(myNickTreeWidget) {
// cout << "use Treewidget niclist" << endl;
QTreeWidgetItemIterator it(myNickTreeWidget);
while (*it) {
if ((*it)->text(0).startsWith(myChatStringList.last(), Qt::CaseInsensitive) && myChatStringList.last() != "")
@@ -142,7 +148,6 @@ void ChatTools::nickAutoCompletition() {
}
if(!myNickStringList.isEmpty()) {
// cout << "use static nickList" << endl;
QStringListIterator it(myNickStringList);
while (it.hasNext()) {
@@ -150,15 +155,9 @@ void ChatTools::nickAutoCompletition() {
if (next.startsWith(myChatStringList.last(), Qt::CaseInsensitive) && myChatStringList.last() != "")
matchStringList << next;
}
//TODO code for static nickList
}
}
// QStringList::const_iterator constIterator;
// for (constIterator = matchStringList.constBegin(); constIterator != matchStringList.constEnd(); ++constIterator) {
// cout << (*constIterator).toLocal8Bit().constData() << endl;
// }
if(!matchStringList.isEmpty() || nickAutoCompletitionCounter > 0) {
myChatStringList.removeLast();
+8 -3
View File
@@ -25,20 +25,23 @@
#include <QtGui>
#include <boost/shared_ptr.hpp>
enum ChatType { INET_LOBBY_CHAT, LAN_LOBBY_CHAT, INGAME_CHAT };
class Session;
class ConfigFile;
class GameTableStyleReader;
class gameLobbyDialogImpl;
class ChatTools : public QObject
{
Q_OBJECT
public:
ChatTools(QLineEdit* l, ConfigFile *c, int notifyMode = 0, QTextBrowser *b = NULL, QTreeWidget *t = NULL);
ChatTools(QLineEdit*, ConfigFile*, ChatType, QTextBrowser *b = NULL, QTreeWidget *t = NULL, gameLobbyDialogImpl *lo = NULL);
~ChatTools();
void setSession(boost::shared_ptr<Session> session) { mySession = session; }
void setSession(boost::shared_ptr<Session> session) { mySession = session; }
public slots:
@@ -56,6 +59,7 @@ public slots:
void setPlayerNicksList(QStringList value) { myNickStringList = value; }
void setMyNick ( const QString& theValue ) { myNick = theValue; }
QString getMyNick () { return myNick; }
void setMyStyle ( GameTableStyleReader* theValue ) { myStyle = theValue; }
@@ -72,12 +76,13 @@ private:
QStringList myNickStringList;
QTextBrowser *myTextBrowser;
boost::shared_ptr<Session> mySession;
int myNotifyMode; // 0 == no notification, 1 == bold notification, 2 == yellow notification
ChatType myChatType;
ConfigFile *myConfig;
QString myNick;
GameTableStyleReader *myStyle;
gameLobbyDialogImpl *myLobby;
};
#endif
@@ -12,7 +12,7 @@
#include "gamelobbydialogimpl.h"
#include "mygamelistsortfilterproxymodel.h"
#include "startwindowimpl.h"
#include "lobbychat.h"
#include "chattools.h"
#include "changecompleteblindsdialogimpl.h"
#include "session.h"
#include "configfile.h"
@@ -29,7 +29,7 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
#endif
setupUi(this);
myChat = new LobbyChat(this, myConfig);
myChat = new ChatTools(lineEdit_ChatInput, myConfig, INET_LOBBY_CHAT, textBrowser_ChatDisplay, treeWidget_NickList, this);
myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str());
@@ -560,6 +560,7 @@ void gameLobbyDialogImpl::clearDialog()
pushButton_CreateGame->clearFocus();
lineEdit_ChatInput->setFocus();
myChat->clearChat();
treeWidget_NickList->clear();
inGame = false;
isAdmin = false;
myPlayerId = 0;
@@ -681,7 +682,21 @@ void gameLobbyDialogImpl::updatePlayer(unsigned playerId, QString newPlayerName)
refreshConnectedPlayerAvatars();
//also rename player in nick-list
myChat->playerChanged(playerId, newPlayerName);
QString oldNick;
QTreeWidgetItemIterator it1(treeWidget_NickList);
while (*it1) {
if ((*it1)->data(0, Qt::UserRole) == playerId)
{
oldNick = (*it1)->data(0, Qt::DisplayRole).toString();
(*it1)->setData(0, Qt::DisplayRole, newPlayerName);
break;
}
++it1;
}
if (myChat->getMyNick() == oldNick) {
myChat->setMyNick(newPlayerName);
}
}
void gameLobbyDialogImpl::removePlayer(unsigned playerId, QString) {
@@ -699,6 +714,32 @@ void gameLobbyDialogImpl::removePlayer(unsigned playerId, QString) {
checkPlayerQuantity();
}
void gameLobbyDialogImpl::playerLeftLobby(unsigned playerId)
{
QTreeWidgetItemIterator it(treeWidget_NickList);
while (*it) {
if ((*it)->data(0, Qt::UserRole) == playerId)
{
treeWidget_NickList->takeTopLevelItem(treeWidget_NickList->indexOfTopLevelItem(*it));
break;
}
++it;
}
treeWidget_NickList->sortItems(0, Qt::AscendingOrder);
refreshPlayerStats();
}
void gameLobbyDialogImpl::playerJoinedLobby(unsigned playerId, QString playerName)
{
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_NickList, 0);
item->setData(0, Qt::DisplayRole, playerName);
item->setData(0, Qt::UserRole, playerId);
treeWidget_NickList->sortItems(0, Qt::AscendingOrder);
refreshPlayerStats();
}
void gameLobbyDialogImpl::newGameAdmin(unsigned playerId, QString)
{
QTreeWidgetItemIterator it(treeWidget_connectedPlayers);
@@ -26,7 +26,7 @@
class Session;
class ConfigFile;
class LobbyChat;
class ChatTools;
class startWindowImpl;
class MyGameListSortFilterProxyModel;
@@ -43,7 +43,7 @@ public:
void exec();
LobbyChat *getLobbyChat() { return myChat; }
ChatTools *getMyChat() { return myChat; }
void setSession(boost::shared_ptr<Session> session) { mySession = session; }
boost::shared_ptr<Session> getSession() { assert(mySession.get()); return mySession; }
@@ -65,6 +65,9 @@ public slots:
void removeGame(unsigned gameId);
void gameAddPlayer(unsigned gameId, unsigned playerId);
void gameRemovePlayer(unsigned gameId, unsigned playerId);
void playerJoinedLobby(unsigned playerId, QString playerName);
void playerLeftLobby(unsigned playerId);
void updateStats(ServerStats stats);
@@ -134,7 +137,7 @@ private:
QColor defaultStartButtonTextColor;
QColor disabledStartButtonColor;
QColor disabledStartButtonTextColor;
LobbyChat *myChat;
ChatTools *myChat;
int keyUpCounter;
QStandardItemModel *myGameListModel;
QItemSelectionModel *myGameListSelectionModel;
@@ -1,229 +0,0 @@
/***************************************************************************
* Copyright (C) 2006 by FThauer FHammer *
* f.thauer@web.de *
* *
* 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 *
* (at your option) 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 "lobbychat.h"
#define IN_INCLUDE_LIBIRC_H
#include <third_party/libircclient/include/libirc_rfcnumeric.h>
#include <net/socket_msg.h>
#include "gamelobbydialogimpl.h"
#include "session.h"
#include "configfile.h"
#include "chattools.h"
using namespace std;
LobbyChat::LobbyChat(gameLobbyDialogImpl* l, ConfigFile *c) : myLobby(l), myConfig(c)
{
myChatTools = new ChatTools(myLobby->lineEdit_ChatInput, myConfig, 1, myLobby->textBrowser_ChatDisplay, myLobby->treeWidget_NickList);
myNick = QString::fromUtf8(myConfig->readConfigString("MyName").c_str());
}
LobbyChat::~LobbyChat()
{
}
void LobbyChat::sendMessage() {
fillChatLinesHistory(myLobby->lineEdit_ChatInput->text());
QString tmpMsg(myLobby->lineEdit_ChatInput->text());
if (tmpMsg.size())
{
myLobby->getSession()->sendLobbyChatMessage(tmpMsg.toUtf8().constData());
myLobby->lineEdit_ChatInput->setText("");
}
}
void LobbyChat::playerJoined(unsigned playerId, QString playerName)
{
QTreeWidgetItem *item = new QTreeWidgetItem(myLobby->treeWidget_NickList, 0);
item->setData(0, Qt::DisplayRole, playerName);
item->setData(0, Qt::UserRole, playerId);
myLobby->treeWidget_NickList->sortItems(0, Qt::AscendingOrder);
myLobby->refreshPlayerStats();
}
void LobbyChat::playerChanged(unsigned playerId, QString newNick)
{
QString oldNick;
QTreeWidgetItemIterator it(myLobby->treeWidget_NickList);
while (*it) {
if ((*it)->data(0, Qt::UserRole) == playerId)
{
oldNick = (*it)->data(0, Qt::DisplayRole).toString();
(*it)->setData(0, Qt::DisplayRole, newNick);
break;
}
++it;
}
if (myNick == oldNick) {
myNick = newNick;
myChatTools->setMyNick(myNick);
}
}
void LobbyChat::playerKicked(QString nickName, QString byWhom, QString reason)
{
if (myNick == nickName)
{
myLobby->treeWidget_NickList->clear();
myLobby->lineEdit_ChatInput->setEnabled(false);
}
myLobby->textBrowser_ChatDisplay->append(nickName + " " + tr("was kicked from the server by") + " " + byWhom + " (" + reason + ")");
}
void LobbyChat::playerLeft(unsigned playerId)
{
QTreeWidgetItemIterator it(myLobby->treeWidget_NickList);
while (*it) {
if ((*it)->data(0, Qt::UserRole) == playerId)
{
myLobby->treeWidget_NickList->takeTopLevelItem(myLobby->treeWidget_NickList->indexOfTopLevelItem(*it));
break;
}
++it;
}
myLobby->treeWidget_NickList->sortItems(0, Qt::AscendingOrder);
myLobby->refreshPlayerStats();
}
void LobbyChat::displayMessage(QString playerName, QString message) {
myChatTools->receiveMessage(playerName, message);
if(message.contains(myNick, Qt::CaseInsensitive) && myLobby->isVisible() && myConfig->readConfigInt("PlayLobbyChatNotification")) {
myLobby->getMyW()->getMySDLPlayer()->playSound("lobbychatnotify",0);
}
}
void LobbyChat::checkInputLength(QString string) {
if(string.toUtf8().length() > 120) myLobby->lineEdit_ChatInput->setMaxLength(string.length());
}
void LobbyChat::clearChat() {
myNick = "";
myLobby->treeWidget_NickList->clear();
myLobby->textBrowser_ChatDisplay->clear();
}
void LobbyChat::chatError(int errorCode)
{
QString errorMsg;
switch (errorCode)
{
case ERR_IRC_INTERNAL :
case ERR_IRC_SELECT_FAILED :
case ERR_IRC_RECV_FAILED :
case ERR_IRC_SEND_FAILED :
case ERR_IRC_INVALID_PARAM :
errorMsg = tr("An internal IRC error has occured:") + " " + QString::number(errorCode);
break;
case ERR_IRC_CONNECT_FAILED :
errorMsg = tr("Could not connect to the IRC server. Chat will be unavailable.");
break;
case ERR_IRC_TERMINATED :
errorMsg = tr("The IRC server terminated the connection. Chat will be unavailable.");
break;
case ERR_IRC_TIMEOUT :
errorMsg = tr("An IRC action timed out.");
break;
}
if (errorMsg.size())
myLobby->textBrowser_ChatDisplay->append(errorMsg);
}
void LobbyChat::chatServerError(int errorCode)
{
QString errorMsg;
switch (errorCode)
{
case LIBIRC_RFC_ERR_NOSUCHNICK :
case LIBIRC_RFC_ERR_NOSUCHCHANNEL :
case LIBIRC_RFC_ERR_CANNOTSENDTOCHAN :
case LIBIRC_RFC_ERR_TOOMANYCHANNELS :
case LIBIRC_RFC_ERR_WASNOSUCHNICK :
case LIBIRC_RFC_ERR_TOOMANYTARGETS :
case LIBIRC_RFC_ERR_NOSUCHSERVICE :
case LIBIRC_RFC_ERR_NOORIGIN :
case LIBIRC_RFC_ERR_NORECIPIENT :
case LIBIRC_RFC_ERR_NOTEXTTOSEND :
case LIBIRC_RFC_ERR_NOTOPLEVEL :
case LIBIRC_RFC_ERR_WILDTOPLEVEL :
case LIBIRC_RFC_ERR_BADMASK :
case LIBIRC_RFC_ERR_UNKNOWNCOMMAND :
case LIBIRC_RFC_ERR_NOMOTD :
case LIBIRC_RFC_ERR_NOADMININFO :
case LIBIRC_RFC_ERR_FILEERROR :
case LIBIRC_RFC_ERR_NONICKNAMEGIVEN :
case LIBIRC_RFC_ERR_ERRONEUSNICKNAME :
case LIBIRC_RFC_ERR_UNAVAILRESOURCE :
case LIBIRC_RFC_ERR_USERNOTINCHANNEL :
case LIBIRC_RFC_ERR_NOTONCHANNEL :
case LIBIRC_RFC_ERR_USERONCHANNEL :
case LIBIRC_RFC_ERR_NOLOGIN :
case LIBIRC_RFC_ERR_SUMMONDISABLED :
case LIBIRC_RFC_ERR_USERSDISABLED :
case LIBIRC_RFC_ERR_NOTREGISTERED :
case LIBIRC_RFC_ERR_NEEDMOREPARAMS :
case LIBIRC_RFC_ERR_ALREADYREGISTRED :
case LIBIRC_RFC_ERR_NOPERMFORHOST :
case LIBIRC_RFC_ERR_PASSWDMISMATCH :
case LIBIRC_RFC_ERR_YOUREBANNEDCREEP :
case LIBIRC_RFC_ERR_YOUWILLBEBANNED :
case LIBIRC_RFC_ERR_KEYSET :
case LIBIRC_RFC_ERR_CHANNELISFULL :
case LIBIRC_RFC_ERR_UNKNOWNMODE :
case LIBIRC_RFC_ERR_INVITEONLYCHAN :
case LIBIRC_RFC_ERR_BANNEDFROMCHAN :
case LIBIRC_RFC_ERR_BADCHANNELKEY :
case LIBIRC_RFC_ERR_BADCHANMASK :
case LIBIRC_RFC_ERR_NOCHANMODES :
case LIBIRC_RFC_ERR_BANLISTFULL :
case LIBIRC_RFC_ERR_NOPRIVILEGES :
case LIBIRC_RFC_ERR_CHANOPRIVSNEEDED :
case LIBIRC_RFC_ERR_CANTKILLSERVER :
case LIBIRC_RFC_ERR_RESTRICTED :
case LIBIRC_RFC_ERR_UNIQOPPRIVSNEEDED :
case LIBIRC_RFC_ERR_NOOPERHOST :
case LIBIRC_RFC_ERR_UMODEUNKNOWNFLAG :
case LIBIRC_RFC_ERR_USERSDONTMATCH :
errorMsg = tr("The IRC server reported an error:") + " " + QString::number(errorCode);
break;
}
// if (errorMsg.size())
// myLobby->textBrowser_ChatDisplay->append(errorMsg);
}
void LobbyChat::fillChatLinesHistory(QString fillString) { myChatTools->fillChatLinesHistory(fillString); }
int LobbyChat::getChatLinesHistorySize() { return myChatTools->getChatLinesHistorySize(); }
void LobbyChat::showChatHistoryIndex(int index) { myChatTools->showChatHistoryIndex(index); }
void LobbyChat::nickAutoCompletition() { myChatTools->nickAutoCompletition(); }
void LobbyChat::setChatTextEdited() { myChatTools->setChatTextEdited(); }
@@ -1,73 +0,0 @@
/***************************************************************************
* Copyright (C) 2006 by FThauer FHammer *
* f.thauer@web.de *
* *
* 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 *
* (at your option) 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 LOBBYCHAT_H
#define LOBBYCHAT_H
#include <string>
#include <QtCore>
#include <QtGui>
class gameLobbyDialogImpl;
class Session;
class ConfigFile;
class ChatTools;
class LobbyChat : public QObject
{
Q_OBJECT
public:
LobbyChat(gameLobbyDialogImpl*, ConfigFile*);
~LobbyChat();
public slots:
void sendMessage();
void playerJoined(unsigned playerId, QString playerName);
void playerChanged(unsigned playerId, QString newNick);
void playerKicked(QString nickName, QString byWhom, QString reason);
void playerLeft(unsigned playerId);
void displayMessage(QString playerName, QString msg);
void checkInputLength(QString);
void clearChat();
void chatError(int errorCode);
void chatServerError(int errorCode);
ChatTools* getMyChatTools() const { return myChatTools; }
void fillChatLinesHistory(QString fillString);
void showChatHistoryIndex(int index);
int getChatLinesHistorySize();
void nickAutoCompletition();
void setChatTextEdited();
private:
gameLobbyDialogImpl *myLobby;
ConfigFile *myConfig;
QString myNick;
unsigned myLobbyPlayerId;
ChatTools *myChatTools;
// friend class GuiWrapper;
};
#endif
-116
View File
@@ -1,116 +0,0 @@
/***************************************************************************
* Copyright (C) 2006 by FThauer FHammer *
* f.thauer@web.de *
* *
* 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 *
* (at your option) 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 "chat.h"
#include "gametableimpl.h"
#include "session.h"
#include "game.h"
#include "playerinterface.h"
#include "chattools.h"
#include "configfile.h"
#include "gametablestylereader.h"
using namespace std;
#define COMMAND_KICK_STR "/kick "
Chat::Chat(gameTableImpl* w, ConfigFile *c) : myW(w), myConfig(c)
{
myChatTools = new ChatTools(myW->lineEdit_ChatInput, myConfig, 2, myW->textBrowser_Chat);
}
Chat::~Chat()
{
delete myConfig;
myConfig = 0;
}
void Chat::sendMessage() {
//filter /kick command
if(myW->lineEdit_ChatInput->text().startsWith(COMMAND_KICK_STR)) {
QString playerToKick = myW->lineEdit_ChatInput->text();
playerToKick.remove(0, sizeof(COMMAND_KICK_STR) - 1);
myW->lineEdit_ChatInput->setText("");
if(myW->getSession()->getClientGameInfo(myW->getSession()->getClientCurrentGameId()).adminPlayerId == myW->getSession()->getCurrentGame()->getSeatsList()->front()->getMyUniqueID()) {
if(playerToKick.toUtf8().constData() == myW->getSession()->getCurrentGame()->getSeatsList()->front()->getMyName()) {
myW->textBrowser_Chat->append("<span style=\"color:#ff0000;\">"+tr("You cannot kick yourself!")+"</span>");
}
else {
myW->getSession()->kickPlayer(playerToKick.toUtf8().constData());
}
}
else {
myW->textBrowser_Chat->append("<span style=\"color:#ff0000;\">"+tr("You cannot kick any player - You are not game admin!")+"</span>");
}
return;
}
fillChatLinesHistory(myW->lineEdit_ChatInput->text());
myW->getSession()->sendGameChatMessage(myW->lineEdit_ChatInput->text().toUtf8().constData());
myW->lineEdit_ChatInput->setText("");
}
void Chat::receiveMessage(QString playerName, QString message) {
myChatTools->receiveMessage(playerName, message);
checkInvisible();
}
void Chat::checkInvisible() {
switch (myW->tabWidget_Left->currentIndex()) {
case 1: { myW->tabWidget_Left->stopBlinkChatTab();
myW->tabWidget_Left->showDefaultChatTab();
}
break;
default: { myW->tabWidget_Left->startBlinkChatTab(); }
}
}
void Chat::checkInputLength(QString string) {
if(string.toUtf8().length() > 120) myW->lineEdit_ChatInput->setMaxLength(string.length());
}
void Chat::clearNewGame() {
myW->textBrowser_Chat->clear();
}
void Chat::setPlayerNicksList(QStringList nickList) {
//fill playerNicksList for nick-autocompletition
myChatTools->setPlayerNicksList(nickList);
}
void Chat::fillChatLinesHistory(QString fillString) { myChatTools->fillChatLinesHistory(fillString); }
int Chat::getChatLinesHistorySize() { return myChatTools->getChatLinesHistorySize(); }
void Chat::showChatHistoryIndex(int index) { myChatTools->showChatHistoryIndex(index); }
void Chat::nickAutoCompletition() { myChatTools->nickAutoCompletition(); }
void Chat::setChatTextEdited() { myChatTools->setChatTextEdited(); }
void Chat::transportMyStyle(GameTableStyleReader *s)
{
myChatTools->setMyStyle(s);
}
-69
View File
@@ -1,69 +0,0 @@
/***************************************************************************
* Copyright (C) 2006 by FThauer FHammer *
* f.thauer@web.de *
* *
* 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 *
* (at your option) 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 CHAT_H
#define CHAT_H
#include <string>
#include <QtCore>
class gameTableImpl;
class ChatTools;
class ConfigFile;
class GameTableStyleReader;
class Chat : public QObject
{
Q_OBJECT
public:
Chat(gameTableImpl*, ConfigFile *c);
~Chat();
public slots:
void sendMessage();
void receiveMessage(QString playerName, QString msg);
void checkInvisible();
void checkInputLength(QString);
void clearNewGame();
void transportMyStyle(GameTableStyleReader*);
ChatTools* getMyChatTools() const { return myChatTools; }
void fillChatLinesHistory(QString fillString);
void showChatHistoryIndex(int index);
int getChatLinesHistorySize();
void nickAutoCompletition();
void setChatTextEdited();
void setPlayerNicksList(QStringList);
private:
gameTableImpl *myW;
ConfigFile *myConfig;
ChatTools *myChatTools;
friend class GuiWrapper;
};
#endif
+6 -8
View File
@@ -32,7 +32,7 @@
#include "mytimeoutlabel.h"
#include "mymenubar.h"
#include "log.h"
#include "chat.h"
#include "chattools.h"
#include "playerinterface.h"
#include "boardinterface.h"
@@ -388,9 +388,9 @@ gameTableImpl::gameTableImpl(ConfigFile *c, QMainWindow *parent)
}
// Dialogs
myChat = new Chat(this, myConfig);
myChat->transportMyStyle(myGameTableStyle);
myChat = new ChatTools(lineEdit_ChatInput, myConfig, INGAME_CHAT, textBrowser_Chat);
myChat->setMyStyle(myGameTableStyle);
lineEdit_ChatInput->installEventFilter(this);
this->installEventFilter(this);
@@ -2775,9 +2775,7 @@ void gameTableImpl::tabSwitchAction() {
switch(tabWidget_Left->currentIndex()) {
case 1: { lineEdit_ChatInput->setFocus();
myChat->checkInvisible();
}
case 1: { lineEdit_ChatInput->setFocus(); }
break;
default: { lineEdit_ChatInput->clearFocus(); }
@@ -2821,7 +2819,7 @@ void gameTableImpl::networkGameModification() {
tabWidget_Left->removeTab(2);
tabWidget_Left->setCurrentIndex(1);
myChat->clearNewGame();
myChat->clearChat();
int i;
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++ ) {
+12 -12
View File
@@ -30,7 +30,7 @@
#include <QtCore>
class Log;
class Chat;
class ChatTools;
class ConfigFile;
class Session;
class Game;
@@ -64,7 +64,7 @@ public:
void setLog(Log* l) { myLog = l; }
SDLPlayer* getMySDLPlayer() const { return mySDLPlayer; }
Chat* getMyChat() const { return myChat; }
ChatTools* getMyChat() const { return myChat; }
GameTableStyleReader* getMyGameTableStyle() const { return myGameTableStyle; }
@@ -125,7 +125,7 @@ signals:
void signalChangeVoteOnKickButtonsState(bool showHide);
void signalEndVoteOnKick();
void signalNetClientPlayerLeft(unsigned playerId);
void signalNetClientPlayerLeft(unsigned playerId);
public slots:
@@ -302,12 +302,12 @@ public slots:
void saveGameTableGeometry();
void restoreGameTableGeometry();
void netClientPlayerLeft(unsigned playerId);
void netClientPlayerLeft(unsigned playerId);
private:
boost::shared_ptr<GuiInterface> myServerGuiInterface;
Log *myLog;
Chat *myChat;
ChatTools *myChat;
ConfigFile *myConfig;
//Timer
@@ -356,9 +356,9 @@ private:
QLabel *cashTopLabelArray[MAX_NUMBER_OF_PLAYERS];
MySetLabel *setLabelArray[MAX_NUMBER_OF_PLAYERS];
QLabel *actionLabelArray[MAX_NUMBER_OF_PLAYERS];
MyNameLabel *playerNameLabelArray[MAX_NUMBER_OF_PLAYERS];
MyNameLabel *playerNameLabelArray[MAX_NUMBER_OF_PLAYERS];
MyAvatarLabel *playerAvatarLabelArray[MAX_NUMBER_OF_PLAYERS];
MyTimeoutLabel *timeoutLabelArray[MAX_NUMBER_OF_PLAYERS];
MyTimeoutLabel *timeoutLabelArray[MAX_NUMBER_OF_PLAYERS];
QGroupBox *groupBoxArray[MAX_NUMBER_OF_PLAYERS];
MyCardsPixmapLabel *boardCardsArray[5];
@@ -422,11 +422,11 @@ private:
CardDeckStyleReader *myCardDeckStyle;
QString AllInString;
QString RaiseString;
QString BetString;
QString CallString;
QString CheckString;
QString FoldString;
QString RaiseString;
QString BetString;
QString CallString;
QString CheckString;
QString FoldString;
QString PotString;
QString TotalString;
QString BetsString;
@@ -33,7 +33,7 @@ startNetworkGameDialogImpl::startNetworkGameDialogImpl(startWindowImpl *parent,
#endif
setupUi(this);
myChat = new ChatTools(lineEdit_ChatInput, myConfig, 1, textBrowser_ChatDisplay, treeWidget );
myChat = new ChatTools(lineEdit_ChatInput, myConfig, LAN_LOBBY_CHAT, textBrowser_ChatDisplay);
lineEdit_ChatInput->installEventFilter(this);
@@ -42,7 +42,7 @@ public:
public slots:
void setMyW ( gameTableImpl* theValue ) { myW = theValue; }
ChatTools *getMyChat() { return myChat; }
void startGame();
void cancel();
+8 -19
View File
@@ -45,8 +45,7 @@
#include "changecompleteblindsdialogimpl.h"
#include "gamelobbydialogimpl.h"
#include "timeoutmsgboximpl.h"
#include "lobbychat.h"
#include "chat.h"
#include "chattools.h"
#include "serverlistdialogimpl.h"
using namespace std;
@@ -141,12 +140,16 @@ startWindowImpl::startWindowImpl(ConfigFile *c)
connect(this, SIGNAL(signalNetClientRemovedFromGame(int)), myGameLobbyDialog, SLOT(removedFromGame(int)));
connect(this, SIGNAL(signalNetClientStatsUpdate(ServerStats)), myGameLobbyDialog, SLOT(updateStats(ServerStats)));
connect(this, SIGNAL(signalNetClientGameChatMsg(QString, QString)), myStartNetworkGameDialog, SLOT(receiveChatMsg(QString, QString)));
connect(this, SIGNAL(signalNetClientGameChatMsg(QString, QString)), myStartNetworkGameDialog->getMyChat(), SLOT(receiveMessage(QString, QString)));
connect(this, SIGNAL(signalNetClientGameChatMsg(QString, QString)), myGuiInterface->getMyW()->getMyChat(), SLOT(receiveMessage(QString, QString)));
connect(this, SIGNAL(signalNetClientLobbyChatMsg(QString, QString)), myGameLobbyDialog->getLobbyChat(), SLOT(displayMessage(QString, QString)));
connect(this, SIGNAL(signalNetClientLobbyChatMsg(QString, QString)), myGameLobbyDialog->getMyChat(), SLOT(receiveMessage(QString, QString)));
connect(this, SIGNAL(signalNetClientMsgBox(QString)), this, SLOT(networkMessage(QString)));
connect(this, SIGNAL(signalNetClientShowTimeoutDialog(int, unsigned)), this, SLOT(showTimeoutDialog(int, unsigned)));
connect(this, SIGNAL(signalLobbyPlayerJoined(unsigned, QString)), myGameLobbyDialog, SLOT(playerJoinedLobby(unsigned, QString)));
// connect(this, SIGNAL(signalLobbyPlayerKicked(QString, QString, QString)), myGameLobbyDialog, SLOT(playerKicked(QString, QString, QString)));
connect(this, SIGNAL(signalLobbyPlayerLeft(unsigned)), myGameLobbyDialog, SLOT(playerLeftLobby(unsigned)));
// Errors are handled globally, not within one dialog.
connect(this, SIGNAL(signalNetClientError(int, int)), this, SLOT(networkError(int, int)));
@@ -154,20 +157,6 @@ startWindowImpl::startWindowImpl(ConfigFile *c)
connect(this, SIGNAL(signalNetServerError(int, int)), this, SLOT(networkError(int, int)));
connect(this, SIGNAL(signalNetClientRemovedFromGame(int)), this, SLOT(networkNotification(int)));
connect(this, SIGNAL(signalNetClientGameStart(boost::shared_ptr<Game>)), this, SLOT(networkStart(boost::shared_ptr<Game>)));
// connect(this, SIGNAL(signalIrcConnect(QString)), myGameLobbyDialog->getLobbyChat(), SLOT(connected(QString)));
// connect(this, SIGNAL(signalIrcSelfJoined(QString, QString)), myGameLobbyDialog->getLobbyChat(), SLOT(selfJoined(QString, QString)));
// connect(this, SIGNAL(signalIrcPlayerJoined(QString)), myGameLobbyDialog->getLobbyChat(), SLOT(playerJoined(QString)));
// connect(this, SIGNAL(signalIrcPlayerChanged(QString, QString)), myGameLobbyDialog->getLobbyChat(), SLOT(playerChanged(QString, QString)));
// connect(this, SIGNAL(signalIrcPlayerKicked(QString, QString, QString)), myGameLobbyDialog->getLobbyChat(), SLOT(playerKicked(QString, QString, QString)));
// connect(this, SIGNAL(signalIrcPlayerLeft(QString)), myGameLobbyDialog->getLobbyChat(), SLOT(playerLeft(QString)));
// connect(this, SIGNAL(signalIrcChatMessage(QString, QString)), myGameLobbyDialog->getLobbyChat(), SLOT(displayMessage(QString, QString)));
// connect(this, SIGNAL(signalIrcError(int)), myGameLobbyDialog->getLobbyChat(), SLOT(chatError(int)));
// connect(this, SIGNAL(signalIrcServerError(int)), myGameLobbyDialog->getLobbyChat(), SLOT(chatServerError(int)));
connect(this, SIGNAL(signalLobbyPlayerJoined(unsigned, QString)), myGameLobbyDialog->getLobbyChat(), SLOT(playerJoined(unsigned, QString)));
connect(this, SIGNAL(signalLobbyPlayerKicked(QString, QString, QString)), myGameLobbyDialog->getLobbyChat(), SLOT(playerKicked(QString, QString, QString)));
connect(this, SIGNAL(signalLobbyPlayerLeft(unsigned)), myGameLobbyDialog->getLobbyChat(), SLOT(playerLeft(unsigned)));
this->show();