Adding stuff for server list (choosing a server). Might not compile (untested yet).
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include <core/thread.h>
|
#include <core/thread.h>
|
||||||
#include <net/senderinterface.h>
|
#include <net/senderinterface.h>
|
||||||
#include <guiinterface.h>
|
#include <guiinterface.h>
|
||||||
|
#include <serverdata.h>
|
||||||
#include <playerdata.h>
|
#include <playerdata.h>
|
||||||
#include <gamedata.h>
|
#include <gamedata.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -74,6 +75,8 @@ public:
|
|||||||
void SendAskKickPlayer(unsigned playerId);
|
void SendAskKickPlayer(unsigned playerId);
|
||||||
void SendVoteKick(bool doKick);
|
void SendVoteKick(bool doKick);
|
||||||
|
|
||||||
|
ServerInfo GetServerInfo(unsigned serverId) const;
|
||||||
|
|
||||||
GameInfo GetGameInfo(unsigned gameId) const;
|
GameInfo GetGameInfo(unsigned gameId) const;
|
||||||
PlayerInfo GetPlayerInfo(unsigned playerId) const;
|
PlayerInfo GetPlayerInfo(unsigned playerId) const;
|
||||||
bool GetPlayerIdFromName(const std::string &playerName, unsigned &playerId) const;
|
bool GetPlayerIdFromName(const std::string &playerName, unsigned &playerId) const;
|
||||||
@@ -89,6 +92,7 @@ protected:
|
|||||||
typedef std::list<boost::shared_ptr<NetPacket> > NetPacketList;
|
typedef std::list<boost::shared_ptr<NetPacket> > NetPacketList;
|
||||||
typedef std::map<unsigned, PlayerInfo> PlayerInfoMap;
|
typedef std::map<unsigned, PlayerInfo> PlayerInfoMap;
|
||||||
typedef std::map<unsigned, boost::shared_ptr<AvatarData> > AvatarDataMap;
|
typedef std::map<unsigned, boost::shared_ptr<AvatarData> > AvatarDataMap;
|
||||||
|
typedef std::map<unsigned, ServerInfo> ServerInfoMap;
|
||||||
|
|
||||||
// Main function of the thread.
|
// Main function of the thread.
|
||||||
virtual void Main();
|
virtual void Main();
|
||||||
@@ -147,6 +151,10 @@ protected:
|
|||||||
|
|
||||||
void RemoveDisconnectedPlayers();
|
void RemoveDisconnectedPlayers();
|
||||||
|
|
||||||
|
void AddServerInfo(unsigned serverId, const ServerInfo &info);
|
||||||
|
void ClearServerInfoMap();
|
||||||
|
void UseServer(unsigned serverId);
|
||||||
|
|
||||||
unsigned GetGameIdByName(const std::string &name) const;
|
unsigned GetGameIdByName(const std::string &name) const;
|
||||||
void AddGameInfo(unsigned gameId, const GameInfo &info);
|
void AddGameInfo(unsigned gameId, const GameInfo &info);
|
||||||
void UpdateGameInfoMode(unsigned gameId, GameMode mode);
|
void UpdateGameInfoMode(unsigned gameId, GameMode mode);
|
||||||
@@ -188,6 +196,9 @@ private:
|
|||||||
StartData m_startData;
|
StartData m_startData;
|
||||||
PlayerDataList m_playerDataList;
|
PlayerDataList m_playerDataList;
|
||||||
|
|
||||||
|
ServerInfoMap m_serverInfoMap;
|
||||||
|
mutable boost::mutex m_serverInfoMapMutex;
|
||||||
|
|
||||||
GameInfoMap m_gameInfoMap;
|
GameInfoMap m_gameInfoMap;
|
||||||
mutable boost::mutex m_gameInfoMapMutex;
|
mutable boost::mutex m_gameInfoMapMutex;
|
||||||
|
|
||||||
|
|||||||
@@ -448,36 +448,67 @@ ClientStateReadingServerList::Process(ClientThread &client)
|
|||||||
|
|
||||||
if (doc.LoadFile())
|
if (doc.LoadFile())
|
||||||
{
|
{
|
||||||
TiXmlHandle docHandle(&doc);
|
client.ClearServerInfoMap();
|
||||||
const TiXmlElement *firstServer = docHandle.FirstChild("ServerList" ).FirstChild("Server").ToElement();
|
int serverCount = 0;
|
||||||
if (firstServer)
|
unsigned lastServerInfoId = 0;
|
||||||
|
TiXmlHandle docHandle(&doc);
|
||||||
|
const TiXmlElement *nextServer = docHandle.FirstChild("ServerList" ).FirstChild("Server").ToElement();
|
||||||
|
while (nextServer)
|
||||||
{
|
{
|
||||||
const TiXmlNode *addrNode;
|
ServerInfo serverInfo;
|
||||||
if (context.GetAddrFamily() == AF_INET6)
|
{
|
||||||
addrNode = firstServer->FirstChild("IPv6Address");
|
int tmpId;
|
||||||
else
|
nextServer->QueryIntAttribute("value", &tmpId);
|
||||||
addrNode = firstServer->FirstChild("IPv4Address");
|
serverInfo.id = (unsigned)tmpId;
|
||||||
const TiXmlNode *portNode = firstServer->FirstChild("Port");
|
}
|
||||||
|
const TiXmlNode *nameNode = nextServer->FirstChild("Name");
|
||||||
|
const TiXmlNode *sponsorNode = nextServer->FirstChild("Sponsor");
|
||||||
|
const TiXmlNode *countryNode = nextServer->FirstChild("Country");
|
||||||
|
const TiXmlNode *addr4Node = nextServer->FirstChild("IPv4Address");
|
||||||
|
const TiXmlNode *addr6Node = nextServer->FirstChild("IPv6Address");
|
||||||
|
const TiXmlNode *sctpNode = nextServer->FirstChild("SCTP");
|
||||||
|
const TiXmlNode *portNode = nextServer->FirstChild("Port");
|
||||||
|
|
||||||
// Currently, only IPv4 is supported for avatar servers.
|
// IPv6 support for avatar servers depends on this address and on libcurl.
|
||||||
const TiXmlNode *avatarNode = firstServer->FirstChild("AvatarServerAddress");
|
const TiXmlNode *avatarNode = nextServer->FirstChild("AvatarServerAddress");
|
||||||
|
|
||||||
if (!addrNode || !addrNode->ToElement() || !portNode || !portNode->ToElement())
|
if (!nameNode || !nameNode->ToElement() || !addrNode || !addr4Node->ToElement()
|
||||||
|
|| !addr6Node->ToElement() || !portNode || !portNode->ToElement())
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
||||||
|
|
||||||
context.SetServerAddr(addrNode->ToElement()->Attribute("value"));
|
serverInfo.name = nameNode->ToElement()->Attribute("value");
|
||||||
|
serverInfo.ipv4addr = addr4Node->ToElement()->Attribute("value");
|
||||||
|
serverInfo.ipv6addr = addr6Node->ToElement()->Attribute("value");
|
||||||
|
portNode->ToElement()->QueryIntAttribute("value", &serverInfo.port);
|
||||||
|
|
||||||
int tmpPort = 0;
|
// Optional parameters:
|
||||||
portNode->ToElement()->QueryIntAttribute("value", &tmpPort);
|
if (sponsorNode && sponsorNode->ToElement())
|
||||||
context.SetServerPort((unsigned)tmpPort);
|
serverInfo.sponsor = sponsorNode->ToElement()->Attribute("value");
|
||||||
|
if (countryNode && countryNode->ToElement())
|
||||||
if (avatarNode && avatarNode->ToElement()) // optional
|
serverInfo.country = countryNode->ToElement()->Attribute("value");
|
||||||
|
if (sctpNode && sctpNode->ToElement())
|
||||||
{
|
{
|
||||||
context.SetAvatarServerAddr(avatarNode->ToElement()->Attribute("value"));
|
int tmpSctp;
|
||||||
|
sctpNode->ToElement()->QueryIntAttribute
|
||||||
}
|
}
|
||||||
|
if (avatarNode && avatarNode->ToElement())
|
||||||
|
serverInfo.avatarServerAddr = avatarNode->ToElement()->Attribute("value");
|
||||||
|
|
||||||
|
client.AddServerInfo(serverInfo.id, serverInfo);
|
||||||
|
nextServer = nextServer->NextSiblingElement();
|
||||||
|
lastServerInfoId = serverInfo.id;
|
||||||
|
serverCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serverCount == 1)
|
||||||
|
{
|
||||||
|
client.UseServer(lastServerInfoId);
|
||||||
retVal = MSG_SOCK_SERVER_LIST_DONE;
|
retVal = MSG_SOCK_SERVER_LIST_DONE;
|
||||||
}
|
}
|
||||||
|
else if (serverCount > 0)
|
||||||
|
{
|
||||||
|
// TODO....
|
||||||
|
}
|
||||||
else
|
else
|
||||||
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
throw ClientException(__FILE__, __LINE__, ERR_SOCK_INVALID_SERVERLIST_XML, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -284,6 +284,19 @@ ClientThread::SendVoteKick(bool doKick)
|
|||||||
m_outPacketList.push_back(vote);
|
m_outPacketList.push_back(vote);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerInfo
|
||||||
|
ClientThread::GetServerInfo(unsigned serverId) const
|
||||||
|
{
|
||||||
|
ServerInfo tmpInfo;
|
||||||
|
boost::mutex::scoped_lock lock(m_serverInfoMapMutex);
|
||||||
|
ServerInfoMap::const_iterator pos = m_serverInfoMap.find(serverId);
|
||||||
|
if (pos != m_serverInfoMap.end())
|
||||||
|
{
|
||||||
|
tmpInfo = pos->second;
|
||||||
|
}
|
||||||
|
return tmpInfo;
|
||||||
|
}
|
||||||
|
|
||||||
GameInfo
|
GameInfo
|
||||||
ClientThread::GetGameInfo(unsigned gameId) const
|
ClientThread::GetGameInfo(unsigned gameId) const
|
||||||
{
|
{
|
||||||
@@ -941,6 +954,42 @@ ClientThread::RemoveDisconnectedPlayers()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientThread::AddServerInfo(unsigned serverId, const ServerInfo &info)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_serverInfoMapMutex);
|
||||||
|
m_serverInfoMap.insert(ServerInfoMap::value_type(serverId, info));
|
||||||
|
}
|
||||||
|
//GetCallback().SignalNetClientServerListAdd(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientThread::ClearServerInfoMap()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_serverInfoMapMutex);
|
||||||
|
m_serverInfoMap.clear();
|
||||||
|
}
|
||||||
|
//GetCallback().SignalNetClientServerListClear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientThread::UseServer(unsigned serverId)
|
||||||
|
{
|
||||||
|
ClientContext &context = client.GetContext();
|
||||||
|
ServerInfo useInfo(GetServerInfo(serverId));
|
||||||
|
|
||||||
|
if (context.GetAddrFamily() == AF_INET6)
|
||||||
|
context.SetServerAddr(useInfo.ipv6addr);
|
||||||
|
else
|
||||||
|
context.SetServerAddr(useInfo.ipv4addr);
|
||||||
|
|
||||||
|
context.SetServerPort((unsigned)useInfo.port);
|
||||||
|
context.SetAvatarServerAddr(useInfo.avatarServerAddr);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
ClientThread::GetGameIdByName(const std::string &name) const
|
ClientThread::GetGameIdByName(const std::string &name) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2009 by Lothar May *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the *
|
||||||
|
* Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
|
***************************************************************************/
|
||||||
|
/* Server data. */
|
||||||
|
|
||||||
|
#ifndef _SERVERDATA_H_
|
||||||
|
#define _SERVERDATA_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
struct ServerInfo
|
||||||
|
{
|
||||||
|
ServerInfo() : id(0), supportsSctp(false), port(0) {}
|
||||||
|
unsigned id;
|
||||||
|
std::string name;
|
||||||
|
std::string sponsor;
|
||||||
|
std::string country;
|
||||||
|
std::string ipv4addr;
|
||||||
|
std::string ipv6addr;
|
||||||
|
bool supportsSctp;
|
||||||
|
int port;
|
||||||
|
std::string avatarServerAddr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -425,6 +425,14 @@ bool Session::isNetworkServerRunning() const
|
|||||||
return myNetServer != NULL;
|
return myNetServer != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerInfo Session::getClientServerInfo(unsigned serverId) const
|
||||||
|
{
|
||||||
|
ServerInfo info;
|
||||||
|
if (myNetClient)
|
||||||
|
info = myNetClient->GetServerInfo(serverId);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
GameInfo Session::getClientGameInfo(unsigned playerId) const
|
GameInfo Session::getClientGameInfo(unsigned playerId) const
|
||||||
{
|
{
|
||||||
GameInfo info;
|
GameInfo info;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#ifndef STDSESSION_H
|
#ifndef STDSESSION_H
|
||||||
#define STDSESSION_H
|
#define STDSESSION_H
|
||||||
|
#include "serverdata.h"
|
||||||
#include "gamedata.h"
|
#include "gamedata.h"
|
||||||
#include "playerdata.h"
|
#include "playerdata.h"
|
||||||
#include "game_defs.h"
|
#include "game_defs.h"
|
||||||
@@ -88,6 +89,7 @@ public:
|
|||||||
bool isNetworkClientRunning() const; // TODO hack
|
bool isNetworkClientRunning() const; // TODO hack
|
||||||
bool isNetworkServerRunning() const; // TODO hack
|
bool isNetworkServerRunning() const; // TODO hack
|
||||||
|
|
||||||
|
ServerInfo getClientServerInfo(unsigned serverId) const;
|
||||||
GameInfo getClientGameInfo(unsigned gameId) const;
|
GameInfo getClientGameInfo(unsigned gameId) const;
|
||||||
PlayerInfo getClientPlayerInfo(unsigned playerId) const;
|
PlayerInfo getClientPlayerInfo(unsigned playerId) const;
|
||||||
ServerStats getClientStats() const;
|
ServerStats getClientStats() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user