Use own lobby chat instead of IRC. First steps, still incomplete.

This commit is contained in:
lotodore
2009-08-15 10:25:13 +00:00
parent 94db67bbd5
commit 4c340d5bdc
18 changed files with 104 additions and 93 deletions
+2 -1
View File
@@ -141,7 +141,8 @@ void ServerGuiWrapper::SignalNetClientGameListUpdateAdmin(unsigned gameId, unsig
void ServerGuiWrapper::SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId) { if (myClientcb) myClientcb->SignalNetClientGameListPlayerJoined(gameId, playerId); }
void ServerGuiWrapper::SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId) { if (myClientcb) myClientcb->SignalNetClientGameListPlayerLeft(gameId, playerId); }
void ServerGuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { if (myClientcb) myClientcb->SignalNetClientGameStart(game); }
void ServerGuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { if (myClientcb) myClientcb->SignalNetClientChatMsg(playerName, msg); }
void ServerGuiWrapper::SignalNetClientGameChatMsg(const string &playerName, const string &msg) { if (myClientcb) myClientcb->SignalNetClientGameChatMsg(playerName, msg); }
void ServerGuiWrapper::SignalNetClientLobbyChatMsg(const string &playerName, const string &msg) { if (myClientcb) myClientcb->SignalNetClientLobbyChatMsg(playerName, msg); }
void ServerGuiWrapper::SignalNetClientMsgBox(const string &msg) { if (myClientcb) myClientcb->SignalNetClientMsgBox(msg); }
void ServerGuiWrapper::SignalNetClientWaitDialog() { if (myClientcb) myClientcb->SignalNetClientWaitDialog(); }
+2 -1
View File
@@ -116,7 +116,8 @@ public:
void SignalNetClientPlayerChanged(unsigned playerId, const std::string &newPlayerName);
void SignalNetClientPlayerLeft(unsigned playerId, const std::string &playerName, int removeReason);
void SignalNetClientNewGameAdmin(unsigned playerId, const std::string &playerName);
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientGameChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientLobbyChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientWaitDialog();
void SignalNetClientGameListNew(unsigned gameId);
+1 -1
View File
@@ -40,7 +40,7 @@ void ChatTools::sendMessage() {
fillChatLinesHistory(myLineEdit->text());
if(mySession) {
mySession->sendChatMessage(myLineEdit->text().toUtf8().constData());
mySession->sendGameChatMessage(myLineEdit->text().toUtf8().constData());
myLineEdit->setText("");
}
else { cout << "Session is not valid" << endl;}
@@ -42,13 +42,16 @@ LobbyChat::~LobbyChat()
void LobbyChat::sendMessage() {
if (myNick.size())
if (myNick.isEmpty())
myNick = QString::fromUtf8(myConfig->readConfigString("MyName").c_str());
if (!myNick.isEmpty())
{
fillChatLinesHistory(myLobby->lineEdit_ChatInput->text());
QString tmpMsg(myLobby->lineEdit_ChatInput->text());
if (tmpMsg.size())
{
myLobby->getSession()->sendIrcChatMessage(tmpMsg.toUtf8().constData());
myLobby->getSession()->sendLobbyChatMessage(tmpMsg.toUtf8().constData());
myLobby->lineEdit_ChatInput->setText("");
displayMessage(myNick, tmpMsg);
@@ -145,8 +148,6 @@ void LobbyChat::clearChat() {
myNick = "";
myLobby->treeWidget_NickList->clear();
myLobby->textBrowser_ChatDisplay->clear();
myLobby->textBrowser_ChatDisplay->append(tr("Connecting to Chat server..."));
myLobby->lineEdit_ChatInput->setEnabled(false);
}
void LobbyChat::chatError(int errorCode)
+1 -1
View File
@@ -67,7 +67,7 @@ void Chat::sendMessage() {
}
fillChatLinesHistory(myW->lineEdit_ChatInput->text());
myW->getSession()->sendChatMessage(myW->lineEdit_ChatInput->text().toUtf8().constData());
myW->getSession()->sendGameChatMessage(myW->lineEdit_ChatInput->text().toUtf8().constData());
myW->lineEdit_ChatInput->setText("");
}
+2 -1
View File
@@ -165,7 +165,8 @@ void GuiWrapper::SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned pla
void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr<Game> game) { myStartWindow->signalNetClientGameStart(game); }
void GuiWrapper::SignalNetClientWaitDialog() { myStartWindow->signalShowClientDialog(); }
void GuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { myStartWindow->signalNetClientChatMsg(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); }
void GuiWrapper::SignalNetClientGameChatMsg(const string &playerName, const string &msg) { myStartWindow->signalNetClientGameChatMsg(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); }
void GuiWrapper::SignalNetClientLobbyChatMsg(const string &playerName, const string &msg) { myStartWindow->signalNetClientLobbyChatMsg(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); }
void GuiWrapper::SignalNetClientMsgBox(const string &msg) { myStartWindow->signalNetClientMsgBox(QString::fromUtf8(msg.c_str())); }
void GuiWrapper::SignalNetServerSuccess(int /*actionID*/) { }
+2 -1
View File
@@ -127,7 +127,8 @@ public:
void SignalNetClientPlayerChanged(unsigned playerId, const std::string &newPlayerName);
void SignalNetClientPlayerLeft(unsigned playerId, const std::string &playerName, int removeReason);
void SignalNetClientNewGameAdmin(unsigned playerId, const std::string &playerName);
void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientGameChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientLobbyChatMsg(const std::string &playerName, const std::string &msg);
void SignalNetClientMsgBox(const std::string &msg);
void SignalNetClientWaitDialog();
+3 -31
View File
@@ -141,8 +141,9 @@ 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(signalNetClientChatMsg(QString, QString)), myStartNetworkGameDialog, SLOT(receiveChatMsg(QString, QString)));
connect(this, SIGNAL(signalNetClientChatMsg(QString, QString)), myGuiInterface->getMyW()->getMyChat(), SLOT(receiveMessage(QString, QString)));
connect(this, SIGNAL(signalNetClientGameChatMsg(QString, QString)), myStartNetworkGameDialog, SLOT(receiveChatMsg(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(signalNetClientMsgBox(QString)), this, SLOT(networkMessage(QString)));
connect(this, SIGNAL(signalNetClientShowTimeoutDialog(int, unsigned)), this, SLOT(showTimeoutDialog(int, unsigned)));
@@ -316,35 +317,6 @@ void startWindowImpl::joinGameLobby() {
// Clear Lobby dialog.
myGameLobbyDialog->clearDialog();
//set clean irc nick
QString myNick(QString::fromUtf8(myConfig->readConfigString("MyName").c_str()));
myNick.replace(QString::fromUtf8("ä"),"ae");
myNick.replace(QString::fromUtf8("Ä"),"Ae");
myNick.replace(QString::fromUtf8("ü"),"ue");
myNick.replace(QString::fromUtf8("Ü"),"Ue");
myNick.replace(QString::fromUtf8("ö"),"oe");
myNick.replace(QString::fromUtf8("Ö"),"Oe");
myNick.replace(QString::fromUtf8("é"),"e");
myNick.replace(QString::fromUtf8("è"),"e");
myNick.replace(QString::fromUtf8("á"),"a");
myNick.replace(QString::fromUtf8("à"),"a");
myNick.replace(QString::fromUtf8("ó"),"o");
myNick.replace(QString::fromUtf8("ò"),"o");
myNick.replace(QString::fromUtf8("ú"),"u");
myNick.replace(QString::fromUtf8("ù"),"u");
myNick.replace(QString::fromUtf8("É"),"E");
myNick.replace(QString::fromUtf8("È"),"E");
myNick.replace(QString::fromUtf8("Á"),"A");
myNick.replace(QString::fromUtf8("À"),"A");
myNick.replace(QString::fromUtf8("Ó"),"O");
myNick.replace(QString::fromUtf8("Ò"),"O");
myNick.replace(QString::fromUtf8("Ú"),"U");
myNick.replace(QString::fromUtf8("Ù"),"U");
myNick.remove(QRegExp("[^A-Z^a-z^0-9|\\-_\\\\^`]*"));
myNick = myNick.mid(0,16);
mySession->setIrcNick(myNick.toUtf8().constData());
// Start client for dedicated server.
mySession->startInternetClient();
+2 -1
View File
@@ -80,7 +80,8 @@ signals:
void signalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId);
void signalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId);
void signalNetClientGameStart(boost::shared_ptr<Game> game);
void signalNetClientChatMsg(QString nickName, QString msg);
void signalNetClientGameChatMsg(QString nickName, QString msg);
void signalNetClientLobbyChatMsg(QString nickName, QString msg);
void signalNetClientMsgBox(QString msg);
void signalIrcConnect(QString server);
+2 -1
View File
@@ -57,7 +57,8 @@ public:
virtual void SignalNetClientPlayerLeft(unsigned playerId, const std::string &playerName, int removeReason) = 0;
virtual void SignalNetClientNewGameAdmin(unsigned playerId, const std::string &playerName) = 0;
virtual void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg) = 0;
virtual void SignalNetClientGameChatMsg(const std::string &playerName, const std::string &msg) = 0;
virtual void SignalNetClientLobbyChatMsg(const std::string &playerName, const std::string &msg) = 0;
virtual void SignalNetClientMsgBox(const std::string &msg) = 0;
virtual void SignalNetClientWaitDialog() = 0;
+2 -1
View File
@@ -70,7 +70,8 @@ public:
void SendLeaveCurrentGame();
void SendStartEvent(bool fillUpWithCpuPlayers);
void SendPlayerAction();
void SendChatMessage(const std::string &msg);
void SendGameChatMessage(const std::string &msg);
void SendLobbyChatMessage(const std::string &msg);
void SendJoinFirstGame(const std::string &password);
void SendJoinGame(unsigned gameId, const std::string &password);
void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password);
+17 -6
View File
@@ -809,18 +809,29 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
ChatMessage_t *netMessage = &tmpPacket->GetMsg()->choice.chatMessage;
string playerName;
if (netMessage->playerId == 0)
if (netMessage->chatType.present == chatType_PR_chatTypeBroadcast)
{
playerName = "(global notice)";
client->GetCallback().SignalNetClientGameChatMsg("(global notice)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
client->GetCallback().SignalNetClientLobbyChatMsg("(global notice)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
}
else
else if (netMessage->chatType.present == chatType_PR_chatTypeGame)
{
boost::shared_ptr<PlayerData> tmpPlayer = client->GetPlayerDataByUniqueId(netMessage->playerId);
unsigned playerId = netMessage->chatType.choice.chatTypeGame.playerId;
boost::shared_ptr<PlayerData> tmpPlayer = client->GetPlayerDataByUniqueId(playerId);
if (tmpPlayer.get())
playerName = tmpPlayer->GetName();
if (!playerName.empty())
client->GetCallback().SignalNetClientGameChatMsg(playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
}
else if (netMessage->chatType.present == chatType_PR_chatTypeLobby)
{
unsigned playerId = netMessage->chatType.choice.chatTypeLobby.playerId;
boost::shared_ptr<PlayerData> tmpPlayer = client->GetPlayerDataByUniqueId(playerId);
if (tmpPlayer.get())
playerName = tmpPlayer->GetName();
if (!playerName.empty())
client->GetCallback().SignalNetClientLobbyChatMsg(playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
}
if (!playerName.empty())
client->GetCallback().SignalNetClientChatMsg(playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
}
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_dialogMessage)
{
+22 -2
View File
@@ -172,18 +172,38 @@ ClientThread::SendPlayerAction()
}
void
ClientThread::SendChatMessage(const std::string &msg)
ClientThread::SendGameChatMessage(const std::string &msg)
{
// Warning: This function is called in the context of the GUI thread.
// Create a network packet containing the chat message.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_chatRequestMessage;
ChatRequestMessage_t *netChat = &packet->GetMsg()->choice.chatRequestMessage;
netChat->gameId = GetGameId();
OCTET_STRING_fromBuf(&netChat->chatText,
msg.c_str(),
msg.length());
netChat->chatRequestType.present = chatRequestType_PR_chatRequestTypeGame;
netChat->chatRequestType.choice.chatRequestTypeGame.gameId = GetGameId();
// Just dump the packet.
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
}
void
ClientThread::SendLobbyChatMessage(const std::string &msg)
{
// Warning: This function is called in the context of the GUI thread.
// Create a network packet containing the chat message.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_chatRequestMessage;
ChatRequestMessage_t *netChat = &packet->GetMsg()->choice.chatRequestMessage;
OCTET_STRING_fromBuf(&netChat->chatText,
msg.c_str(),
msg.length());
netChat->chatRequestType.present = chatRequestType_PR_chatRequestTypeLobby;
// Just dump the packet.
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
}
+4 -2
View File
@@ -240,8 +240,10 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
netChat->gameId = server->GetId();
netChat->playerId = session.playerData->GetUniqueId();
netChat->chatType.present = chatType_PR_chatTypeGame;
ChatTypeGame_t *netGameChat = &netChat->chatType.choice.chatTypeGame;
netGameChat->gameId = server->GetId();
netGameChat->playerId = session.playerData->GetUniqueId();
OCTET_STRING_fromBuf(
&netChat->chatText,
(char *)netChatRequest->chatText.buf,
+24 -3
View File
@@ -399,14 +399,13 @@ ServerLobbyThread::SendGlobalChat(const string &message)
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
// TODO proper game id handling.
netChat->gameId = 0;
netChat->playerId = 0;
netChat->chatType.present = chatType_PR_chatTypeBroadcast;
OCTET_STRING_fromBuf(
&netChat->chatText,
message.c_str(),
message.length());
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
}
@@ -747,6 +746,8 @@ ServerLobbyThread::HandlePacket(SessionWrapper session, boost::shared_ptr<NetPac
else if (joinRequest->joinGameAction.present == joinGameAction_PR_joinExistingGame)
HandleNetPacketJoinGame(session, password, joinRequest->joinGameAction.choice.joinExistingGame);
}
else if (packet->GetMsg()->present == PokerTHMessage_PR_chatRequestMessage)
HandleNetPacketChatRequest(session, packet->GetMsg()->choice.chatRequestMessage);
else
SessionError(session, ERR_SOCK_INVALID_STATE);
}
@@ -1070,6 +1071,26 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st
}
}
void
ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest)
{
if (chatRequest.chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby && session.playerData)
{
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
netChat->chatType.present = chatType_PR_chatTypeLobby;
ChatTypeLobby_t *netLobbyChat = &netChat->chatType.choice.chatTypeLobby;
netLobbyChat->playerId = session.playerData->GetUniqueId();
OCTET_STRING_fromBuf(
&netChat->chatText,
(char *)chatRequest.chatText.buf,
chatRequest.chatText.size);
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
}
}
void
ServerLobbyThread::EstablishSession(SessionWrapper session)
{
+1
View File
@@ -122,6 +122,7 @@ protected:
void HandleNetPacketRetrieveAvatar(SessionWrapper session, const AvatarRequestMessage_t &retrieveAvatar);
void HandleNetPacketCreateGame(SessionWrapper session, const std::string &password, const JoinNewGame_t &newGame);
void HandleNetPacketJoinGame(SessionWrapper session, const std::string &password, const JoinExistingGame_t &joinGame);
void HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest);
void EstablishSession(SessionWrapper session);
void RequestPlayerAvatar(SessionWrapper session);
void TimerRemoveGame(const boost::system::error_code &ec);
+10 -31
View File
@@ -156,30 +156,13 @@ boost::shared_ptr<AvatarManager> Session::getAvatarManager()
void Session::startInternetClient()
{
if (myNetClient || myClientIrcThread || !myGui)
if (myNetClient || !myGui)
{
assert(false);
return;
}
myGameType = GAME_TYPE_INTERNET;
if (myConfig->readConfigInt("UseIRCLobbyChat"))
{
myClientIrcThread.reset(new IrcThread(myGui));
myClientIrcThread->Init(
myConfig->readConfigString("IRCServerAddress"),
myConfig->readConfigInt("IRCServerPort"),
myConfig->readConfigInt("IRCServerUseIpv6") == 1,
myIrcNick,
#ifdef POKERTH_IS_07BETA
"#pokerth-lobby-07beta",
#else
myConfig->readConfigString("IRCChannel"),
#endif
myConfig->readConfigString("IRCChannelPassword"));
myClientIrcThread->Run();
}
myNetClient.reset(new ClientThread(*myGui, *myAvatarManager));
bool useAvatarServer = myConfig->readConfigInt("UseAvatarServer") != 0;
@@ -261,13 +244,9 @@ void Session::terminateNetworkClient()
if (!myNetClient)
return; // already terminated
myNetClient->SignalTermination();
if (myClientIrcThread)
myClientIrcThread->SignalTermination();
// Give the threads some time to terminate.
if (myNetClient->Join(NET_CLIENT_TERMINATE_TIMEOUT_MSEC))
myNetClient.reset();
if (myClientIrcThread && myClientIrcThread->Join(NET_IRC_TERMINATE_TIMEOUT_MSEC))
myClientIrcThread.reset();
// If termination fails, leave a memory leak to prevent a crash.
myGameType = GAME_TYPE_NONE;
@@ -348,13 +327,6 @@ bool Session::pollNetworkServerTerminated()
return retVal;
}
void Session::sendIrcChatMessage(const std::string &message)
{
if (!myClientIrcThread)
return;
myClientIrcThread->SendChatMessage(message);
}
void Session::sendLeaveCurrentGame()
{
if (!myNetClient)
@@ -376,11 +348,18 @@ void Session::sendClientPlayerAction()
myNetClient->SendPlayerAction();
}
void Session::sendChatMessage(const std::string &message)
void Session::sendGameChatMessage(const std::string &message)
{
if (!myNetClient)
return; // only act if client is running.
myNetClient->SendChatMessage(message);
myNetClient->SendGameChatMessage(message);
}
void Session::sendLobbyChatMessage(const std::string &message)
{
if (!myNetClient)
return;
myNetClient->SendLobbyChatMessage(message);
}
void Session::kickPlayer(unsigned playerId)
+2 -5
View File
@@ -75,12 +75,10 @@ public:
void terminateNetworkServer();
bool pollNetworkServerTerminated();
void sendIrcChatMessage(const std::string &message);
void setIrcNick(const std::string &value) { myIrcNick = value; }
void sendClientPlayerAction();
void sendChatMessage(const std::string &message);
void sendGameChatMessage(const std::string &message);
void sendLobbyChatMessage(const std::string &message);
void kickPlayer(unsigned playerId);
void kickPlayer(const std::string &playerName);
void startVoteKickPlayer(unsigned playerId);
@@ -108,7 +106,6 @@ private:
boost::shared_ptr<ClientThread> myNetClient;
boost::shared_ptr<ServerManager> myNetServer;
boost::shared_ptr<IrcThread> myClientIrcThread;
boost::shared_ptr<AvatarManager> myAvatarManager;