mirror of
https://github.com/glest/glest-source.git
synced 2025-08-13 03:44:00 +02:00
- find servers on LAN now discovers customized game ports
This commit is contained in:
@@ -264,10 +264,19 @@ void MenuStateJoinGame::DiscoveredServers(std::vector<string> serverList) {
|
||||
buttonAutoFindServers.setEnabled(true);
|
||||
buttonConnect.setEnabled(true);
|
||||
if(serverList.empty() == false) {
|
||||
Config &config= Config::getInstance();
|
||||
string bestIPMatch = "";
|
||||
int serverGamePort = config.getInt("ServerPort",intToStr(GameConstants::serverPort).c_str());
|
||||
std::vector<std::string> localIPList = Socket::getLocalIPAddressList();
|
||||
|
||||
for(int idx = 0; idx < serverList.size(); idx++) {
|
||||
|
||||
vector<string> paramPartPortsTokens;
|
||||
Tokenize(serverList[idx],paramPartPortsTokens,":");
|
||||
if(paramPartPortsTokens.size() >= 2 && paramPartPortsTokens[1].length() > 0) {
|
||||
serverGamePort = strToInt(paramPartPortsTokens[1]);
|
||||
}
|
||||
|
||||
bestIPMatch = serverList[idx];
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] bestIPMatch = [%s] localIPList[0] = [%s]\n",__FILE__,__FUNCTION__,__LINE__,bestIPMatch.c_str(),localIPList[0].c_str());
|
||||
@@ -277,6 +286,9 @@ void MenuStateJoinGame::DiscoveredServers(std::vector<string> serverList) {
|
||||
}
|
||||
}
|
||||
|
||||
if(bestIPMatch != "") {
|
||||
bestIPMatch += ":" + intToStr(serverGamePort);
|
||||
}
|
||||
labelServerIp.setText(bestIPMatch);
|
||||
|
||||
if(serverList.size() > 1) {
|
||||
|
@@ -220,9 +220,10 @@ class BroadCastSocketThread : public BaseThread
|
||||
private:
|
||||
Mutex *mutexPauseBroadcast;
|
||||
bool pauseBroadcast;
|
||||
int boundPort;
|
||||
|
||||
public:
|
||||
BroadCastSocketThread();
|
||||
BroadCastSocketThread(int boundPort);
|
||||
virtual ~BroadCastSocketThread();
|
||||
virtual void execute();
|
||||
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
|
||||
|
@@ -1999,8 +1999,17 @@ void BroadCastClientSocketThread::execute() {
|
||||
string fromIP = szHostFrom;
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"broadcast message received: [%s] from: [%s]\n", buff,fromIP.c_str() );
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Client got broadcast from server: [%s] data [%s]\n",fromIP.c_str(),buff);
|
||||
|
||||
int serverGamePort = Socket::getBroadCastPort();
|
||||
vector<string> paramPartPortsTokens;
|
||||
Tokenize(buff,paramPartPortsTokens,":");
|
||||
if(paramPartPortsTokens.size() >= 3 && paramPartPortsTokens[2].length() > 0) {
|
||||
serverGamePort = strToInt(paramPartPortsTokens[2]);
|
||||
}
|
||||
|
||||
if(std::find(foundServers.begin(),foundServers.end(),fromIP) == foundServers.end()) {
|
||||
foundServers.push_back(fromIP);
|
||||
foundServers.push_back(fromIP + ":" + intToStr(serverGamePort));
|
||||
}
|
||||
|
||||
// For now break as soon as we find a server
|
||||
@@ -2144,7 +2153,7 @@ void ServerSocket::startBroadCastThread() {
|
||||
|
||||
stopBroadCastThread();
|
||||
|
||||
broadCastThread = new BroadCastSocketThread();
|
||||
broadCastThread = new BroadCastSocketThread(this->boundPort);
|
||||
|
||||
//printf("Start broadcast thread [%p]\n",broadCastThread);
|
||||
|
||||
@@ -2672,10 +2681,11 @@ void UPNP_Tools::NETremRedirects(int ext_port) {
|
||||
// Description: To be forked in its own thread to send out a broadcast to the local subnet
|
||||
// the current broadcast message is <myhostname:my.ip.address.dotted>
|
||||
//
|
||||
BroadCastSocketThread::BroadCastSocketThread() : BaseThread() {
|
||||
BroadCastSocketThread::BroadCastSocketThread(int boundPort) : BaseThread() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
mutexPauseBroadcast = new Mutex();
|
||||
setPauseBroadcast(false);
|
||||
this->boundPort = boundPort;
|
||||
//printf("new broadcast thread [%p]\n",this);
|
||||
}
|
||||
|
||||
@@ -2792,6 +2802,8 @@ void BroadCastSocketThread::execute() {
|
||||
//sprintf(buff,"%s:%s",buff,ipList[idx1].c_str());
|
||||
strcat(buff,":");
|
||||
strcat(buff,ipList[idx1].c_str());
|
||||
strcat(buff,":");
|
||||
strcat(buff,intToStr(this->boundPort).c_str());
|
||||
}
|
||||
|
||||
if(difftime((long int)time(NULL),elapsed) >= 1 && getQuitStatus() == false) {
|
||||
@@ -2801,6 +2813,9 @@ void BroadCastSocketThread::execute() {
|
||||
if(pauseBroadCast == false) {
|
||||
// Broadcast the packet to the subnet
|
||||
//if( sendto( bcfd, buff, sizeof(buff) + 1, 0 , (struct sockaddr *)&bcaddr, sizeof(struct sockaddr_in) ) != sizeof(buff) + 1 )
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Server is sending broadcast data [%s]\n",buff);
|
||||
|
||||
ssize_t send_res = sendto( bcfd[idx], buff, buffMaxSize, 0 , (struct sockaddr *)&bcLocal[idx], sizeof(struct sockaddr_in) );
|
||||
if( send_res != buffMaxSize ) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Sendto error: %s\n", getLastSocketErrorFormattedText().c_str());
|
||||
|
Reference in New Issue
Block a user