masterserver ( work in progress )
This commit is contained in:
parent
36c7ccfff1
commit
9fb3352dfe
|
@ -46,6 +46,7 @@ FontMenuVeryBigBaseSize=25
|
|||
FontSizeAdjustment=0
|
||||
Lang=english
|
||||
MaxLights=8
|
||||
Masterserver=http://soft-haus.com/glest/cgi-bin/
|
||||
NetPlayerName=unknown
|
||||
NetworkConsistencyChecks=true
|
||||
PhotoMode=false
|
||||
|
|
|
@ -23,8 +23,10 @@
|
|||
#include "conversion.h"
|
||||
#include "socket.h"
|
||||
#include "game.h"
|
||||
#include "util.h"
|
||||
#include <algorithm>
|
||||
#include <time.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
|
@ -51,7 +53,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||
Config &config = Config::getInstance();
|
||||
|
||||
needToSetChangedGameSettings = false;
|
||||
lastSetChangedGameSettings = time(NULL);;
|
||||
lastSetChangedGameSettings = time(NULL);
|
||||
lastMasterserverPublishing = time(NULL);
|
||||
|
||||
vector<string> teamItems, controlItems, results;
|
||||
|
||||
|
@ -112,6 +115,15 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||
listBoxTechTree.setItems(results);
|
||||
labelTechTree.init(700, 290);
|
||||
|
||||
|
||||
labelPublishServer.init(350, 90, 100);
|
||||
labelPublishServer.setText(lang.get("Publish Server"));
|
||||
listBoxPublishServer.init(350, 60, 100);
|
||||
listBoxPublishServer.pushBackItem(lang.get("Yes"));
|
||||
listBoxPublishServer.pushBackItem(lang.get("No"));
|
||||
listBoxPublishServer.setSelectedItemIndex(1);
|
||||
|
||||
|
||||
//list boxes
|
||||
for(int i=0; i<GameConstants::maxPlayers; ++i){
|
||||
labelPlayers[i].init(100, 550-i*30);
|
||||
|
@ -283,6 +295,9 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||
lastSetChangedGameSettings = time(NULL);;
|
||||
}
|
||||
}
|
||||
else if(listBoxPublishServer.mouseClick(x, y)&&listBoxPublishServer.getEditable()){
|
||||
soundRenderer.playFx(coreData.getClickSoundC());
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i=0; i<mapInfo.players; ++i)
|
||||
|
@ -357,6 +372,7 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){
|
|||
listBoxFogOfWar.mouseMove(x, y);
|
||||
listBoxTileset.mouseMove(x, y);
|
||||
listBoxTechTree.mouseMove(x, y);
|
||||
listBoxPublishServer.mouseMove(x, y);
|
||||
}
|
||||
|
||||
void MenuStateCustomGame::render(){
|
||||
|
@ -394,6 +410,11 @@ void MenuStateCustomGame::render(){
|
|||
|
||||
renderer.renderChatManager(&chatManager);
|
||||
renderer.renderConsole(&console);
|
||||
if(listBoxPublishServer.getEditable())
|
||||
{
|
||||
renderer.renderListBox(&listBoxPublishServer);
|
||||
renderer.renderLabel(&labelPublishServer);
|
||||
}
|
||||
}
|
||||
catch(const std::exception &ex) {
|
||||
char szBuf[1024]="";
|
||||
|
@ -411,6 +432,7 @@ void MenuStateCustomGame::update()
|
|||
Lang& lang= Lang::getInstance();
|
||||
|
||||
bool haveAtLeastOneNetworkClientConnected = false;
|
||||
bool hasOneNetworkSlotOpen = false;
|
||||
Config &config = Config::getInstance();
|
||||
|
||||
|
||||
|
@ -468,11 +490,11 @@ void MenuStateCustomGame::update()
|
|||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
||||
{
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START - ctNetwork\n",__FILE__,__FUNCTION__);
|
||||
|
||||
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
|
||||
|
||||
assert(connectionSlot!=NULL);
|
||||
|
||||
hasOneNetworkSlotOpen=true;
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__);
|
||||
|
||||
if(connectionSlot->isConnected())
|
||||
|
@ -574,6 +596,25 @@ void MenuStateCustomGame::update()
|
|||
needToSetChangedGameSettings = false;
|
||||
}
|
||||
|
||||
if(hasOneNetworkSlotOpen)
|
||||
{
|
||||
//listBoxPublishServer.setSelectedItemIndex(0);
|
||||
listBoxPublishServer.setEditable(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
listBoxPublishServer.setSelectedItemIndex(1);
|
||||
listBoxPublishServer.setEditable(false);
|
||||
}
|
||||
|
||||
if(listBoxPublishServer.getEditable() && listBoxPublishServer.getSelectedItemIndex()==0 && (difftime(time(NULL),lastMasterserverPublishing) >= 5) ){
|
||||
// give it to me baby, aha aha ...
|
||||
lastMasterserverPublishing = time(NULL);
|
||||
publishToMasterserver();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(difftime(time(NULL),lastSetChangedGameSettings) >= 2)
|
||||
{
|
||||
GameSettings gameSettings;
|
||||
|
@ -601,6 +642,73 @@ void MenuStateCustomGame::update()
|
|||
}
|
||||
}
|
||||
|
||||
void MenuStateCustomGame::publishToMasterserver()
|
||||
{
|
||||
int slotCountUsed=0;
|
||||
int slotCountHumans=0;
|
||||
int slotCountConnectedPlayers=0;
|
||||
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||
GameSettings gameSettings;
|
||||
loadGameSettings(&gameSettings);
|
||||
string serverinfo="";
|
||||
|
||||
for(int i= 0; i<mapInfo.players; ++i)
|
||||
{
|
||||
if(listBoxControls[i].getSelectedItemIndex() != ctClosed)
|
||||
{
|
||||
slotCountUsed++;
|
||||
}
|
||||
|
||||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
||||
{
|
||||
slotCountHumans++;
|
||||
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
|
||||
if((connectionSlot!=NULL) && (connectionSlot->isConnected()))
|
||||
{
|
||||
slotCountConnectedPlayers++;
|
||||
}
|
||||
}
|
||||
else if(listBoxControls[i].getSelectedItemIndex() == ctHuman)
|
||||
{
|
||||
slotCountHumans++;
|
||||
slotCountConnectedPlayers++;
|
||||
}
|
||||
}
|
||||
//?status=waiting&system=linux&info=titus
|
||||
serverinfo+="glestVersion="+escapeURL(glestVersionString)+"&";
|
||||
serverinfo+="platform=xxx&";
|
||||
serverinfo+="binaryCompileDate="+escapeURL(getCompileDateTime())+"&";
|
||||
|
||||
//game info:
|
||||
serverinfo+="serverTitle="+escapeURL(Config::getInstance().getString("NetPlayerName")+"'s game")+"&";
|
||||
//ip is automatically set
|
||||
|
||||
//game setup info:
|
||||
serverinfo+="tech="+escapeURL(listBoxTechTree.getSelectedItem())+"&";
|
||||
serverinfo+="map="+escapeURL(listBoxMap.getSelectedItem())+"&";
|
||||
serverinfo+="tileset="+escapeURL(listBoxTileset.getSelectedItem())+"&";
|
||||
serverinfo+="activeSlots="+intToStr(slotCountUsed)+"&";
|
||||
serverinfo+="networkSlots="+intToStr(slotCountHumans)+"&";
|
||||
serverinfo+="connectedClients="+intToStr(slotCountConnectedPlayers);
|
||||
|
||||
string request = Config::getInstance().getString("Masterserver")+"addServerInfo.php?"+serverinfo;
|
||||
printf("the request is:\n%s\n",request.c_str());
|
||||
|
||||
|
||||
std::string serverInfo = SystemFlags::getHTTP(request);
|
||||
|
||||
}
|
||||
|
||||
string MenuStateCustomGame::escapeURL(string in)
|
||||
{
|
||||
char *escaped=curl_easy_escape(SystemFlags::curl_handle,in.c_str(),0);
|
||||
if(escaped==NULL)
|
||||
abort();
|
||||
string out=escaped;
|
||||
curl_free(escaped);
|
||||
return out;
|
||||
}
|
||||
|
||||
void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings)
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2005 Martiño Figueroa
|
||||
// Copyright (C) 2001-2005 Marti<EFBFBD>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
|
@ -48,8 +48,12 @@ private:
|
|||
GraphicLabel labelNetStatus[GameConstants::maxPlayers];
|
||||
MapInfo mapInfo;
|
||||
|
||||
GraphicLabel labelPublishServer;
|
||||
GraphicListBox listBoxPublishServer;
|
||||
|
||||
bool needToSetChangedGameSettings;
|
||||
time_t lastSetChangedGameSettings;
|
||||
time_t lastMasterserverPublishing;
|
||||
|
||||
Console console;
|
||||
ChatManager chatManager;
|
||||
|
@ -74,6 +78,8 @@ private:
|
|||
void updateControlers();
|
||||
void closeUnusedSlots();
|
||||
void updateNetworkSlots();
|
||||
void publishToMasterserver();
|
||||
string escapeURL(string in);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -226,7 +226,7 @@ void MenuStateMasterserver::updateServerInfo() {
|
|||
//MasterServerInfos masterServerInfos;
|
||||
clearServerLines();
|
||||
|
||||
std::string serverInfo = SystemFlags::getHTTP("http://soft-haus.com/glest/cgi-bin/mega-glest-master-query.php");
|
||||
std::string serverInfo = SystemFlags::getHTTP(Config::getInstance().getString("Masterserver")+"showServersForGlest.php");
|
||||
|
||||
std::vector<std::string> serverList;
|
||||
Tokenize(serverInfo,serverList,"\n");
|
||||
|
|
Loading…
Reference in New Issue
Block a user