- updated Internet games to use 2 new fields, country and game status.

for now svn users can edit glestuser.ini and add the following entry (pointing to your folder of course) to see the country flags in game:
CountryTexturePath=/home/softcoder/Code/megaglest/trunk/source/masterserver/flags
This commit is contained in:
Mark Vejvoda 2011-01-25 07:41:12 +00:00
parent 4670935fd0
commit e06639c78d
15 changed files with 263 additions and 44 deletions

View File

@ -75,6 +75,13 @@ enum FactionPersonalityType {
fpt_EndCount fpt_EndCount
}; };
enum MasterServerGameStatusType {
game_status_waiting_for_players = 0,
game_status_waiting_for_start = 1,
game_status_in_progress = 2,
game_status_finished = 3
};
class GameConstants { class GameConstants {
public: public:
static const int specialFactions = fpt_EndCount - 1; static const int specialFactions = fpt_EndCount - 1;

View File

@ -1861,6 +1861,10 @@ void Renderer::renderSurface(const int renderFps) {
#if defined(ENABLE_VBO_CODE) #if defined(ENABLE_VBO_CODE)
int lastSurfaceDataIndex = -1;
std::vector<SurfaceData> surface;
//surface.reserve(qCache.visibleScaledCellList.size());
for(int visibleIndex = 0; for(int visibleIndex = 0;
visibleIndex < qCache.visibleScaledCellList.size(); ++visibleIndex) { visibleIndex < qCache.visibleScaledCellList.size(); ++visibleIndex) {
Vec2i &pos = qCache.visibleScaledCellList[visibleIndex]; Vec2i &pos = qCache.visibleScaledCellList[visibleIndex];
@ -1890,40 +1894,92 @@ void Renderer::renderSurface(const int renderFps) {
if(tc00->getSurfaceTexture() == NULL) { if(tc00->getSurfaceTexture() == NULL) {
throw runtime_error("tc00->getSurfaceTexture() == NULL"); throw runtime_error("tc00->getSurfaceTexture() == NULL");
} }
vector<VisibleQuadContainerVBOCache> &vboCache = GetSurfaceVBOs(pos);
int surfaceDataIndex = -1;
currTex= static_cast<const Texture2DGl*>(tc00->getSurfaceTexture())->getHandle(); currTex= static_cast<const Texture2DGl*>(tc00->getSurfaceTexture())->getHandle();
if(currTex != lastTex) { if(currTex != lastTex) {
lastTex = currTex; lastTex = currTex;
glBindTexture(GL_TEXTURE_2D, lastTex);
} }
else {
surfaceDataIndex = lastSurfaceDataIndex;
}
if(surfaceDataIndex < 0) {
SurfaceData newData;
newData.textureHandle = currTex;
surface.push_back(newData);
surfaceDataIndex = surface.size()-1;
//surface[surfaceDataIndex].texCoords.reserve(100);
//surface[surfaceDataIndex].texCoordsSurface.reserve(100);
//surface[surfaceDataIndex].vertices.reserve(100);
//surface[surfaceDataIndex].normals.reserve(100);
}
lastSurfaceDataIndex = surfaceDataIndex;
const Vec2f &surfCoord= tc00->getSurfTexCoord(); const Vec2f &surfCoord= tc00->getSurfTexCoord();
vector<VisibleQuadContainerVBOCache> &vboCache = GetSurfaceVBOs(pos); //int dataIndex = surface[surfaceDataIndex].texCoords.size();
surface[surfaceDataIndex].texCoords.push_back(tc01->getFowTexCoord());
surface[surfaceDataIndex].texCoordsSurface.push_back(Vec2f(surfCoord.x, surfCoord.y + coordStep));
surface[surfaceDataIndex].vertices.push_back(tc01->getVertex());
surface[surfaceDataIndex].normals.push_back(tc01->getNormal());
glBegin(GL_TRIANGLE_STRIP); surface[surfaceDataIndex].texCoords.push_back(tc00->getFowTexCoord());
surface[surfaceDataIndex].texCoordsSurface.push_back(Vec2f(surfCoord.x, surfCoord.y));
surface[surfaceDataIndex].vertices.push_back(tc00->getVertex());
surface[surfaceDataIndex].normals.push_back(tc00->getNormal());
assertGl(); surface[surfaceDataIndex].texCoords.push_back(tc11->getFowTexCoord());
surface[surfaceDataIndex].texCoordsSurface.push_back(Vec2f(surfCoord.x+coordStep, surfCoord.y+coordStep));
surface[surfaceDataIndex].vertices.push_back(tc11->getVertex());
surface[surfaceDataIndex].normals.push_back(tc11->getNormal());
//draw quad using immediate mode surface[surfaceDataIndex].texCoords.push_back(tc10->getFowTexCoord());
for(int i = 0; i < vboCache.size(); ++i) { surface[surfaceDataIndex].texCoordsSurface.push_back(Vec2f(surfCoord.x+coordStep, surfCoord.y));
surface[surfaceDataIndex].vertices.push_back(tc10->getVertex());
assertGl(); surface[surfaceDataIndex].normals.push_back(tc10->getNormal());
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache[i].m_nVBOFowTexCoords );
glMultiTexCoord2fv(fowTexUnit, 0);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache[i].m_nVBOSurfaceTexCoords );
glMultiTexCoord2fv(baseTexUnit, 0);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache[i].m_nVBONormals );
glNormal3fv(0);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboCache[i].m_nVBOVertices );
glVertex3fv(0);
assertGl();
} }
//printf("\nsurface.size() = %d vs qCache.visibleScaledCellList.size() = %d \n",surface.size(),qCache.visibleScaledCellList.size());
for(int i = 0; i < surface.size(); ++i) {
SurfaceData &data = surface[i];
Vec2f *texCoords = &data.texCoords[0];
Vec2f *texCoordsSurface = &data.texCoordsSurface[0];
Vec3f *vertices = &data.vertices[0];
Vec3f *normals = &data.normals[0];
glClientActiveTexture(fowTexUnit);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0,texCoords);
glBindTexture(GL_TEXTURE_2D, data.textureHandle);
glClientActiveTexture(baseTexUnit);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, texCoordsSurface);
assertGl();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
assertGl(); assertGl();
glEnd(); glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(GL_FLOAT, 0, normals);
glDrawArrays(GL_TRIANGLE_STRIP, 0, data.vertices.size());
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
//assertGl();
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
//assertGl();
} }
#else #else

