mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
chat code
This commit is contained in:
parent
8daa81e462
commit
5d32bb8bc4
14 changed files with 85 additions and 28 deletions
|
|
@ -1,8 +1,8 @@
|
|||
#include "chatchannel.h"
|
||||
#include "serversocket.h"
|
||||
|
||||
ChatChannel::ChatChannel(const QString &_name, const QString &_description)
|
||||
: name(_name), description(_description)
|
||||
ChatChannel::ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QStringList &_joinMessage)
|
||||
: name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -16,6 +16,8 @@ void ChatChannel::addPlayer(ServerSocket *player)
|
|||
|
||||
for (int i = 0; i < size(); ++i)
|
||||
player->msg(QString("chat|list_players|%1|%2").arg(name).arg(at(i)->getPlayerName()));
|
||||
for (int i = 0; i < joinMessage.size(); ++i)
|
||||
player->msg(QString("chat|server_message|%1|%2").arg(name).arg(joinMessage[i]));
|
||||
|
||||
emit channelInfoChanged();
|
||||
}
|
||||
|
|
@ -40,5 +42,5 @@ void ChatChannel::say(ServerSocket *player, const QString &s)
|
|||
|
||||
QString ChatChannel::getChannelListLine() const
|
||||
{
|
||||
return QString("chat|list_channels|%1|%2|%3").arg(name).arg(description).arg(size());
|
||||
}
|
||||
return QString("chat|list_channels|%1|%2|%3|%4").arg(name).arg(description).arg(size()).arg(autoJoin ? 1 : 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
class ServerSocket;
|
||||
|
||||
|
|
@ -13,10 +14,13 @@ signals:
|
|||
private:
|
||||
QString name;
|
||||
QString description;
|
||||
bool autoJoin;
|
||||
QStringList joinMessage;
|
||||
public:
|
||||
ChatChannel(const QString &_name, const QString &_description);
|
||||
ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QStringList &_joinMessage);
|
||||
QString getName() const { return name; }
|
||||
QString getDescription() const { return description; }
|
||||
bool getAutoJoin() const { return autoJoin; }
|
||||
void addPlayer(ServerSocket *player);
|
||||
void removePlayer(ServerSocket *player);
|
||||
void say(ServerSocket *player, const QString &s);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
#include <QSettings>
|
||||
|
||||
Server::Server(QObject *parent)
|
||||
: QTcpServer(parent), nextGameId(0)
|
||||
: QTcpServer(parent), nextGameId(0)
|
||||
{
|
||||
rng = new RNG_Qt(this);
|
||||
|
||||
|
|
@ -37,11 +37,20 @@ Server::Server(QObject *parent)
|
|||
if (dbType == "mysql")
|
||||
openDatabase();
|
||||
|
||||
chatChannelList << new ChatChannel("channel1", "testchannel 1");
|
||||
chatChannelList << new ChatChannel("channel2", "testchannel 2");
|
||||
int size = settings->beginReadArray("chatchannels");
|
||||
for (int i = 0; i < size; ++i) {
|
||||
settings->setArrayIndex(i);
|
||||
chatChannelList << new ChatChannel(settings->value("name").toString(),
|
||||
settings->value("description").toString(),
|
||||
settings->value("autojoin").toBool(),
|
||||
settings->value("joinmessage").toStringList());
|
||||
}
|
||||
settings->endArray();
|
||||
|
||||
for (int i = 0; i < chatChannelList.size(); ++i)
|
||||
connect(chatChannelList[i], SIGNAL(channelInfoChanged()), this, SLOT(broadcastChannelUpdate()));
|
||||
|
||||
loginMessage = settings->value("messages/login").toStringList();
|
||||
}
|
||||
|
||||
Server::~Server()
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#define SERVER_H
|
||||
|
||||
#include <QTcpServer>
|
||||
#include <QStringList>
|
||||
|
||||
class ServerGame;
|
||||
class ServerSocket;
|
||||
|
|
@ -52,12 +53,14 @@ public:
|
|||
AbstractRNG *getRNG() const { return rng; }
|
||||
void broadcastGameListUpdate(ServerGame *game);
|
||||
void removePlayer(ServerSocket *player);
|
||||
const QStringList &getLoginMessage() const { return loginMessage; }
|
||||
private:
|
||||
void incomingConnection(int SocketId);
|
||||
QList<ServerGame *> games;
|
||||
QList<ServerSocket *> players;
|
||||
QList<ChatChannel *> chatChannelList;
|
||||
int nextGameId;
|
||||
QStringList loginMessage;
|
||||
AbstractRNG *rng;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -236,7 +236,13 @@ ReturnMessage::ReturnCode ServerSocket::cmdLogin(const QList<QVariant> ¶ms)
|
|||
return ReturnMessage::ReturnPasswordWrong;
|
||||
playerName = params[0].toString();
|
||||
|
||||
return ReturnMessage::ReturnOk;
|
||||
remsg->send(ReturnMessage::ReturnOk);
|
||||
|
||||
QStringList loginMessage = server->getLoginMessage();
|
||||
for (int i = 0; i < loginMessage.size(); ++i)
|
||||
msg("chat|server_message||" + loginMessage[i]);
|
||||
|
||||
return ReturnMessage::ReturnNothing;
|
||||
}
|
||||
|
||||
ReturnMessage::ReturnCode ServerSocket::cmdChatListChannels(const QList<QVariant> &/*params*/)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue