26 #include "configuration/doomseekerconfig.h"
27 #include "configuration/queryspeed.h"
28 #include "pathfinder/pathfinder.h"
29 #include "plugins/engineplugin.h"
31 #include "serverapi/tooltips/tooltipgenerator.h"
32 #include "serverapi/exefile.h"
33 #include "serverapi/gameclientrunner.h"
34 #include "serverapi/gameexeretriever.h"
35 #include "serverapi/message.h"
36 #include "serverapi/playerslist.h"
37 #include "lookuphost.h"
38 #include <QElapsedTimer>
50 gameMode = GameMode::mkCooperative();
77 QElapsedTimer lastRefreshClock;
89 bool randomMapRotation;
113 QWeakPointer<Server>
self;
124 QString
Server::teamNames[] =
137 d->bIsRefreshing =
false;
139 d->lockedInGame =
false;
143 d->name = tr(
"<< ERROR >>");
149 for (
int i = 0; i < MAX_TEAMS; ++i)
154 d->randomMapRotation =
false;
158 d->lastRefreshClock.invalidate();
160 set_customDetails(&Server::customDetails_default);
161 set_createSendRequest(&Server::createSendRequest_default);
162 set_readRequest(&Server::readRequest_default);
164 if(gConfig.doomseeker.bLookupHosts)
196 return QString(
"%1:%2").arg(
address().toString()).arg(
port());
202 if (!d->iwad.trimmed().isEmpty())
206 foreach (
const PWad&
wad, d->wads)
208 result << wad.
name();
215 if (d->iwad.contains(text, cs))
220 for (
int j = 0; j <
numWads(); ++j)
223 if (pwad.
name().contains(text, cs))
231 void Server::clearDMFlags()
236 QByteArray Server::createSendRequest_default()
238 assert(0 &&
"Server::createSendRequest() is not implemented");
263 QString Server::customDetails_default()
278 void Server::emitUpdated(
int response)
280 emit
updated(
self(), response);
287 return plugin()->data()->name;
291 return tr(
"Undefined");
312 if(!forceAddress && gConfig.doomseeker.bLookupHosts &&
313 d->host.error() == QHostInfo::NoError && d->host.lookupId() != -1)
315 return QString(
"%1:%2").arg(d->host.hostName()).arg(
port());
317 return QString(
"%1:%2").arg(
address().toString()).arg(
port());
332 return d->players.numClients() == 0;
337 return d->players.numClients() ==
maxClients();
357 return d->lockedInGame;
362 return d->randomMapRotation;
367 return d->bIsRefreshing;
387 LookupHost::lookupHost(
address().toString(),
this,
388 SLOT(setHostName(QHostInfo)));
403 return d->maxClients;
408 return d->maxPlayers;
413 return QList<GameCVar>();
429 return (returnValue < 0) ? 0 : returnValue;
434 int returnValue = d->maxPlayers - d->players.numClients();
435 return (returnValue < 0) ? 0 : returnValue;
441 return (returnValue < 0) ? 0 : returnValue;
451 return d->players[index];
471 assert(0 &&
"Server::readRequest(const QByteArray&) is not implemented.");
477 d->bIsRefreshing =
true;
480 d->triesLeft = gConfig.doomseeker.querySpeed().attemptsPerServer;
481 if (d->triesLeft > 10)
489 d->lastRefreshClock.start();
490 setResponse(response);
494 d->ping = d->pingClock.elapsed();
495 d->bPingIsSet =
true;
497 d->bIsRefreshing =
false;
498 d->iwad = d->iwad.toLower();
499 emit
updated(
self(), response);
504 return d->scores[team];
509 return d->scoreLimit;
529 if (d->triesLeft <= 0)
537 if (request.isEmpty())
543 d->bPingIsSet =
false;
544 d->pingClock.start();
573 d->version = version;
576 void Server::setHostName(QHostInfo host)
579 if(!d->bIsRefreshing)
595 d->lockedInGame = locked;
605 d->mapName = mapName;
625 d->name = serverName;
627 d->name.replace(
'\n',
' ').replace(
'\r',
' ');
647 d->randomMapRotation = randomMapRotation;
650 void Server::setResponse(
Response response)
652 d->response = response;
663 void Server::setScores(
const QList<int>&
scores)
670 d->scoreLimit = serverScoreLimit;
675 d->bSecure = bSecure;
685 d->timeLeft = serverTimeLeft;
690 d->timeLimit = serverTimeLimit;
698 void Server::setWads(
const QList<PWad>&
wads)
712 case Player::TEAM_BLUE:
713 return qRgb(0, 0, 255);
714 case Player::TEAM_RED:
715 return qRgb(255, 0, 0);
716 case Player::TEAM_GREEN:
717 return qRgb(0, 255, 0);
718 case Player::TEAM_GOLD:
719 return qRgb(255, 255, 0);
722 return qRgb(0, 255, 0);
727 return team < MAX_TEAMS && team >= 0 ? teamNames[team] :
"";
742 if (d->lastRefreshClock.isValid())
744 return d->lastRefreshClock.elapsed();
764 return wads()[index];
776 QScopedPointer<ExeFile> exeFile(
clientExe());
const QStringList & mapList() const
List of all levels that are in map rotation on this server.
const QPixmap & icon() const
Icon for this server.
void setRandomMapRotation(bool b)
Set random map rotation status parsed from the response packet.
virtual QString teamName(int team) const
Name of team under given index.
void setSecure(bool bSecureServer)
Set isSecure().
void setProgramName(const QString &name)
Plugin setter for programName().
const QString & webSite() const
Website URL provided by this server.
bool isLockedInGame() const
"Join" passworded or not.
Performs a case-insensitive (OS independent) file searches.
bool isRefreshing() const
Is the server being refreshed at the current moment?
int numFreeClientSlots() const
Amount of free connection slots.
void lookupHost()
Prompts the server to reverse resolve its address to a hostname.
virtual GameClientRunner * gameRunner()
Creates an instance of GameClientRunner's derivative class.
unsigned char skill() const
Game skill level, starting from zero.
QString addressWithPort() const
Returns "address:port" string.
void setGameMode(const GameMode &gameMode)
Set game mode parsed from the response packet.
bool anyWadnameContains(const QString &text, Qt::CaseSensitivity cs=Qt::CaseInsensitive) const
True if name of any WAD of this server contains given text.
const QString & motd() const
Messafe of the Day.
void setExeTypeName(const QString &name)
Plugin setter for exeTypeName().
void setPort(unsigned short i)
Set network port, should be called by Doomseeker only.
void setMapList(const QStringList &mapList)
Set map rotation list parsed from the response packet.
Message object used to pass messages throughout the Doomseeker's system.
Player is banned from that server.
A convenience wrapper class for GameExeFactory.
void setCustom(bool custom)
Set whether this server is custom, should be called by Doomseeker only.
const QList< PWad > & wads() const
List of all PWADs loaded on this server.
unsigned int ping() const
Ping from local host to this server.
void setTimeLeft(unsigned short timeLeft)
Set timeLeft().
int numTotalSlots() const
Actual number of free connection slots deduced from maxPlayers() and maxClients().
QString hostName(bool forceAddress=false) const
A string that is either the "ipaddress:port" or "hostname:port".
QString engineName() const
Returns name of the engine for this server, for example: "Skulltag".
unsigned short maxPlayers() const
Amount of play slots for this server.
void setConfigKey(const QString &keyName)
Plugin setter for configKey().
A representation of a server for a given game.
const QString & gameVersion() const
Version of the server program (1.0, 0.98-beta, and so on).
virtual QRgb teamColor(int team) const
Color of team under given index.
"Dummy" response for servers that weren't refreshed yet.
virtual QList< GameCVar > modifiers() const
What kind of game modifiers are enabled on this server?
virtual ExeFile * clientExe()
Client executable retriever.
int numFreeJoinSlots() const
Amount of free play slots.
QWeakPointer< Server > self() const
Reference to this server made available ONLY after the server is fully created.
void clearWads()
Clear PWADs list.
unsigned int score(int team=0) const
Total score of a given team, by default team 0 is used.
void setWebSite(const QString &site)
Set web site URL parsed from the response packet.
void setGameVersion(const QString &version)
Set gameVersion().
bool isSecure() const
Secure as in 'secure for players', not 'passworded'.
void setIwad(const QString &iwad)
Set iwad().
void setEmail(const QString &mail)
Set email parsed from the response packet.
Response from the server was erroreneous.
QByteArray createSendRequest()
[Pure Virtual] Prepares challenge data.
void setMaxPlayers(unsigned short i)
Set amount of slots for players parsed from the response packet.
void setTimeLimit(unsigned short timeLimit)
Set timeLimit().
virtual TooltipGenerator * tooltipGenerator() const
Creates an instance of TooltipGenerator.
Response lastResponse() const
Last response status deduced by parsing of the server response packet.
const QString & name() const
Server's name.
Server(const QHostAddress &address, unsigned short port)
Spawn server with given address and port.
const PWad & wad(int index) const
PWAD under given index on the PWADs list.
Data structure that holds information about players in a server.
void begunRefreshing(ServerPtr server)
Emitted when refresh process begins for the current server.
const GameMode & gameMode() const
GameMode that is currently running on this server.
unsigned short timeLimit() const
Round time limit, expressed in minutes.
bool isLocked() const
"Connect" passworded or not.
Game mode representation.
QStringList allWadNames() const
IWAD + PWADs.
const QList< int > & scores() const
Scores for all teams.
unsigned short timeLeft() const
Amount of time until the round is over, expressed in minutes.
const QString & iwad() const
IWAD used by this server.
void addPlayer(const Player &player)
Add new Player to this server's PlayersList.
void addWad(const PWad &wad)
Add PWAD to the list of this server's PWADs.
const QString & email() const
Email address provided by this server.
void setLocked(bool locked)
Set isLocked().
Response readRefreshQueryResponse(const QByteArray &data)
Entry point for Refresher that pushes response packet for parsing.
virtual EnginePlugin * plugin() const =0
void setPing(unsigned int currentPing)
Set ping().
Response was parsed properly and Server information is available.
const PlayersList & players() const
List of players that are on this server currently.
virtual PathFinder wadPathFinder()
Instantiate and return PathFinder configured to search for WADs for this server.
void setSelf(const QWeakPointer< Server > &self)
Set "self" reference, should by called by Doomseeker only.
void setMaxClients(unsigned short i)
Set amount of slots for client parsed from the response packet.
void clearPlayersList()
Removes all players from PlayersList.
const QList< DMFlagsSection > & dmFlags() const
dmflags used by this server.
void refreshStarts()
Called when server begins refreshing routine.
qint64 timeMsSinceLastRefresh() const
Milliseconds elapsed since last refresh.
bool isEmpty() const
Are there any players on this server?
void setMap(const QString &name)
Set current level parsed from the response packet.
void setDmFlags(const QList< DMFlagsSection > &dmFlags)
Set dmFlags().
bool isFull() const
Is this server full?
void updated(ServerPtr server, int response)
Emitted when a refresh has been completed.
bool isRandomMapRotation() const
Is random maplist rotation enabled?
void refreshStops(Response response)
Called when server finishes refreshing routine.
void setScoreLimit(unsigned int scoreLimit)
Set scoreLimit().
void setName(const QString &name)
Set server's name parsed from the response packet.
Server didn't respond at all.
void setLockedInGame(bool locked)
Set isLockedInGame().
const Player & player(int index) const
Player at given index of PlayersList.
int numFreeSpectatorSlots() const
Amount of free spectator slots.
QList< int > & scoresMutable()
Mutable reference to the scores list, available for contents modification.
bool isKnown() const
Is information for this server available?
Creates command line that launches the client executable of the game and connects it to a server...
Response
Type of response that is extracted by parsing the packet that came from the Server.
int numWads() const
Number of PWADs loaded on this server.
bool isLockedAnywhere() const
True if any "isLocked()" returns true.
Access to external program executables (game clients, servers, and so on).
void addPrioritySearchDir(const QString &dir)
void setPingIsSet(bool b)
Plugins should set this to true to prevent default ping calculation.
void setMotd(const QString &message)
Set Message of the Day parsed from the response packet.
unsigned short port() const
Network port on which this server is hosted.
unsigned short maxClients() const
Amount of connection slots for this server, as reported by the server.
bool isCustom() const
Is this a custom server defined by the user?
unsigned int scoreLimit() const
Current score limit.
QString customDetails()
[Virtual] Allows a plugin to provide custom server details.
Response readRequest(const QByteArray &data)
[Pure Virtual] Reads response packet.
const QHostAddress & address() const
Address of this server.
const QString & map() const
Name of the current level.
void setSkill(unsigned char newSkill)
Set skill level parsed from the response packet.
const QString & name() const
File name of the WAD.
bool sendRefreshQuery(QUdpSocket *socket)
Method called by the refreshing thread; sends the challenge query through refresher's socket...