View File

@ -1361,7 +1361,7 @@ void MenuStateCustomGame::render() {
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);!!! //throw runtime_error(szBuf);
showGeneralError=true; showGeneralError=true;
generalErrorToShow = ex.what(); generalErrorToShow = ex.what();
} }
@ -1842,6 +1842,11 @@ void MenuStateCustomGame::publishToMasterserver()
string externalport = config.getString("MasterServerExternalPort", "61357"); string externalport = config.getString("MasterServerExternalPort", "61357");
publishToServerInfo["externalconnectport"] = externalport; publishToServerInfo["externalconnectport"] = externalport;
publishToServerInfo["gameStatus"] = intToStr(game_status_waiting_for_players);
if(slotCountHumans <= slotCountConnectedPlayers) {
publishToServerInfo["gameStatus"] = intToStr(game_status_waiting_for_start);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
@ -1988,7 +1993,7 @@ void MenuStateCustomGame::simpleTask(BaseThread *callingThread) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
if(callingThread->getQuitStatus() == false) { if(callingThread->getQuitStatus() == false) {
//throw runtime_error(szBuf);!!! //throw runtime_error(szBuf);
showGeneralError=true; showGeneralError=true;
generalErrorToShow = ex.what(); generalErrorToShow = ex.what();
} }
@ -2631,7 +2636,7 @@ void MenuStateCustomGame::updateNetworkSlots() {
sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); sprintf(szBuf,"In [%s::%s %d] Error detected:\n%s\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);!!! //throw runtime_error(szBuf);
showGeneralError=true; showGeneralError=true;
generalErrorToShow = ex.what(); generalErrorToShow = ex.what();

View File

@ -149,13 +149,23 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
serverTitleLabel.init(i,startOffset-lineOffset); serverTitleLabel.init(i,startOffset-lineOffset);
serverTitleLabel.setText(lang.get("MGGameTitle")); serverTitleLabel.setText(lang.get("MGGameTitle"));
i+=200; i+=80;
countryLabel.registerGraphicComponent(containerName,"countryLabel");
countryLabel.init(i,startOffset-lineOffset);
countryLabel.setText(lang.get("MGGameCountry"));
i+=80;
statusLabel.registerGraphicComponent(containerName,"statusLabel");
statusLabel.init(i,startOffset-lineOffset);
statusLabel.setText(lang.get("MGGameStatus"));
i+=90;
ipAddressLabel.registerGraphicComponent(containerName,"ipAddressLabel"); ipAddressLabel.registerGraphicComponent(containerName,"ipAddressLabel");
ipAddressLabel.init(i,startOffset-lineOffset); ipAddressLabel.init(i,startOffset-lineOffset);
ipAddressLabel.setText(lang.get("MGGameIP")); ipAddressLabel.setText(lang.get("MGGameIP"));
//game setup info: //game setup info:
i+=120; i+=100;
techLabel.registerGraphicComponent(containerName,"techLabel"); techLabel.registerGraphicComponent(containerName,"techLabel");
techLabel.init(i,startOffset-lineOffset); techLabel.init(i,startOffset-lineOffset);
techLabel.setText(lang.get("TechTree")); techLabel.setText(lang.get("TechTree"));
@ -524,6 +534,8 @@ void MenuStateMasterserver::render(){
//game info: //game info:
renderer.renderLabel(&serverTitleLabel,&titleLabelColor); renderer.renderLabel(&serverTitleLabel,&titleLabelColor);
renderer.renderLabel(&countryLabel,&titleLabelColor);
renderer.renderLabel(&statusLabel,&titleLabelColor);
renderer.renderLabel(&ipAddressLabel,&titleLabelColor); renderer.renderLabel(&ipAddressLabel,&titleLabelColor);
//game setup info: //game setup info:
@ -820,6 +832,8 @@ void MenuStateMasterserver::rebuildServerLines(const string &serverInfo) {
Lang &lang= Lang::getInstance(); Lang &lang= Lang::getInstance();
try { try {
if(serverInfo != "") { if(serverInfo != "") {
//printf("--------------> serverInfo [%s]\n",serverInfo.c_str());
std::vector<std::string> serverList; std::vector<std::string> serverList;
Tokenize(serverInfo,serverList,"\n"); Tokenize(serverInfo,serverList,"\n");
for(int i=0; i < serverList.size(); i++) { for(int i=0; i < serverList.size(); i++) {
@ -827,7 +841,9 @@ void MenuStateMasterserver::rebuildServerLines(const string &serverInfo) {
std::vector<std::string> serverEntities; std::vector<std::string> serverEntities;
Tokenize(server,serverEntities,"|"); Tokenize(server,serverEntities,"|");
const int MIN_FIELDS_EXPECTED = 12; //printf("--------------> server [%s] serverEntities.size() = %d\n",server.c_str(),serverEntities.size());
const int MIN_FIELDS_EXPECTED = 14;
if(serverEntities.size() >= MIN_FIELDS_EXPECTED) { if(serverEntities.size() >= MIN_FIELDS_EXPECTED) {
labelTitle.setText(lang.get("AvailableServers")); labelTitle.setText(lang.get("AvailableServers"));
@ -854,6 +870,10 @@ void MenuStateMasterserver::rebuildServerLines(const string &serverInfo) {
masterServerInfo->setNetworkSlots(strToInt(serverEntities[9])); masterServerInfo->setNetworkSlots(strToInt(serverEntities[9]));
masterServerInfo->setConnectedClients(strToInt(serverEntities[10])); masterServerInfo->setConnectedClients(strToInt(serverEntities[10]));
masterServerInfo->setExternalConnectPort(strToInt(serverEntities[11])); masterServerInfo->setExternalConnectPort(strToInt(serverEntities[11]));
masterServerInfo->setCountry(serverEntities[12]);
masterServerInfo->setStatus(strToInt(serverEntities[13]));
//printf("--------------> Country [%s] Status [%d]\n",masterServerInfo->getCountry().c_str(),masterServerInfo->getStatus());
//printf("Getting Ping time for host %s\n",masterServerInfo->getIpAddress().c_str()); //printf("Getting Ping time for host %s\n",masterServerInfo->getIpAddress().c_str());
//float pingTime = Socket::getAveragePingMS(masterServerInfo->getIpAddress().c_str(),1); //float pingTime = Socket::getAveragePingMS(masterServerInfo->getIpAddress().c_str(),1);

View File

@ -52,6 +52,9 @@ private:
//game info: //game info:
GraphicLabel serverTitleLabel; GraphicLabel serverTitleLabel;
GraphicLabel countryLabel;
GraphicLabel statusLabel;
GraphicLabel ipAddressLabel; GraphicLabel ipAddressLabel;
//game setup info: //game setup info:

View File

@ -32,6 +32,7 @@ namespace Glest{ namespace Game{
ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY, int lineHeight, const char * containerName) { ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY, int lineHeight, const char * containerName) {
this->containerName = containerName; this->containerName = containerName;
this->countryTexture = NULL;
Lang &lang= Lang::getInstance(); Lang &lang= Lang::getInstance();
this->lineHeight=lineHeight; this->lineHeight=lineHeight;
@ -60,7 +61,36 @@ ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY,
serverTitleLabel.init(i,baseY-lineOffset); serverTitleLabel.init(i,baseY-lineOffset);
serverTitleLabel.setText(masterServerInfo.getServerTitle()); serverTitleLabel.setText(masterServerInfo.getServerTitle());
i+=200; i+=80;
country.init(i,baseY-lineOffset);
country.setText(masterServerInfo.getCountry());
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
string countryLogoPath = data_path + "data/core/misc_textures/";
Config &config = Config::getInstance();
if(config.getString("CountryTexturePath","") != "") {
countryLogoPath = config.getString("CountryTexturePath","");
}
if(fileExists(countryLogoPath + "/" + masterServerInfo.getCountry() + ".png") == true) {
countryTexture=GraphicsInterface::getInstance().getFactory()->newTexture2D();
//loadingTexture = renderer.newTexture2D(rsGlobal);
countryTexture->setMipmap(true);
//loadingTexture->getPixmap()->load(filepath);
countryTexture->load(countryLogoPath + "/" + masterServerInfo.getCountry() + ".png");
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer &renderer= Renderer::getInstance();
renderer.initTexture(rsGlobal,countryTexture);
}
i+=80;
status.init(i,baseY-lineOffset);
status.setText(lang.get("MGGameStatus" + intToStr(masterServerInfo.getStatus())));
i+=90;
ipAddressLabel.init(i,baseY-lineOffset); ipAddressLabel.init(i,baseY-lineOffset);
ipAddressLabel.setText(masterServerInfo.getIpAddress()); ipAddressLabel.setText(masterServerInfo.getIpAddress());
@ -69,7 +99,7 @@ ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY,
wrongVersionLabel.setText(lang.get("IncompatibleVersion")); wrongVersionLabel.setText(lang.get("IncompatibleVersion"));
//game setup info: //game setup info:
i+=120; i+=100;
techLabel.init(i,baseY-lineOffset); techLabel.init(i,baseY-lineOffset);
techLabel.setText(masterServerInfo.getTech()); techLabel.setText(masterServerInfo.getTech());
@ -107,6 +137,18 @@ ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY,
ServerLine::~ServerLine() { ServerLine::~ServerLine() {
//delete masterServerInfo; //delete masterServerInfo;
if(countryTexture != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
countryTexture->end();
delete countryTexture;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//delete loadingTexture;
countryTexture=NULL;
}
} }
bool ServerLine::buttonMouseClick(int x, int y){ bool ServerLine::buttonMouseClick(int x, int y){
@ -147,7 +189,15 @@ void ServerLine::render() {
//game info: //game info:
renderer.renderLabel(&serverTitleLabel); renderer.renderLabel(&serverTitleLabel);
if(!gameFull.getEnabled()){ if(countryTexture != NULL) {
renderer.renderTextureQuad(country.getX() + 20,country.getY(),countryTexture->getTextureWidth(),countryTexture->getTextureHeight(),countryTexture,0.7f);
}
else {
renderer.renderLabel(&country);
}
renderer.renderLabel(&status);
if(gameFull.getEnabled() == false) {
if (compatible) { if (compatible) {
renderer.renderLabel(&ipAddressLabel); renderer.renderLabel(&ipAddressLabel);
@ -176,6 +226,8 @@ void ServerLine::setY(int y) {
//game info: //game info:
serverTitleLabel.setY(y); serverTitleLabel.setY(y);
country.setY(y);
status.setY(y);
ipAddressLabel.setY(y); ipAddressLabel.setY(y);
//game setup info: //game setup info:

View File

@ -53,6 +53,11 @@ private:
GraphicLabel externalConnectPort; GraphicLabel externalConnectPort;
GraphicLabel country;
GraphicLabel status;
Texture2D *countryTexture;
const char * containerName; const char * containerName;
public: public:

View File

@ -13,6 +13,7 @@
#define _GLEST_GAME_MASTERSERVERINFO_H_ #define _GLEST_GAME_MASTERSERVERINFO_H_
#include <string> #include <string>
#include "game_constants.h"
#include "leak_dumper.h" #include "leak_dumper.h"
using std::string; using std::string;
@ -25,7 +26,7 @@ namespace Glest{ namespace Game{
/// A type of particle system /// A type of particle system
// =========================================================== // ===========================================================
class MasterServerInfo{ class MasterServerInfo {
protected: protected:
//general info: //general info:
string glestVersion; string glestVersion;
@ -44,6 +45,8 @@ protected:
int networkSlots; int networkSlots;
int connectedClients; int connectedClients;
int externalconnectport; int externalconnectport;
string country;
int status;
public: public:
const string &getGlestVersion() const {return glestVersion;} const string &getGlestVersion() const {return glestVersion;}
@ -60,7 +63,8 @@ public:
const int getNetworkSlots() const {return networkSlots;} const int getNetworkSlots() const {return networkSlots;}
const int getConnectedClients() const {return connectedClients;} const int getConnectedClients() const {return connectedClients;}
const int getExternalConnectPort() const {return externalconnectport;} const int getExternalConnectPort() const {return externalconnectport;}
const string &getCountry() const { return country;}
const int getStatus() const { return status;}
//general info: //general info:
@ -81,6 +85,8 @@ public:
void setNetworkSlots(int value) { networkSlots = value; } void setNetworkSlots(int value) { networkSlots = value; }
void setConnectedClients(int value) { connectedClients = value; } void setConnectedClients(int value) { connectedClients = value; }
void setExternalConnectPort(int value) { externalconnectport = value; } void setExternalConnectPort(int value) { externalconnectport = value; }
void setCountry(string value) { country = value; }
void setStatus(int value) { status = value; }
}; };
}}//end namespace }}//end namespace

View File

@ -1408,7 +1408,7 @@ std::map<string,string> ServerInterface::publishToMasterserver() {
publishToServerInfo["glestVersion"] = glestVersionString; publishToServerInfo["glestVersion"] = glestVersionString;
publishToServerInfo["platform"] = getPlatformNameString(); publishToServerInfo["platform"] = getPlatformNameString();
publishToServerInfo["binaryCompileDate"] = getCompileDateTime(); publishToServerInfo["binaryCompileDate"] = getCompileDateTime();
publishToServerInfo["serverTitle"] = getHumanPlayerName() + "'s game *IN PROGRESS*"; publishToServerInfo["serverTitle"] = getHumanPlayerName() + "'s game";
publishToServerInfo["tech"] = this->getGameSettings()->getTech(); publishToServerInfo["tech"] = this->getGameSettings()->getTech();
publishToServerInfo["map"] = this->getGameSettings()->getMap(); publishToServerInfo["map"] = this->getGameSettings()->getMap();
publishToServerInfo["tileset"] = this->getGameSettings()->getTileset(); publishToServerInfo["tileset"] = this->getGameSettings()->getTileset();
@ -1417,9 +1417,11 @@ std::map<string,string> ServerInterface::publishToMasterserver() {
publishToServerInfo["connectedClients"] = intToStr(slotCountConnectedPlayers); publishToServerInfo["connectedClients"] = intToStr(slotCountConnectedPlayers);
string externalport = config.getString("MasterServerExternalPort", "61357"); string externalport = config.getString("MasterServerExternalPort", "61357");
publishToServerInfo["externalconnectport"] = externalport; publishToServerInfo["externalconnectport"] = externalport;
publishToServerInfo["gameStatus"] = intToStr(game_status_in_progress);
if(publishToMasterserverThread == NULL) { if(publishToMasterserverThread == NULL) {
publishToServerInfo["serverTitle"] = getHumanPlayerName() + "'s game *FINISHED*";
publishToServerInfo["gameCmd"]= "gameOver"; publishToServerInfo["gameCmd"]= "gameOver";
publishToServerInfo["gameStatus"] = intToStr(game_status_finished);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
return publishToServerInfo; return publishToServerInfo;

View File

@ -45,10 +45,15 @@
$networkSlots = (int) clean_str( $_GET['networkSlots'] ); $networkSlots = (int) clean_str( $_GET['networkSlots'] );
$connectedClients = (int) clean_str( $_GET['connectedClients'] ); $connectedClients = (int) clean_str( $_GET['connectedClients'] );
$status = 0;
if(isset($_GET["gameStatus"])) {
$status = (int) clean_str( $_GET['gameStatus'] );
}
$gameCmd = ""; $gameCmd = "";
if(isset($_GET["gameCmd"])) { if(isset($_GET["gameCmd"])) {
$gameCmd = (string) clean_str( $_GET['gameCmd'] ); $gameCmd = (string) clean_str( $_GET['gameCmd'] );
} }
define( 'DB_LINK', db_connect() ); define( 'DB_LINK', db_connect() );
@ -81,6 +86,7 @@
'networkSlots=\'' . mysql_real_escape_string( $networkSlots ) . '\', ' . 'networkSlots=\'' . mysql_real_escape_string( $networkSlots ) . '\', ' .
'connectedClients=\'' . mysql_real_escape_string( $connectedClients ) . '\', ' . 'connectedClients=\'' . mysql_real_escape_string( $connectedClients ) . '\', ' .
'externalServerPort=\''. mysql_real_escape_string( $service_port ) . '\', ' . 'externalServerPort=\''. mysql_real_escape_string( $service_port ) . '\', ' .
'status=\'' . mysql_real_escape_string( $status ) . '\', ' .
'lasttime=' . 'now()' . ' ' . 'lasttime=' . 'now()' . ' ' .
'where ip=\'' . mysql_real_escape_string( $remote_ip ) . '\' && externalServerPort=\'' . mysql_real_escape_string( $service_port ) . '\';' ); 'where ip=\'' . mysql_real_escape_string( $remote_ip ) . '\' && externalServerPort=\'' . mysql_real_escape_string( $service_port ) . '\';' );
updateServer($remote_ip, $service_port, $serverTitle, $connectedClients, $networkSlots); updateServer($remote_ip, $service_port, $serverTitle, $connectedClients, $networkSlots);
@ -181,7 +187,8 @@
'networkSlots=\'' . mysql_real_escape_string( $networkSlots ) . '\', ' . 'networkSlots=\'' . mysql_real_escape_string( $networkSlots ) . '\', ' .
'connectedClients=\'' . mysql_real_escape_string( $connectedClients ) . '\', ' . 'connectedClients=\'' . mysql_real_escape_string( $connectedClients ) . '\', ' .
'externalServerPort=\''. mysql_real_escape_string( $service_port ) . '\', ' . 'externalServerPort=\''. mysql_real_escape_string( $service_port ) . '\', ' .
'country=\'' . mysql_real_escape_string( $country ) . '\';' 'country=\'' . mysql_real_escape_string( $country ) . '\', ' .
'status=\'' . mysql_real_escape_string( $status ) . '\';'
); );
echo 'OK'; echo 'OK';
addLatestServer($remote_ip, $service_port, $serverTitle, $connectedClients, $networkSlots); addLatestServer($remote_ip, $service_port, $serverTitle, $connectedClients, $networkSlots);

View File

@ -12,4 +12,5 @@
define( 'MYSQL_LINK_PERSIST', false ); define( 'MYSQL_LINK_PERSIST', false );
// How many recently seen servers to store // How many recently seen servers to store
define( 'MAX_RECENT_SERVERS', 5 ); define( 'MAX_RECENT_SERVERS', 5 );
define( 'DEFAULT_COUNTRY', '?' );
?> ?>

View File

@ -21,6 +21,7 @@ CREATE TABLE IF NOT EXISTS `glestserver` (
`connectedClients` int(11) NOT NULL, `connectedClients` int(11) NOT NULL,
`externalServerPort` int(11) NOT NULL, `externalServerPort` int(11) NOT NULL,
`country` varchar(2) collate utf8_unicode_ci NOT NULL, `country` varchar(2) collate utf8_unicode_ci NOT NULL,
`status` int(11) NOT NULL default 0, -- valid statuses: 0 waiting for players, 1 = game full pending start, 2 game in progress, 3 game over
KEY `lasttime` (`lasttime`) KEY `lasttime` (`lasttime`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

View File

@ -59,6 +59,7 @@ echo <<<END
<th>connectedClients</th> <th>connectedClients</th>
<th>externalServerPort</th> <th>externalServerPort</th>
<th>country</th> <th>country</th>
<th>status</th>
</tr> </tr>
END; END;
@ -87,6 +88,38 @@ END;
echo "\t\t\t\t<td>" . 'unknown' . '</td>' . PHP_EOL; echo "\t\t\t\t<td>" . 'unknown' . '</td>' . PHP_EOL;
} }
} }
else {
echo "\t\t\t\t<td>" . htmlspecialchars( $server['country'], ENT_QUOTES ) . '</td>' . PHP_EOL;
}
$calculatedStatus = $server['status'];
if($calculatedStatus == 0)
{
$gameFull = ($server['networkSlots'] <= $server['connectedClients']);
if($gameFull == true)
{
$calculatedStatus = 1;
}
}
switch($calculatedStatus)
{
case 0:
echo "\t\t\t\t<td>" . htmlspecialchars( "waiting for players", ENT_QUOTES ) . '</td>' . PHP_EOL;
break;
case 1:
echo "\t\t\t\t<td>" . htmlspecialchars( "game full, pending start", ENT_QUOTES ) . '</td>' . PHP_EOL;
break;
case 2:
echo "\t\t\t\t<td>" . htmlspecialchars( "in progress", ENT_QUOTES ) . '</td>' . PHP_EOL;
break;
case 3:
echo "\t\t\t\t<td>" . htmlspecialchars( "finished", ENT_QUOTES ) . '</td>' . PHP_EOL;
break;
default:
echo "\t\t\t\t<td>" . htmlspecialchars( "unknown: " . $server['status'], ENT_QUOTES ) . '</td>' . PHP_EOL;
}
echo "\t\t\t" . '</tr>' . PHP_EOL; echo "\t\t\t" . '</tr>' . PHP_EOL;
} }
unset( $all_servers ); unset( $all_servers );

View File

@ -23,9 +23,30 @@
header( 'Content-Type: text/plain; charset=utf-8' ); header( 'Content-Type: text/plain; charset=utf-8' );
foreach( $all_servers as &$server ) foreach( $all_servers as &$server )
{ {
echo ( $outString =
"${server['glestVersion']}|${server['platform']}|${server['binaryCompileDate']}|${server['serverTitle']}|${server['ip']}|${server['tech']}|${server['map']}|${server['tileset']}|${server['activeSlots']}|${server['networkSlots']}|${server['connectedClients']}|${server['externalServerPort']}|\n" "${server['glestVersion']}|${server['platform']}|${server['binaryCompileDate']}|${server['serverTitle']}|${server['ip']}|${server['tech']}|${server['map']}|${server['tileset']}|${server['activeSlots']}|${server['networkSlots']}|${server['connectedClients']}|${server['externalServerPort']}|";
);
if ( $server['country'] !== '' )
{
$outString = $outString . "${server['country']}|";
}
else
{
$outString = $outString . DEFAULT_COUNTRY . "|";
}
$calculatedStatus = $server['status'];
if($calculatedStatus == 0)
{
$gameFull = ($server['networkSlots'] <= $server['connectedClients']);
if($gameFull == true)
{
$outString = $outString . "1|\n";
}
}
$outString = $outString . "$calculatedStatus|\n";
echo ($outString);
} }
unset( $all_servers ); unset( $all_servers );
unset( $server ); unset( $server );