mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 03:28:49 -07:00
initial commit of local server code
This commit is contained in:
parent
cbfbc542e7
commit
7921b5f82d
35 changed files with 143 additions and 365 deletions
|
|
@ -92,10 +92,12 @@ void Server::broadcastGameListUpdate(Server_Game *game)
|
|||
eventGameList.append(new ServerInfo_Game(game->getGameId(), QString(), false, 0, game->getMaxPlayers(), QString(), false, 0));
|
||||
Event_ListGames *event = new Event_ListGames(eventGameList);
|
||||
|
||||
bool mayDelete = true;
|
||||
for (int i = 0; i < clients.size(); i++)
|
||||
if (clients[i]->getAcceptsGameListChanges())
|
||||
clients[i]->sendProtocolItem(event, false);
|
||||
delete event;
|
||||
mayDelete = clients[i]->sendProtocolItem(event, false);
|
||||
if (mayDelete)
|
||||
delete event;
|
||||
}
|
||||
|
||||
void Server::broadcastChannelUpdate()
|
||||
|
|
@ -105,10 +107,12 @@ void Server::broadcastChannelUpdate()
|
|||
eventChannelList.append(new ServerInfo_ChatChannel(channel->getName(), channel->getDescription(), channel->size(), channel->getAutoJoin()));
|
||||
Event_ListChatChannels *event = new Event_ListChatChannels(eventChannelList);
|
||||
|
||||
bool mayDelete = true;
|
||||
for (int i = 0; i < clients.size(); ++i)
|
||||
if (clients[i]->getAcceptsChatChannelListChanges())
|
||||
clients[i]->sendProtocolItem(event, false);
|
||||
delete event;
|
||||
mayDelete = clients[i]->sendProtocolItem(event, false);
|
||||
if (mayDelete)
|
||||
delete event;
|
||||
}
|
||||
|
||||
void Server::gameClosing()
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ void Server_ChatChannel::say(Server_ProtocolHandler *client, const QString &s)
|
|||
|
||||
void Server_ChatChannel::sendChatEvent(ChatEvent *event)
|
||||
{
|
||||
bool mayDelete = true;
|
||||
for (int i = 0; i < size(); ++i)
|
||||
at(i)->sendProtocolItem(event, false);
|
||||
delete event;
|
||||
mayDelete = at(i)->sendProtocolItem(event, false);
|
||||
if (mayDelete)
|
||||
delete event;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include "server_card.h"
|
||||
#include "server_cardzone.h"
|
||||
#include "server_counter.h"
|
||||
#include <QSqlQuery>
|
||||
#include <QTimer>
|
||||
|
||||
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, QObject *parent)
|
||||
|
|
@ -345,28 +344,34 @@ void Server_Game::sendGameEvent(GameEvent *event, GameEventContext *context, Ser
|
|||
|
||||
void Server_Game::sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude, bool excludeOmniscient)
|
||||
{
|
||||
bool mayDelete = true;
|
||||
|
||||
cont->setGameId(gameId);
|
||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
Server_Player *p = playerIterator.next().value();
|
||||
if ((p != exclude) && !(excludeOmniscient && p->getSpectator() && spectatorsSeeEverything))
|
||||
p->sendProtocolItem(cont, false);
|
||||
mayDelete = p->sendProtocolItem(cont, false);
|
||||
}
|
||||
|
||||
delete cont;
|
||||
if (mayDelete)
|
||||
delete cont;
|
||||
}
|
||||
|
||||
void Server_Game::sendGameEventContainerOmniscient(GameEventContainer *cont, Server_Player *exclude)
|
||||
{
|
||||
bool mayDelete = true;
|
||||
|
||||
cont->setGameId(gameId);
|
||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
Server_Player *p = playerIterator.next().value();
|
||||
if ((p != exclude) && (p->getSpectator() && spectatorsSeeEverything))
|
||||
p->sendProtocolItem(cont, false);
|
||||
mayDelete = p->sendProtocolItem(cont, false);
|
||||
}
|
||||
|
||||
delete cont;
|
||||
|
||||
if (mayDelete)
|
||||
delete cont;
|
||||
}
|
||||
|
||||
void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
|
||||
|
|
|
|||
|
|
@ -196,8 +196,10 @@ bool Server_Player::deleteCounter(int counterId)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Server_Player::sendProtocolItem(ProtocolItem *item, bool deleteItem)
|
||||
bool Server_Player::sendProtocolItem(ProtocolItem *item, bool deleteItem)
|
||||
{
|
||||
if (handler)
|
||||
handler->sendProtocolItem(item, deleteItem);
|
||||
return handler->sendProtocolItem(item, deleteItem);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public:
|
|||
void clearZones();
|
||||
void setupZones();
|
||||
|
||||
void sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
|
||||
bool sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public:
|
|||
const QDateTime &getLastCommandTime() const { return lastCommandTime; }
|
||||
|
||||
void processCommandContainer(CommandContainer *cont);
|
||||
virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
|
||||
virtual bool sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
|
||||
void enqueueProtocolItem(ProtocolItem *item);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue