mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-09 15:54:47 -07:00
chat code
This commit is contained in:
parent
120193fb0b
commit
e6a419aa3d
9 changed files with 51 additions and 9 deletions
|
|
@ -37,3 +37,8 @@ void ChatChannel::say(ServerSocket *player, const QString &s)
|
|||
for (int i = 0; i < size(); ++i)
|
||||
at(i)->msg(str);
|
||||
}
|
||||
|
||||
QString ChatChannel::getChannelListLine() const
|
||||
{
|
||||
return QString("chat|list_channels|%1|%2|%3").arg(name).arg(description).arg(size());
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ public:
|
|||
void addPlayer(ServerSocket *player);
|
||||
void removePlayer(ServerSocket *player);
|
||||
void say(ServerSocket *player, const QString &s);
|
||||
QString getChannelListLine() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ Server::Server(QObject *parent)
|
|||
|
||||
chatChannelList << new ChatChannel("channel1", "testchannel 1");
|
||||
chatChannelList << new ChatChannel("channel2", "testchannel 2");
|
||||
|
||||
for (int i = 0; i < chatChannelList.size(); ++i)
|
||||
connect(chatChannelList[i], SIGNAL(channelInfoChanged()), this, SLOT(broadcastChannelUpdate()));
|
||||
}
|
||||
|
||||
Server::~Server()
|
||||
|
|
@ -163,6 +166,14 @@ void Server::broadcastGameListUpdate(ServerGame *game)
|
|||
players[i]->msg(line);
|
||||
}
|
||||
|
||||
void Server::broadcastChannelUpdate()
|
||||
{
|
||||
QString line = qobject_cast<ChatChannel *>(sender())->getChannelListLine();
|
||||
for (int i = 0; i < players.size(); ++i)
|
||||
if (players[i]->getAcceptsChatChannelListChanges())
|
||||
players[i]->msg(line);
|
||||
}
|
||||
|
||||
void Server::addClientToGame(int gameId, ServerSocket *client)
|
||||
{
|
||||
ServerGame *game = getGame(gameId);
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ private slots:
|
|||
void addGame(const QString description, const QString password, const int maxPlayers, ServerSocket *creator);
|
||||
void addClientToGame(int gameId, ServerSocket *client);
|
||||
void gameClosing();
|
||||
void broadcastChannelUpdate();
|
||||
public:
|
||||
Server(QObject *parent = 0);
|
||||
~Server();
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdChatListChannels(const QList<QVariant
|
|||
{
|
||||
QList<ChatChannel *> chatChannelList = server->getChatChannelList();
|
||||
for (int i = 0; i < chatChannelList.size(); ++i)
|
||||
msg(QString("chat|list_channels|%1|%2|%3").arg(chatChannelList[i]->getName()).arg(chatChannelList[i]->getDescription()).arg(chatChannelList[i]->size()));
|
||||
msg(chatChannelList[i]->getChannelListLine());
|
||||
|
||||
acceptsChatChannelListChanges = true;
|
||||
return ReturnMessage::ReturnOk;
|
||||
|
|
@ -306,6 +306,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdCreateGame(const QList<QVariant> &par
|
|||
QString password = params[1].toString();
|
||||
int maxPlayers = params[2].toInt();
|
||||
acceptsGameListChanges = false;
|
||||
acceptsChatChannelListChanges = false;
|
||||
leaveGame();
|
||||
emit createGame(description, password, maxPlayers, this);
|
||||
return ReturnMessage::ReturnOk;
|
||||
|
|
@ -318,6 +319,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdJoinGame(const QList<QVariant> ¶m
|
|||
if (!server->checkGamePassword(gameId, password))
|
||||
return ReturnMessage::ReturnPasswordWrong;
|
||||
acceptsGameListChanges = false;
|
||||
acceptsChatChannelListChanges = false;
|
||||
leaveGame();
|
||||
emit joinGame(gameId, this);
|
||||
return ReturnMessage::ReturnOk;
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ public:
|
|||
void setPlayerId(int _id) { playerId = _id; }
|
||||
QString getPlayerName() const { return playerName; }
|
||||
bool getAcceptsGameListChanges() const { return acceptsGameListChanges; }
|
||||
bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; }
|
||||
QStringList listCounters() const;
|
||||
QStringList listZones() const;
|
||||
void setupZones();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue