25 #include "configuration/doomseekerconfig.h" 26 #include "configuration/queryspeed.h" 28 #include "pathfinder/pathfinder.h" 29 #include "pathfinder/wadpathfinder.h" 30 #include "plugins/engineplugin.h" 31 #include "serverapi/exefile.h" 32 #include "serverapi/gameclientrunner.h" 33 #include "serverapi/gameexeretriever.h" 34 #include "serverapi/message.h" 35 #include "serverapi/playerslist.h" 36 #include "serverapi/tooltips/tooltipgenerator.h" 37 #include "strings.hpp" 39 #include <QElapsedTimer> 50 gameMode = GameMode::mkCooperative();
77 QElapsedTimer lastRefreshClock;
90 bool randomMapRotation;
115 QWeakPointer<Server>
self;
126 QString
Server::teamNames[] =
139 d->bIsRefreshing =
false;
142 d->lockedInGame =
false;
143 d->testingServer =
false;
147 d->name = tr(
"<< ERROR >>");
153 for (
int i = 0; i < MAX_TEAMS; ++i)
158 d->randomMapRotation =
false;
162 d->lastRefreshClock.invalidate();
164 set_customDetails(&Server::customDetails_default);
165 set_createSendRequest(&Server::createSendRequest_default);
166 set_readRequest(&Server::readRequest_default);
168 if (gConfig.doomseeker.bLookupHosts)
200 return QString(
"%1:%2").arg(
address().toString()).arg(
port());
206 if (!d->iwad.trimmed().isEmpty())
210 for (
const PWad &
wad : d->wads)
212 result << wad.
name();
219 if (d->iwad.contains(text, cs))
224 for (
int j = 0; j <
numWads(); ++j)
227 if (pwad.
name().contains(text, cs))
235 void Server::clearDMFlags()
240 QByteArray Server::createSendRequest_default()
242 assert(0 &&
"Server::createSendRequest() is not implemented");
262 f->setExeTypeName(tr(
"client"));
263 f->setConfigKey(
"BinaryPath");
267 QString Server::customDetails_default()
286 return plugin()->data()->name;
290 return tr(
"Undefined");
311 if (!forceAddress && gConfig.doomseeker.bLookupHosts &&
312 d->host.error() == QHostInfo::NoError && d->host.lookupId() != -1)
314 return QString(
"%1:%2").arg(d->host.hostName()).arg(
port());
316 return QString(
"%1:%2").arg(
address().toString()).arg(
port());
331 return d->players.numClients() == 0;
336 return d->players.numClients() ==
maxClients();
356 return d->lockedInGame;
361 return d->randomMapRotation;
366 return d->bIsRefreshing;
381 return d->testingServer;
396 QHostInfo::lookupHost(
address().toString(),
this,
397 SLOT(setHostName(QHostInfo)));
412 return d->maxClients;
417 return d->maxPlayers;
422 return QList<GameCVar>();
438 return (returnValue < 0) ? 0 : returnValue;
443 int returnValue = d->maxPlayers - d->players.numClients();
444 return (returnValue < 0) ? 0 : returnValue;
450 return (returnValue < 0) ? 0 : returnValue;
460 return d->players[index];
481 assert(0 &&
"Server::readRequest(const QByteArray&) is not implemented.");
487 d->bIsRefreshing =
true;
490 d->triesLeft = gConfig.doomseeker.querySpeed().attemptsPerServer;
492 d->triesLeft = qMin(d->triesLeft, QuerySpeed::MAX_ATTEMPTS_PER_SERVER);
494 d->triesLeft = qMax(d->triesLeft, 1);
499 d->lastRefreshClock.start();
500 setResponse(response);
504 d->ping = d->pingClock.elapsed();
505 d->bPingIsSet =
true;
507 d->bIsRefreshing =
false;
508 d->iwad = d->iwad.toLower();
509 emit
updated(
self(), response);
514 return d->scores[team];
519 return d->scoreLimit;
539 if (d->triesLeft <= 0)
547 if (request.isEmpty())
553 d->bPingIsSet =
false;
554 d->pingClock.start();
583 d->version = version;
586 void Server::setHostName(QHostInfo host)
589 if (!d->bIsRefreshing)
605 d->lockedInGame = locked;
615 d->mapName = mapName;
635 d->name = serverName;
637 d->name.replace(
'\n',
' ').replace(
'\r',
' ');
657 d->randomMapRotation = randomMapRotation;
660 void Server::setResponse(
Response response)
662 d->response = response;
673 void Server::setScores(
const QList<int> &
scores)
680 d->scoreLimit = serverScoreLimit;
685 d->bSecure = bSecure;
693 void Server::setTestingServer(
bool b)
695 d->testingServer = b;
700 d->timeLeft = serverTimeLeft;
705 d->timeLimit = serverTimeLimit;
713 void Server::setWads(
const QList<PWad> &
wads)
727 case Player::TEAM_BLUE:
728 return qRgb(0, 0, 255);
729 case Player::TEAM_RED:
730 return qRgb(255, 0, 0);
731 case Player::TEAM_GREEN:
732 return qRgb(0, 255, 0);
733 case Player::TEAM_GOLD:
734 return qRgb(255, 255, 0);
737 return qRgb(0, 255, 0);
742 return team < MAX_TEAMS && team >= 0 ? teamNames[team] :
"";
757 if (d->lastRefreshClock.isValid())
759 return d->lastRefreshClock.elapsed();
779 return wads()[index];
794 QScopedPointer<ExeFile> exeFile(
clientExe());
816 void Server::setLan(
bool b)
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().
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
Message of the Day.
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.
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 erroneous.
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.
bool isSpecial() const
Special servers are custom servers or LAN servers.
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.
bool isTestingServer() const
Does this server run a testing version of the game?
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.
bool isLan() const
Does this server come from LAN.
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...