[Orxonox-commit 5953] r10612 - in code/branches/presentationFS15merge: . data/gui/scripts src/libraries/network src/libraries/network/packet
landauf at orxonox.net
landauf at orxonox.net
Sun Oct 4 12:13:43 CEST 2015
Author: landauf
Date: 2015-10-04 12:13:42 +0200 (Sun, 04 Oct 2015)
New Revision: 10612
Modified:
code/branches/presentationFS15merge/
code/branches/presentationFS15merge/data/gui/scripts/MultiplayerMenu.lua
code/branches/presentationFS15merge/src/libraries/network/GamestateManager.h
code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.cc
code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.h
code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.cc
code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.h
code/branches/presentationFS15merge/src/libraries/network/MasterServer.cc
code/branches/presentationFS15merge/src/libraries/network/MasterServer.h
code/branches/presentationFS15merge/src/libraries/network/MasterServerProtocol.h
code/branches/presentationFS15merge/src/libraries/network/PeerList.cc
code/branches/presentationFS15merge/src/libraries/network/PeerList.h
code/branches/presentationFS15merge/src/libraries/network/Server.cc
code/branches/presentationFS15merge/src/libraries/network/Server.h
code/branches/presentationFS15merge/src/libraries/network/ServerList.cc
code/branches/presentationFS15merge/src/libraries/network/ServerList.h
code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.cc
code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.h
code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.cc
code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.h
code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.cc
code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.h
Log:
merged branch multiplayerFS15
Property changes on: code/branches/presentationFS15merge
___________________________________________________________________
Modified: svn:mergeinfo
- /code/branches/Racingbot:9388-9513
/code/branches/ScriptableController:9999-10075
/code/branches/ai:6592-7033
/code/branches/ai2:8721-8880
/code/branches/bigships:8137-8588
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/clangenb:10385-10609
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/core6:9552-9666
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dockingsystem:8101-8192
/code/branches/dockingsystem2:8196-8560
/code/branches/dynamicmatch:6584-7030
/code/branches/environment3:8887-8975
/code/branches/formation:8885-8991
/code/branches/formationFS15:10320-10610
/code/branches/formationupdate:9580-9624
/code/branches/fps:6591-7072
/code/branches/gamecontent:8893-8968
/code/branches/gameimmersion:8102-8577
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hud:8883-8986
/code/branches/hudHS14:10083-10241
/code/branches/hudelements:6584-6941
/code/branches/hudimprovements:7920-8672
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/invaders:9694-9896
/code/branches/ipv6:7293-7458
/code/branches/keckslevelHS14:10082-10222
/code/branches/kicklib:7940-8096,8098-8277
/code/branches/kicklib2:8282-8350
/code/branches/largeShip1:9384-9515
/code/branches/lastmanstanding:7479-7644
/code/branches/lastmanstanding3:7903-8175
/code/branches/levelElias:9697-9921
/code/branches/levelKaan:9695-9921
/code/branches/levelMichael:9696-9921
/code/branches/leveljoemeHS14:10087-10223
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/libs:9668-9674
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/mac_osx:7789-8128,8135
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/masterserverfix:8933-8936
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/menue:8884-8976
/code/branches/minigame4DHS14:10081-10230
/code/branches/miniprojects:2754-2824
/code/branches/modularships:9994-10071
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network6:7823-8315
/code/branches/network64:2210-2355
/code/branches/newlevel2012:9033-9244
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/ois_update:7506-7788
/code/branches/output:8739-8857
/code/branches/overlay:2117-2385
/code/branches/pCuts:9023-9284
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup:8145-8555
/code/branches/pickup2:5942-6405
/code/branches/pickup2012:9029-9189
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/pickupsFS14:10000-10259
/code/branches/png2:7262-7263
/code/branches/portals:8087-8455
/code/branches/portals2:8460-8602
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786,8500-8705
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation2011:8974-9015
/code/branches/presentation2012:9189-9268
/code/branches/presentation2012merge:9266-9347
/code/branches/presentation3:6913-7162
/code/branches/presentationFS14:10069-10215
/code/branches/presentationHS12:9481-9525
/code/branches/presentationHS13:9891-9938
/code/branches/presentationHS14merge:10222-10257
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/radarDreiD:9690-9901
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/sfxThilo:9691-9917
/code/branches/shipSelection:9038-9206
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound2012:9205-9214
/code/branches/sound3:5941-6102
/code/branches/spaceNavigation:9381-9497
/code/branches/spaceboundaries:8085-8457
/code/branches/spaceboundaries2:8460-8613
/code/branches/spacerace:8182-8630
/code/branches/spaceraceTwo:8881-8996
/code/branches/spacestationentry:9699-9905
/code/branches/steering:5949-6091,8140-8595
/code/branches/storymodeHS14:10085-10254
/code/branches/surfaceRace:9028-9199
/code/branches/surfaceraceHS14:10080-10236
/code/branches/testing:9015-9549
/code/branches/tetris:8100-8563
/code/branches/towerdefenseHS14:10086-10247
/code/branches/turret:9380-9501
/code/branches/turretFS14:9998-10070
/code/branches/tutoriallevel:7827-8370
/code/branches/tutoriallevel2:8370-8452
/code/branches/tutoriallevel3:8453-8636
/code/branches/unity_build:8440-8716
/code/branches/usability:7915-8078
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051,8143-8591
/code/branches/weaponsystem:2742-2890
/code/branches/weaponupdateHS14:10084-10237
+ /code/branches/Racingbot:9388-9513
/code/branches/ScriptableController:9999-10075
/code/branches/ai:6592-7033
/code/branches/ai2:8721-8880
/code/branches/bigships:8137-8588
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/clangenb:10385-10609
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/core6:9552-9666
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dockingsystem:8101-8192
/code/branches/dockingsystem2:8196-8560
/code/branches/dynamicmatch:6584-7030
/code/branches/environment3:8887-8975
/code/branches/formation:8885-8991
/code/branches/formationFS15:10320-10610
/code/branches/formationupdate:9580-9624
/code/branches/fps:6591-7072
/code/branches/gamecontent:8893-8968
/code/branches/gameimmersion:8102-8577
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hud:8883-8986
/code/branches/hudHS14:10083-10241
/code/branches/hudelements:6584-6941
/code/branches/hudimprovements:7920-8672
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/invaders:9694-9896
/code/branches/ipv6:7293-7458
/code/branches/keckslevelHS14:10082-10222
/code/branches/kicklib:7940-8096,8098-8277
/code/branches/kicklib2:8282-8350
/code/branches/largeShip1:9384-9515
/code/branches/lastmanstanding:7479-7644
/code/branches/lastmanstanding3:7903-8175
/code/branches/levelElias:9697-9921
/code/branches/levelKaan:9695-9921
/code/branches/levelMichael:9696-9921
/code/branches/leveljoemeHS14:10087-10223
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/libs:9668-9674
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/mac_osx:7789-8128,8135
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/masterserverfix:8933-8936
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/menue:8884-8976
/code/branches/minigame4DHS14:10081-10230
/code/branches/miniprojects:2754-2824
/code/branches/modularships:9994-10071
/code/branches/multiplayerFS15:10324-10611
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network6:7823-8315
/code/branches/network64:2210-2355
/code/branches/newlevel2012:9033-9244
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/ois_update:7506-7788
/code/branches/output:8739-8857
/code/branches/overlay:2117-2385
/code/branches/pCuts:9023-9284
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup:8145-8555
/code/branches/pickup2:5942-6405
/code/branches/pickup2012:9029-9189
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/pickupsFS14:10000-10259
/code/branches/png2:7262-7263
/code/branches/portals:8087-8455
/code/branches/portals2:8460-8602
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786,8500-8705
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation2011:8974-9015
/code/branches/presentation2012:9189-9268
/code/branches/presentation2012merge:9266-9347
/code/branches/presentation3:6913-7162
/code/branches/presentationFS14:10069-10215
/code/branches/presentationHS12:9481-9525
/code/branches/presentationHS13:9891-9938
/code/branches/presentationHS14merge:10222-10257
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/radarDreiD:9690-9901
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/sfxThilo:9691-9917
/code/branches/shipSelection:9038-9206
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound2012:9205-9214
/code/branches/sound3:5941-6102
/code/branches/spaceNavigation:9381-9497
/code/branches/spaceboundaries:8085-8457
/code/branches/spaceboundaries2:8460-8613
/code/branches/spacerace:8182-8630
/code/branches/spaceraceTwo:8881-8996
/code/branches/spacestationentry:9699-9905
/code/branches/steering:5949-6091,8140-8595
/code/branches/storymodeHS14:10085-10254
/code/branches/surfaceRace:9028-9199
/code/branches/surfaceraceHS14:10080-10236
/code/branches/testing:9015-9549
/code/branches/tetris:8100-8563
/code/branches/towerdefenseHS14:10086-10247
/code/branches/turret:9380-9501
/code/branches/turretFS14:9998-10070
/code/branches/tutoriallevel:7827-8370
/code/branches/tutoriallevel2:8370-8452
/code/branches/tutoriallevel3:8453-8636
/code/branches/unity_build:8440-8716
/code/branches/usability:7915-8078
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051,8143-8591
/code/branches/weaponsystem:2742-2890
/code/branches/weaponupdateHS14:10084-10237
Modified: code/branches/presentationFS15merge/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/presentationFS15merge/data/gui/scripts/MultiplayerMenu.lua 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/data/gui/scripts/MultiplayerMenu.lua 2015-10-04 10:13:42 UTC (rev 10612)
@@ -69,7 +69,7 @@
local destination = nil
if choice then
local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
- destination = P.serverList[index][2]
+ destination = P.serverList[index][1]
else
return
end
@@ -92,6 +92,8 @@
local index = 0
local servername = ""
local serverip = ""
+ local serverrtt = ""
+ local playernumber = ""
while true do
servername = discovery:getServerListItemName(index)
if servername == "" then
@@ -101,12 +103,15 @@
if serverip == "" then
break
end
- table.insert(P.serverList, {servername, serverip})
+ --serverrtt = discovery:getServerListItemRTT(index)
+ playernumber = discovery:getServerListItemPlayerNumber(index)
+
+ table.insert(P.serverList, {serverip, servername, playernumber})
index = index + 1
end
index = 1
for k,v in pairs(P.serverList) do
- local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
+ local item = CEGUI.createListboxTextItem("IP: " .. v[1] .. " Name: " .. v[2] .. " Players: " .. v[3])
item:setID(index)
index = index + 1
item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
@@ -124,6 +129,8 @@
local index = 0
local servername = ""
local serverip = ""
+ local serverrtt = ""
+ local playernumber = ""
while true do
servername = discovery:getServerListItemName(index)
if servername == "" then
@@ -133,12 +140,15 @@
if serverip == "" then
break
end
- table.insert(P.serverList, {servername, serverip})
+ --serverrtt = discovery:getServerListItemRTT(index)
+ playernumber = discovery:getServerListItemPlayerNumber(index)
+
+ table.insert(P.serverList, {serverip, servername, playernumber})
index = index + 1
end
index = 1
for k,v in pairs(P.serverList) do
- local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
+ local item = CEGUI.createListboxTextItem("IP: " .. v[1] .. " Name: " .. v[2] .. " Players: " .. v[3])
item:setID(index)
index = index + 1
item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
@@ -149,4 +159,3 @@
end
return P
-
Modified: code/branches/presentationFS15merge/src/libraries/network/GamestateManager.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/GamestateManager.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/GamestateManager.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -1,4 +1,4 @@
-/*
+ /*
* ORXONOX - the hottest 3D action shooter ever to exist
* > www.orxonox.net <
*
@@ -77,9 +77,9 @@
bool isSynched;
std::map< uint32_t, packet::Gamestate* > gamestates;
};
-
+
public:
-
+
GamestateManager();
~GamestateManager();
@@ -87,7 +87,7 @@
virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID);
virtual uint32_t getLastReceivedGamestateID( unsigned int peerID );
virtual uint32_t getCurrentGamestateID(){ if( currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; }
-
+
bool processGamestates();
bool sendAck(unsigned int gamestateID, uint32_t peerID);
bool update();
Modified: code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.cc
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.cc 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.cc 2015-10-04 10:13:42 UTC (rev 10612)
@@ -34,7 +34,10 @@
#include "util/Output.h"
#include "packet/ServerInformation.h"
+#include "core/config/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+
namespace orxonox
{
const char* LAN_DISCOVERY_MESSAGE = "Orxonox Client";
@@ -42,11 +45,23 @@
LANDiscoverable::LANDiscoverable()
{
+ /* register object in orxonox */
+ RegisterObject(LANDiscoverable);
+
+ this->setConfigValues();
+ // this->setActivity(true);
this->host_ = 0;
this->bActive_ = false;
-// this->setActivity(true);
}
+ void LANDiscoverable::setConfigValues()
+ {
+ /* update ownName string from orxonox.ini config file, if it
+ * has changed.
+ */
+ SetConfigValueExternal(ownName, "Discovery", "ownName", "OrxServer");
+ }
+
LANDiscoverable::~LANDiscoverable()
{
if( this->host_ )
@@ -60,7 +75,7 @@
{
if( bActive == this->bActive_ ) // no change
return;
-
+
if( bActive )
{
ENetAddress bindAddress;
@@ -83,11 +98,11 @@
void LANDiscoverable::update()
{
ENetEvent event;
-
+
if( this->bActive_==false )
return;
assert(this->host_);
-
+
while( enet_host_service( this->host_, &event, 0 ) > 0 )
{
switch(event.type)
@@ -103,7 +118,8 @@
{
orxout(internal_info, context::network) << "Received LAN discovery message from client " << event.peer->host->receivedAddress << endl;
packet::ServerInformation info;
- info.setServerName("Orxonox Server");
+ info.setServerName(this->ownName);
+ info.setClientNumber(this->clientNumber);
info.send(event.peer);
// ENetPacket* packet = enet_packet_create( LAN_DISCOVERY_ACK, strlen(LAN_DISCOVERY_ACK)+1, ENET_PACKET_FLAG_RELIABLE );
// enet_peer_send(event.peer, 0, packet );
Modified: code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/LANDiscoverable.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -30,21 +30,28 @@
#define _LANDISCOVERABLE_H__
#include "NetworkPrereqs.h"
+#include "core/config/Configurable.h"
namespace orxonox
{
- class LANDiscoverable
+ class LANDiscoverable: public Configurable
{
public:
LANDiscoverable();
virtual ~LANDiscoverable();
void setActivity( bool bActive );
void update();
+ void updateClientNumber(int clientNumber) {this->clientNumber = clientNumber;}
+;
+ /** Function used for the configuration file parameter update */
+ void setConfigValues();
private:
bool bActive_;
ENetHost* host_;
+ std::string ownName;
+ int clientNumber;
};
}
Modified: code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.cc
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.cc 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.cc 2015-10-04 10:13:42 UTC (rev 10612)
@@ -88,7 +88,10 @@
case ENET_EVENT_TYPE_RECEIVE:
{
packet::ServerInformation info(&event);
- orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", RTT: " << info.getServerRTT() << endl;
+ std::string payload = info.getServerName();
+ info.setServerName(payload.substr(0,payload.length()-2));
+ info.setClientNumber( Ogre::StringConverter::parseInt(payload.substr(payload.length()-1)));
+ orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", Players: " << info.getClientNumber() << ", RTT: " << info.getServerRTT() << endl;
std::vector<packet::ServerInformation>::iterator it;
for( it=this->servers_.begin(); it!=this->servers_.end(); ++it )
{
@@ -123,5 +126,23 @@
return this->servers_[index].getServerIP();
}
+ std::string LANDiscovery::getServerListItemRTT(unsigned int index)
+ {
+ if( index >= this->servers_.size() )
+ return BLANKSTRING;
+ else{
+ uint32_t serverrtt = this->servers_[index].getServerRTT();
+ return Ogre::StringConverter::toString(serverrtt);
+ }
+ }
+ std::string LANDiscovery::getServerListItemPlayerNumber(unsigned int index)
+ {
+ if( index >= this->servers_.size() )
+ return BLANKSTRING;
+ else{
+ int playerNumber = this->servers_[index].getClientNumber();
+ return Ogre::StringConverter::toString(playerNumber);
+ }
+ }
} // namespace orxonox
Modified: code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/LANDiscovery.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -32,6 +32,7 @@
#include "NetworkPrereqs.h"
#include "packet/ServerInformation.h"
#include "util/Singleton.h"
+#include <OgreStringConverter.h>
#include <vector>
@@ -50,8 +51,10 @@
void discover(); // tolua_export
std::string getServerListItemName( unsigned int index ); // tolua_export
std::string getServerListItemIP( unsigned int index ); // tolua_export
+ std::string getServerListItemRTT( unsigned int index ); // tolua_export
+ std::string getServerListItemPlayerNumber( unsigned int index ); // tolua_export
static LANDiscovery& getInstance(){ return Singleton<LANDiscovery>::getInstance(); } // tolua_export
-
+
private:
static LANDiscovery* singletonPtr_s;
ENetHost* host_;
Modified: code/branches/presentationFS15merge/src/libraries/network/MasterServer.cc
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/MasterServer.cc 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/MasterServer.cc 2015-10-04 10:13:42 UTC (rev 10612)
@@ -33,7 +33,7 @@
#include "core/CorePrereqs.h"
#include "util/Output.h"
-namespace orxonox
+namespace orxonox
{
/*** MACROS ***/
/* commands for the terminal interface */
@@ -44,11 +44,8 @@
/* forward declaration so the linker doesn't complain */
MasterServer *MasterServer::instance = NULL;
-
-
-
/* command: list servers */
- void
+ void
MasterServer::listServers( void )
{
/* get an iterator */
@@ -58,8 +55,8 @@
orxout(user_info) << "List of connected servers" << std::endl;
/* loop through list elements */
- for( i = MasterServer::getInstance()->mainlist.serverlist.begin();
- i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i )
+ for( i = MasterServer::getInstance()->mainlist.serverlist.begin();
+ i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i )
{
orxout(user_info) << " " << (*i).ServerInfo.getServerIP() << std::endl;
}
@@ -69,15 +66,15 @@
" servers connected." << std::endl;
}
- void
+ void
MasterServer::delServer( std::string todeladdr )
{
/* tell the user we're now removing the entry from the server list */
- orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..."
+ orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..."
<< std::endl;
/* see if we actually have that server on our list */
- ServerListSearchResult shandle =
+ ServerListSearchResult shandle =
MasterServer::getInstance()->mainlist.findServerByAddress(todeladdr);
if( !shandle.success )
@@ -85,7 +82,7 @@
return;
}
- /* force-disconnect the server */
+ /* force-disconnect the server */
enet_peer_disconnect( shandle.result.peer, 0 );
/* actually remove the entry from the server list by address */
@@ -97,16 +94,16 @@
/* helpers */
- static void
+ static void
helper_output_debug( ENetEvent *event, char *addrconv )
{
orxout(verbose, context::master_server)
- << "A packet of length"
+ << "A packet of length"
<< event->packet->dataLength
<< " containing "
<< (const char*)event->packet->data
<< " was received from "
- << addrconv
+ << addrconv
<< " on channel "
<< event->channelID << endl;
}
@@ -121,23 +118,23 @@
ENetPacket *reply;
/* loop through list elements */
- for( i = mainlist.serverlist.begin(); i
- != mainlist.serverlist.end(); ++i )
+ for( i = mainlist.serverlist.begin(); i
+ != mainlist.serverlist.end(); ++i )
{
/* send this particular server */
/* build reply string */
- char *tosend = (char *)calloc( (*i).ServerInfo.getServerIP().length()
- + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
- if( !tosend )
+ int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1 + sizeof((*i).ServerInfo.getClientNumber()) + 1;
+ char *tosend = (char *)calloc(packetlen ,1 );
+ if( !tosend )
{ orxout(internal_warning, context::master_server) << "Masterserver.cc: Memory allocation failed." << endl;
continue;
- }
- sprintf( tosend, "%s %s", MSPROTO_SERVERLIST_ITEM,
- (*i).ServerInfo.getServerIP().c_str() );
+ }
+ sprintf( tosend, "%s %s %s %u", MSPROTO_SERVERLIST_ITEM,
+ (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str(), (*i).ServerInfo.getClientNumber());
/* create packet from it */
reply = enet_packet_create( tosend,
- strlen( tosend ) + 1,
+ strlen( tosend ) + 1,
ENET_PACKET_FLAG_RELIABLE);
/* Send the reply to the peer over channel id 0. */
@@ -148,7 +145,7 @@
/* free the tosend buffer */
free( tosend );
- }
+ }
/* create end-of-list packet */
reply = enet_packet_create( MSPROTO_SERVERLIST_END,
@@ -162,40 +159,40 @@
enet_host_flush( this->server );
}
- /* maybe the two methods below can be merged into one and
- * made to use ENet's RTT functionality to check for disconnected
+ /* maybe the two methods below can be merged into one and
+ * made to use ENet's RTT functionality to check for disconnected
* servers.
*/
- void
+ void
MasterServer::helper_cleanupServers( void )
{
/* get an iterator */
std::list<ServerListElem>::iterator i;
-
+
if( mainlist.serverlist.size() == 0 )
return;
/* loop through list elements */
- for( i = mainlist.serverlist.begin(); i
- != mainlist.serverlist.end(); ++i )
+ for( i = mainlist.serverlist.begin(); i
+ != mainlist.serverlist.end(); ++i )
{ /* see if we have a disconnected peer */
- if( (*i).peer &&
+ if( (*i).peer &&
((*i).peer->state == ENET_PEER_STATE_DISCONNECTED ||
(*i).peer->state == ENET_PEER_STATE_ZOMBIE ))
- {
+ {
/* Remove it from the list */
orxout(internal_warning) << (char*)(*i).peer->data << " timed out.\n";
mainlist.delServerByName( (*i).ServerInfo.getServerName() );
/* stop iterating, we manipulated the list */
/* TODO note: this only removes one dead server per loop
- * iteration. not beautiful, but one iteration is ~100ms,
+ * iteration. not beautiful, but one iteration is ~100ms,
* so not really relevant for the moment.
*/
break;
}
}
-
+
}
@@ -203,7 +200,7 @@
/***** EVENTS *****/
/* connect event */
- int
+ int
MasterServer::eventConnect( ENetEvent *event )
{ /* check for bad parameters */
if( !event )
@@ -216,20 +213,20 @@
enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
/* output debug info */
- orxout(verbose, context::master_server) << "A new client connected from "
- << addrconv
- << " on port "
+ orxout(verbose, context::master_server) << "A new client connected from "
+ << addrconv
+ << " on port "
<< event->peer->address.port << endl;
/* store string form of address here */
- event->peer->data = addrconv;
+ event->peer->data = addrconv;
/* all fine. */
return 0;
}
/* disconnect event */
- int
+ int
MasterServer::eventDisconnect( ENetEvent *event )
{ /* check for bad parameters */
if( !event )
@@ -254,68 +251,87 @@
}
/* data event */
- int
+ int
MasterServer::eventData( ENetEvent *event )
{ /* validate packet */
if( !event || !(event->packet) || !(event->peer) )
{ orxout(internal_warning, context::master_server) << "No complete event given." << endl;
return -1;
}
-
+
/* generate address in readable form */
char *addrconv = (char *) calloc( 50, 1 );
enet_address_get_host_ip( &(event->peer->address), addrconv, 49 );
+ /* convert to string */
+ std::string ip = std::string( addrconv );
+ /* delete addrconv */
+ if( addrconv ) free( addrconv );
+ /* pointer to full packet data */
+ char * packetdata = (char *)event->packet->data;
+
/* output debug info about the data that has come */
helper_output_debug( event, addrconv );
/* GAME SERVER OR CLIENT CONNECTION? */
- if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER,
- MSPROTO_GAME_SERVER_LEN ) )
+ if( !strncmp(packetdata, MSPROTO_GAME_SERVER, MSPROTO_GAME_SERVER_LEN ) )
{ /* Game server */
- if( !strncmp( (char *)event->packet->data
- + MSPROTO_GAME_SERVER_LEN+1,
- MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
+ if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) )
{ /* register new server */
- mainlist.addServer( packet::ServerInformation( event ),
- event->peer );
-
+ mainlist.addServer( packet::ServerInformation( event ), event->peer );
+
/* tell people we did so */
- orxout(internal_info, context::master_server) << "Added new server to list: " <<
+ orxout(internal_info, context::master_server) << "Added new server to list: " <<
packet::ServerInformation( event ).getServerIP() << endl;
}
- else if( !strncmp( (char *)event->packet->data
- + MSPROTO_GAME_SERVER_LEN+1,
- MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) )
- {
+ else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SERVERDC, MSPROTO_SERVERDC_LEN ) )
+ { /* disconnect server */
+
+ /* remove the server from the list it belongs to */
+ this->mainlist.delServerByAddress( ip );
+
+ /* tell the user */
+ orxout(internal_info, context::master_server) << "Removed server " << ip << " from list." << endl;
+ }
+ /* TODO add hook for disconnect here */
+
+ else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SET_NAME, MSPROTO_SET_NAME_LEN ) )
+ { /* save server name */
/* create string from peer data */
- std::string name = std::string( addrconv );
+ std::string data (event->packet->data,event->packet->data + event->packet->dataLength );
+ std::string name = data.substr(MSPROTO_GAME_SERVER_LEN+1 + MSPROTO_SET_NAME_LEN + 1);
/* remove the server from the list it belongs to */
- this->mainlist.delServerByAddress( name );
+ this->mainlist.setNameByAddress( ip, name );
/* tell the user */
- orxout(internal_info, context::master_server) << "Removed server " << name << " from list." << endl;
+ orxout(internal_info, context::master_server) << "Updated server " << ip << " with new name " << name << endl;
}
- /* TODO add hook for disconnect here */
+ else if( !strncmp( packetdata + MSPROTO_GAME_SERVER_LEN+1, MSPROTO_SET_CLIENTS, MSPROTO_SET_CLIENTS_LEN ) )
+ { /* save client count from server */
+ /* create string from peer data */
+ std::string data (event->packet->data,event->packet->data + event->packet->dataLength );
+ std::string textform= data.substr(MSPROTO_GAME_SERVER_LEN + 1 + MSPROTO_SET_CLIENTS_LEN + 1);
+ int clientNumber = Ogre::StringConverter::parseInt(textform);
+
+ this->mainlist.setClientsByAddress( ip, clientNumber);
+
+ /* tell the user */
+ orxout(internal_info, context::master_server) << "Updated server " << ip << " with new client number " << clientNumber << endl;
+ }
}
- else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT,
- MSPROTO_CLIENT_LEN) )
+ else if( !strncmp( packetdata, MSPROTO_CLIENT, MSPROTO_CLIENT_LEN) )
{ /* client */
- if( !strncmp( (char *)event->packet->data + MSPROTO_CLIENT_LEN+1,
- MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) )
+ if( !strncmp( packetdata + MSPROTO_CLIENT_LEN+1, MSPROTO_REQ_LIST, MSPROTO_REQ_LIST_LEN ) )
/* send server list */
helper_sendlist( event );
}
else
- { /* bad message, don't do anything. */ }
+ { /* bad message, don't do anything. */ }
- /* delete addrconv */
- if( addrconv ) free( addrconv );
-
/* Clean up the packet now that we're done using it. */
enet_packet_destroy( event->packet );
return 0;
@@ -323,13 +339,13 @@
/**** MAIN ROUTINE *****/
- int
+ int
MasterServer::run()
{
/***** ENTER MAIN LOOP *****/
ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char));
if( event == NULL )
- {
+ {
orxout(user_error, context::master_server) << "Could not create ENetEvent structure, exiting." << endl;
exit( EXIT_FAILURE );
}
@@ -344,11 +360,11 @@
/* check what type of event it is and react accordingly */
switch (event->type)
{ /* new connection */
- case ENET_EVENT_TYPE_CONNECT:
+ case ENET_EVENT_TYPE_CONNECT:
eventConnect( event ); break;
/* disconnect */
- case ENET_EVENT_TYPE_DISCONNECT:
+ case ENET_EVENT_TYPE_DISCONNECT:
eventDisconnect( event ); break;
/* incoming data */
@@ -357,8 +373,9 @@
}
/* done */
+ free(event);
return 0;
- }
+ }
/* constructor */
MasterServer::MasterServer()
@@ -379,15 +396,15 @@
this->address.host = ENET_HOST_ANY;
this->address.port = ORX_MSERVER_PORT;
- /* create a host with the above settings (the last two 0 mean: accept
+ /* create a host with the above settings (the last two 0 mean: accept
* any input/output bandwidth */
- this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS,
+ this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS,
ORX_MSERVER_MAXCHANS, 0, 0 );
assert(this->server);
/* see if creation worked */
if( !this->server )
- { orxout(user_error, context::master_server) <<
+ { orxout(user_error, context::master_server) <<
"An error occurred while trying to create an ENet server host." << endl;
exit( EXIT_FAILURE );
}
Modified: code/branches/presentationFS15merge/src/libraries/network/MasterServer.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/MasterServer.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/MasterServer.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -48,7 +48,10 @@
/* c compatibility */
#include <cstdio>
-namespace orxonox
+#include <OgreStringConverter.h>
+
+
+namespace orxonox
{
/* singleton */
class _NetworkExport MasterServer
@@ -62,11 +65,11 @@
/* static pointer for commands */
static MasterServer *instance;
- static MasterServer *getInstance()
+ static MasterServer *getInstance()
{ return instance; }
- static void setInstance( MasterServer *setto )
+ static void setInstance( MasterServer *setto )
{ instance = setto; }
-
+
/* functions for commands */
static void listServers( void );
static void delServer( std::string todeladdr );
Modified: code/branches/presentationFS15merge/src/libraries/network/MasterServerProtocol.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/MasterServerProtocol.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/MasterServerProtocol.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -36,15 +36,13 @@
/*** CLIENT COMMUNICATIONS ***/
/* Client token (shows that the party sending data is a client */
#define MSPROTO_CLIENT "CL"
-#define MSPROTO_CLIENT_LEN 2
+#define MSPROTO_CLIENT_LEN 2
/* Request: Serverlist (requiest made from client to master server */
#define MSPROTO_REQ_LIST "REQ:LIST"
#define MSPROTO_REQ_LIST_LEN 8
-
-
/*** GAME SERVER COMMUNICATIONS ***/
/* Game server token (shows that the party sending data is a game server) */
#define MSPROTO_GAME_SERVER "GS"
@@ -66,7 +64,7 @@
/* ping request from server */
#define MSPROTO_PING_GAMESERVER "PING"
-#define MSPROTO_PING_GAMESERVER_LEN 4
+#define MSPROTO_PING_GAMESERVER_LEN 4
/* server disconnect */
#define MSPROTO_SERVERDC "DC"
@@ -74,10 +72,18 @@
/* ping reply */
#define MSPROTO_ACK "ACK"
-#define MSPROTO_ACK_LEN 3
+#define MSPROTO_ACK_LEN 3
+/* server name */
+#define MSPROTO_SET_NAME "NAM"
+#define MSPROTO_SET_NAME_LEN 3
+/* server number of clients */
+#define MSPROTO_SET_CLIENTS "CLI"
+#define MSPROTO_SET_CLIENTS_LEN 3
+#define SERVER_NAME_MAXLEN 7
+
/* default master server port */
#define ORX_MSERVER_PORT 55557
Modified: code/branches/presentationFS15merge/src/libraries/network/PeerList.cc
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/PeerList.cc 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/PeerList.cc 2015-10-04 10:13:42 UTC (rev 10612)
@@ -37,10 +37,10 @@
PeerList::PeerList() { }
PeerList::~PeerList() { }
- int
+ int
PeerList::addPeer( ENetPeer *toadd )
{ /* error correction */
- if( toadd == NULL )
+ if( toadd == NULL )
{ orxout(internal_error, context::master_server) << "PeerList::addPeer: empty peer given." << endl;
return -1;
}
@@ -51,7 +51,7 @@
}
bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 )
- {
+ {
for( int i = 0; i < 16; ++i )
if( addr1.host.addr[i] < addr2.host.addr[i] )
return -i;
@@ -60,15 +60,15 @@
return 0;
}
-
+
bool
PeerList::remPeerByAddr( ENetAddress addr )
{ /* get an iterator */
std::list<ENetPeer *>::iterator i;
/* loop through list elements */
- for( i = peerlist.begin(); i != peerlist.end(); ++i )
+ for( i = peerlist.begin(); i != peerlist.end(); ++i )
if( !sub_compAddr((*i)->address, addr ) )
{ /* found this name, remove and quit */
this->peerlist.remove( *i );
@@ -85,7 +85,7 @@
std::list<ENetPeer *>::iterator i;
/* loop through list elements */
- for( i = peerlist.begin(); i != peerlist.end(); ++i )
+ for( i = peerlist.begin(); i != peerlist.end(); ++i )
if( !sub_compAddr((*i)->address, addr ) )
/* found this name, remove and quit */
return *i;
@@ -94,5 +94,9 @@
return NULL;
}
+ int
+ PeerList::count(){
+ return this->peerlist.size();
+ }
+
}
-
Modified: code/branches/presentationFS15merge/src/libraries/network/PeerList.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/PeerList.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/PeerList.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -34,12 +34,12 @@
#include <enet/enet.h>
/* peer list */
-namespace orxonox
+namespace orxonox
{
- /** This class keeps a list of open connections
+ /** This class keeps a list of open connections
* and some info about them.
*/
- class PeerList
+ class PeerList
{ public:
/** constructor */
PeerList();
@@ -49,24 +49,30 @@
/** \param toadd The peer to add
* \return 0 for success, -1 for error.
- *
- * Add new peer to list
+ *
+ * Add new peer to list
*/
int addPeer( ENetPeer *toadd );
/** \param addr Address to look for
* \return if the peer was found or not
- *
- * Remove peer from list by address
+ *
+ * Remove peer from list by address
*/
bool remPeerByAddr( ENetAddress addr );
/** \param addr The address to find by
- *
- * Find a connection by address */
+ *
+ * Find a connection by address
+ */
ENetPeer *findPeerByAddr( ENetAddress addr );
- /* NOTE: making this list public so it can easily
+ /**
+ * Count current peers
+ */
+ int count();
+
+ /* NOTE: making this list public so it can easily
* be iterated. This makes sense since iterating it
* will happen all the time, and using getter methods
* for the next in list would slow things down unnecessarily.
Modified: code/branches/presentationFS15merge/src/libraries/network/Server.cc
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/Server.cc 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/Server.cc 2015-10-04 10:13:42 UTC (rev 10612)
@@ -76,7 +76,13 @@
this->setPort( port );
this->timeSinceLastUpdate_=0;
}
-
+/*
+ Server::Server(int port, const std::string name)
+ {
+ this->setPort( port );
+ this->timeSinceLastUpdate_=0;
+ this->serverName_=name;
+ }*/
/**
* Constructor
* @param port Port to listen on
@@ -107,9 +113,11 @@
/* make discoverable on LAN */
LANDiscoverable::setActivity(true);
+ LANDiscoverable::updateClientNumber(0);
/* make discoverable on WAN */
WANDiscoverable::setActivity(true);
+ WANDiscoverable::updateClientNumber(0);
/* done */
return;
@@ -282,12 +290,16 @@
// inform all the listeners
this->clientIDs_.push_back(peerID);
+ WANDiscoverable::updateClientNumber(this->clientIDs_.size());
+ LANDiscoverable::updateClientNumber(this->clientIDs_.size());
+
ClientConnectionListener::broadcastClientConnected(peerID);
GamestateManager::addPeer(peerID);
// ++newid;
orxout(internal_info, context::network) << "Server: added client id: " << peerID << endl;
+
createClient(peerID);
}
@@ -308,6 +320,9 @@
break;
}
}
+ WANDiscoverable::updateClientNumber(this->clientIDs_.size());
+ LANDiscoverable::updateClientNumber(this->clientIDs_.size());
+
ClientConnectionListener::broadcastClientDisconnected(peerID);
GamestateManager::removePeer(peerID);
//ServerConnection::disconnectClient( client );
Modified: code/branches/presentationFS15merge/src/libraries/network/Server.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/Server.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/Server.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -66,6 +66,9 @@
unsigned int getRTT(unsigned int clientID);
virtual void printRTT();
float getPacketLoss(unsigned int clientID);
+ int getClientCount() { return this->clientIDs_.size();}
+ std::string getServerName() { return this->serverName_;}
+
protected:
void updateGamestate();
private:
@@ -88,6 +91,7 @@
float timeSinceLastUpdate_;
std::deque<packet::Packet*> packetQueue_;
std::vector<uint32_t> clientIDs_;
+ std::string serverName_;
};
Modified: code/branches/presentationFS15merge/src/libraries/network/ServerList.cc
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/ServerList.cc 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/ServerList.cc 2015-10-04 10:13:42 UTC (rev 10612)
@@ -29,7 +29,7 @@
#include "ServerList.h"
namespace orxonox
-{
+{
ServerList::ServerList()
{ /* create a new list */ }
@@ -38,26 +38,26 @@
serverlist.clear();
}
- int
+ int
ServerList::addServer( packet::ServerInformation toadd,
ENetPeer *peer )
- {
+ {
ServerListElem toAdd;
toAdd.ServerInfo = toadd;
toAdd.peer = peer;
- this->serverlist.push_back( toAdd );
+ this->serverlist.push_back( toAdd );
return 0;
}
- bool
+ bool
ServerList::delServerByName( std::string name )
- {
+ {
/* get an iterator */
std::list<ServerListElem>::iterator i;
/* loop through list elements */
- for( i = serverlist.begin(); i != serverlist.end(); ++i )
+ for( i = serverlist.begin(); i != serverlist.end(); ++i )
if( (*i).ServerInfo.getServerName() == name )
{ /* found this name, remove and quit */
this->serverlist.erase( i );
@@ -67,12 +67,12 @@
}
bool ServerList::delServerByAddress( std::string address )
- {
+ {
/* get an iterator */
std::list<ServerListElem>::iterator i;
/* loop through list elements */
- for( i = serverlist.begin(); i != serverlist.end(); ++i )
+ for( i = serverlist.begin(); i != serverlist.end(); ++i )
if( (*i).ServerInfo.getServerIP() == address )
{ /* found this name, remove and quit */
this->serverlist.erase( i );
@@ -89,7 +89,7 @@
std::list<ServerListElem>::iterator i;
/* loop through list elements */
- for( i = serverlist.begin(); i != serverlist.end(); ++i )
+ for( i = serverlist.begin(); i != serverlist.end(); ++i )
if( (*i).ServerInfo.getServerIP() == address )
{ /* found the target, return it */
ServerListSearchResult res = { (*i), true };
@@ -109,9 +109,9 @@
/* iterate, return when name found */
/* loop through list elements */
- for( i = serverlist.begin(); i != serverlist.end(); ++i )
+ for( i = serverlist.begin(); i != serverlist.end(); ++i )
if( (*i).ServerInfo.getServerName() == name )
- {
+ {
ServerListSearchResult res = { (*i), true };
return res;
}
@@ -123,25 +123,53 @@
/* SORTING */
/* sort by name */
- bool sub_compare_names( ServerListElem no1,
+ bool sub_compare_names( ServerListElem no1,
ServerListElem no2 )
{ return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName(); }
void ServerList::sortByName()
- {
- this->serverlist.sort( sub_compare_names );
+ {
+ this->serverlist.sort( sub_compare_names );
}
-
+
/* sort by ping */
- bool sub_compare_pings( ServerListElem no1,
+ bool sub_compare_pings( ServerListElem no1,
ServerListElem no2 )
- {
- return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName();
+ {
+ return no1.ServerInfo.getServerRTT() > no2.ServerInfo.getServerRTT();
}
void ServerList::sortByPing()
{
- this->serverlist.sort( sub_compare_pings );
+ this->serverlist.sort( sub_compare_pings );
}
+ bool ServerList::setNameByAddress( std::string address, std::string name ){
+ /* get an iterator */
+ std::list<ServerListElem>::iterator i;
+
+ /* loop through list elements */
+ for( i = serverlist.begin(); i != serverlist.end(); ++i )
+ if( (*i).ServerInfo.getServerIP() == address )
+ { /* found this adress, rename and quit */
+ (*i).ServerInfo.setServerName( name );
+ return true;
+ }
+ return false;
+ };
+
+ bool ServerList::setClientsByAddress( std::string address, int clientNumber ){
+ /* get an iterator */
+ std::list<ServerListElem>::iterator i;
+
+ /* loop through list elements */
+ for( i = serverlist.begin(); i != serverlist.end(); ++i )
+ if( (*i).ServerInfo.getServerIP() == address )
+ { /* found this adress, rename and quit */
+ (*i).ServerInfo.setClientNumber( clientNumber );
+ return true;
+ }
+ return false;
+ };
+
}
Modified: code/branches/presentationFS15merge/src/libraries/network/ServerList.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/ServerList.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/ServerList.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -34,10 +34,10 @@
#include <network/packet/ServerInformation.h>
/* methods necessary */
-namespace orxonox
-{
+namespace orxonox
+{
/* HELPER STRUCTURES */
- struct ServerListElem
+ struct ServerListElem
{
/* server information (name, IP, etc) */
packet::ServerInformation ServerInfo;
@@ -62,7 +62,7 @@
/** This class is keeps a list of game servers
* and some info about them.
*/
- class ServerList
+ class ServerList
{ public:
/** constructor */
ServerList();
@@ -73,43 +73,44 @@
/* BASIC MANIPULATION */
/** \param toadd the server to add.
- *
+ *
* Add server to the game server list
*/
int addServer( packet::ServerInformation toadd,
ENetPeer *peer );
/** \param name Name of the server to remove
- *
- * Remove server by name
+ *
+ * Remove server by name
*/
bool delServerByName( std::string name );
/** \param address IP address of the server to remove
- *
+ *
* Remove server by address
*/
bool delServerByAddress( std::string address );
+ bool setNameByAddress( std::string address, std::string name );
+ bool setClientsByAddress( std::string address, int clientNumber );
-
/* SEARCHING */
- /* \param address The address of the server that is to be
+ /* \param address The address of the server that is to be
* found
* \return A struct containing a result of the search and a boolean
* that is only true if the search was successful
- *
+ *
* Find and return the list handle of a given address.
*/
ServerListSearchResult
findServerByAddress( std::string address );
- /* \param name The name of the server that is to be
+ /* \param name The name of the server that is to be
* found
* \return The struct containing the list entry of the server
- *
+ *
* Find and return the list handle of a given name.
*/
ServerListSearchResult
@@ -119,7 +120,7 @@
/* SORTING */
/** sort by name */
void sortByName();
-
+
/** sort by ping */
void sortByPing();
Modified: code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.cc
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.cc 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.cc 2015-10-04 10:13:42 UTC (rev 10612)
@@ -43,35 +43,35 @@
{
/* debugging output */
orxout(verbose, context::master_server) << "Creating WANDiscoverable." << endl;
-
+
/* register object in orxonox */
RegisterObject(WANDiscoverable);
/* check for the masterserver address option in orxonox.ini */
this->setConfigValues();
-
+
}
void WANDiscoverable::setConfigValues()
{
- /* update msaddress string from orxonox.ini config file, if it
- * has changed.
+ /* update msaddress string from orxonox.ini config file, if it
+ * has changed.
*/
- SetConfigValueExternal(msaddress, "WANDiscovery", "msaddress", "orxonox.net");
-// SetConfigValue( msaddress, "orxonox.net");
- }
+ SetConfigValueExternal(msaddress, "Discovery", "msaddress", "orxonox.net");
+ SetConfigValueExternal(ownName, "Discovery", "ownName", "OrxServer");
+ }
WANDiscoverable::~WANDiscoverable()
{
if( this->bActive_ )
this->disconnect();
}
-
+
void WANDiscoverable::setActivity(bool bActive)
{
if( bActive==this->bActive_ )
return;
-
+
if( bActive )
{
if( this->connect() )
@@ -83,7 +83,7 @@
this->bActive_ = false;
}
}
-
+
bool WANDiscoverable::connect()
{
/* initialize it and see if it worked */
@@ -92,22 +92,25 @@
orxout(internal_error, context::master_server) << "Could not initialize master server communications!" << endl;
return false;
}
-
+
/* connect and see if it worked */
if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
{
- orxout(internal_error, context::master_server) << "Could not connect to master server at "
+ orxout(internal_error, context::master_server) << "Could not connect to master server at "
<< this->msaddress << endl;
return false;
}
-
+
/* debugging output */
orxout(verbose, context::master_server) << "Initialization of WANDiscoverable complete." << endl;
-
-
+
// Now register the server at the master server
this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
-
+
+ std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_NAME " ";
+ request += this->ownName;
+ this->msc.sendRequest( request );
+
return true;
}
@@ -117,7 +120,16 @@
msc.disconnect();
}
+ void WANDiscoverable::updateClientNumber(int clientNumber)
+ {
+ orxout(verbose, context::master_server) << "Sending new number of clients: " << clientNumber << endl;
+ std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_CLIENTS " ";
+ request += Ogre::StringConverter::toString(clientNumber);
+ this->msc.sendRequest( request );
+ }
-
+
+
+
} // namespace orxonox
Modified: code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/WANDiscoverable.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -31,6 +31,7 @@
#include "NetworkPrereqs.h"
#include "core/config/Configurable.h"
#include "MasterServerComm.h"
+#include <OgreStringConverter.h>
namespace orxonox
{
@@ -45,30 +46,33 @@
~WANDiscoverable();
/** \return Address of the master server
- *
- * Get the master server address
+ *
+ * Get the master server address
*/
std::string getMSAddress()
{ return this->msaddress; }
/** Function used for the configuration file parameter update */
void setConfigValues();
-
+
/** Function used to set the activity/discoverability */
void setActivity( bool bActive );
+ void updateClientNumber(int clientNumber);
+
/** Master server communications object */
MasterServerComm msc;
-
+
private:
/** Function used to connect to the master server */
bool connect();
-
+
/** Function used to disconnect from the master server */
void disconnect();
-
+
/** master server address */
std::string msaddress;
+ std::string ownName;
bool bActive_;
};
Modified: code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.cc 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.cc 2015-10-04 10:13:42 UTC (rev 10612)
@@ -40,7 +40,7 @@
{
/* debugging output */
orxout(verbose, context::master_server) << "Creating WANDiscovery." << endl;
-
+
/* register object in orxonox */
RegisterObject(WANDiscovery);
@@ -53,7 +53,7 @@
/* connect and see if it worked */
if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
- orxout(internal_error, context::master_server) << "Could not connect to master server at "
+ orxout(internal_error, context::master_server) << "Could not connect to master server at "
<< this->msaddress << endl;
/* debugging output */
@@ -62,21 +62,21 @@
void WANDiscovery::setConfigValues()
{
- /* update msaddress string from orxonox.ini config file, if it
- * has changed.
+ /* update msaddress string from orxonox.ini config file, if it
+ * has changed.
*/
SetConfigValue( msaddress, "master.orxonox.net");
- }
+ }
WANDiscovery::~WANDiscovery()
- {
+ {
/* clear server list */
- this->servers_.clear();
+ this->servers_.clear();
}
/* callback for the network reply poller */
int WANDiscovery::rhandler( char *addr, ENetEvent *ev )
- {
+ {
/* error recognition */
if( !ev || !ev->packet || !ev->packet->data )
{ orxout(internal_warning, context::master_server) << "Bad arguments received in WANDiscovery's reply handler." << endl;
@@ -87,33 +87,37 @@
/* if a list entry arrives add to list */
if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM,
MSPROTO_SERVERLIST_ITEM_LEN ) )
- {
+ {
/* create server structure from that item */
packet::ServerInformation toadd;
/* fill in data, -1 for the index: index should be length -1 */
- toadd.setServerName( std::string((char*)ev->packet->data +
- MSPROTO_SERVERLIST_ITEM_LEN+1) );
- toadd.setServerIP( std::string((char*)ev->packet->data +
- MSPROTO_SERVERLIST_ITEM_LEN+1) );
+ std::string datastr = std::string((char*)ev->packet->data + MSPROTO_SERVERLIST_ITEM_LEN+1);
+ int separator = datastr.find(" ");
+ toadd.setServerIP(datastr.substr(0,separator));
+ int secondsep = datastr.find(" ", separator + 1);
+ toadd.setServerName(datastr.substr(separator + 1, secondsep - separator - 1));
+ toadd.setClientNumber(Ogre::StringConverter::parseInt(datastr.substr(secondsep+1)));
+ orxout(internal_info, context::network) << "Received WAN discovery server information; Name: " << toadd.getServerName() << ", Address: " << toadd.getServerIP() << ", Players: " << toadd.getClientNumber() << ", RTT: " << toadd.getServerRTT() << endl;
+
/* add to list */
this->servers_.push_back( toadd );
}
else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
MSPROTO_SERVERLIST_END_LEN ) )
- {
+ {
/* this is the only case where 2 should be returned,
* as 1 is used to signal that we're done receiving
* the list
*/
- return 2;
+ return 2;
}
/* done handling, return all ok code 0 */
return 1;
}
-
+
void WANDiscovery::discover()
{
/* clear list */
@@ -130,7 +134,7 @@
switch( this->msc.pollForReply( this, 500 ) )
{ case 0: /* no event occured, decrease timeout */
--i; break;
- case 1: /* got a list element, continue */
+ case 1: /* got a list element, continue */
break;
case 2: /* done. */
i = 0; break;
@@ -158,5 +162,24 @@
return this->servers_[index].getServerIP();
}
+ std::string WANDiscovery::getServerListItemRTT(unsigned int index)
+ {
+ if( index >= this->servers_.size() )
+ return BLANKSTRING;
+ else{
+ uint32_t serverrtt = this->servers_[index].getServerRTT();
+ return Ogre::StringConverter::toString(serverrtt);
+ }
+ }
+ std::string WANDiscovery::getServerListItemPlayerNumber(unsigned int index)
+ {
+ if( index >= this->servers_.size() )
+ return BLANKSTRING;
+ else{
+ int playerNumber = this->servers_[index].getClientNumber();
+ return Ogre::StringConverter::toString(playerNumber);
+ }
+ }
+
} // namespace orxonox
Modified: code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -34,6 +34,7 @@
#include "core/config/ConfigValueIncludes.h"
#include "MasterServerComm.h"
#include "MasterServerProtocol.h"
+#include <OgreStringConverter.h>
#include <vector>
@@ -55,8 +56,8 @@
~WANDiscovery();
/** \return Address of the master server
- *
- * Get the master server address
+ *
+ * Get the master server address
*/
std::string getMSAddress()
{ return this->msaddress; }
@@ -64,22 +65,36 @@
/** ask server for server list */
void discover(); // tolua_export
- /** \param index Index to get the name of
+ /** \param index Index to get the name of
* \return The name of the server
- *
- * Get the name of the server at index index.
+ *
+ * Get the name of the server at index index.
*/
std::string getServerListItemName( unsigned int index ); // tolua_export
- /** \param index Index to get the IP of
+ /** \param index Index to get the IP of
* \return The IP of the server
- *
- * Get the IP of the server at index index.
+ *
+ * Get the IP of the server at index index.
*/
std::string getServerListItemIP( unsigned int index ); // tolua_export
+ /** \param index Index to get the RTT of
+ * \return The RTT of the server
+ *
+ * Get the RTT of the server at index index.
+ */
+ std::string getServerListItemRTT( unsigned int index ); // tolua_export
+
+ /** \param index Index to get the RTT of
+ * \return The number of players on the server
+ *
+ * Get the number of players on the server
+ */
+ std::string getServerListItemPlayerNumber( unsigned int index ); // tolua_export
+
/* todo: might make this private and use getter/setter methods
- * at some later time.
+ * at some later time.
*/
/** game server list */
std::vector<packet::ServerInformation> servers_;
@@ -91,7 +106,7 @@
MasterServerComm msc;
int rhandler( char *addr, ENetEvent *ev );
-
+
private:
/** master server address */
std::string msaddress;
Modified: code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.cc
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.cc 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.cc 2015-10-04 10:13:42 UTC (rev 10612)
@@ -38,12 +38,11 @@
{
namespace packet
{
-
+
ServerInformation::ServerInformation()
{
-
}
-
+
ServerInformation::ServerInformation(ENetEvent* event)
{
char serverIP[64];
@@ -68,22 +67,23 @@
ServerInformation::~ServerInformation()
{
-
+
}
void ServerInformation::send(ENetPeer* peer)
{
- uint32_t size = returnSize((char*&)LAN_DISCOVERY_ACK) + returnSize(this->serverName_);
+ std::string payload = this->serverName_ + Ogre::StringConverter::toString(this->clientNumber_);
+ uint32_t size = returnSize((char*&)LAN_DISCOVERY_ACK) + returnSize(payload);
uint8_t* temp = new uint8_t[size];
uint8_t* temp2 = temp;
saveAndIncrease((char*&)LAN_DISCOVERY_ACK, temp2);
- saveAndIncrease(this->serverName_, temp2);
+ saveAndIncrease(payload, temp2);
ENetPacket* packet = enet_packet_create( temp, size, 0 );
enet_peer_send(peer, 0, packet);
-
+
delete[] temp;
}
-
+
} // namespace packet
std::ostream& operator<<(std::ostream& out, const ENetAddress& address)
@@ -94,4 +94,3 @@
return out;
}
} // namespace orxonox
-
Modified: code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.h
===================================================================
--- code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.h 2015-10-04 10:12:42 UTC (rev 10611)
+++ code/branches/presentationFS15merge/src/libraries/network/packet/ServerInformation.h 2015-10-04 10:13:42 UTC (rev 10612)
@@ -29,7 +29,9 @@
#include "../NetworkPrereqs.h"
#include <string>
+#include <OgreStringConverter.h>
+
#ifndef SERVERINFORMATION_H
#define SERVERINFORMATION_H
@@ -44,16 +46,19 @@
ServerInformation();
ServerInformation(ENetEvent* event);
~ServerInformation();
-
+
void send( ENetPeer* peer );
- std::string getServerIP() { return this->serverIP_; }
+ void setServerName(std::string name) { this->serverName_ = name; }
std::string getServerName() { return this->serverName_; }
- void setServerName(std::string name) { this->serverName_ = name; }
void setServerIP( std::string IP ) { this->serverIP_ = IP; }
+ std::string getServerIP() { return this->serverIP_; }
+ void setClientNumber( int clientNumber ) { this->clientNumber_ = clientNumber; }
+ int getClientNumber() { return this->clientNumber_; }
uint32_t getServerRTT() { return this->serverRTT_; }
-
+
private:
std::string serverName_;
+ int clientNumber_;
std::string serverIP_;
uint32_t serverRTT_;
};
More information about the Orxonox-commit
mailing list