diff --git a/mk/linux/glest.ini b/mk/linux/glest.ini index 0c0c94427..4ebd94028 100644 --- a/mk/linux/glest.ini +++ b/mk/linux/glest.ini @@ -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 diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index bd3e29e0e..b09223759 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -23,8 +23,10 @@ #include "conversion.h" #include "socket.h" #include "game.h" +#include "util.h" #include #include +#include #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 teamItems, controlItems, results; @@ -81,7 +84,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b listBoxMap.setItems(results); labelMap.init(100, 290); labelMapInfo.init(100, 230, 200, 40); - + // fog - o - war // @350 ? 300 ? labelFogOfWar.init(350, 290, 100); @@ -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; igetSlot(i); - assert(connectionSlot!=NULL); + + hasOneNetworkSlotOpen=true; //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__); @@ -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; igetSlot(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__); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 756e64cfd..22ae6fae0 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -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�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -47,9 +47,13 @@ private: GraphicListBox listBoxTeams[GameConstants::maxPlayers]; 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 diff --git a/source/glest_game/menu/menu_state_masterserver.cpp b/source/glest_game/menu/menu_state_masterserver.cpp index 7a602c643..dc8ad52ef 100644 --- a/source/glest_game/menu/menu_state_masterserver.cpp +++ b/source/glest_game/menu/menu_state_masterserver.cpp @@ -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 serverList; Tokenize(serverInfo,serverList,"\n");