mirror of
https://github.com/glest/glest-source.git
synced 2025-08-11 19:04:00 +02:00
Added auto-discovery of LAN servers using UDP broadcast. (for now the client must press the A key from the join menu to trigger this)
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "thread.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
@@ -53,11 +55,16 @@ class Socket {
|
||||
protected:
|
||||
int sock;
|
||||
long lastDebugEvent;
|
||||
static int broadcast_portno;
|
||||
|
||||
public:
|
||||
Socket(int sock);
|
||||
Socket();
|
||||
~Socket();
|
||||
virtual ~Socket();
|
||||
|
||||
static int getBroadCastPort() { return broadcast_portno; }
|
||||
static void setBroadCastPort(int value) { broadcast_portno = value; }
|
||||
static std::vector<std::string> getLocalIPAddressList();
|
||||
|
||||
// Int lookup is socket fd while bool result is whether or not that socket was signalled for reading
|
||||
static bool hasDataToRead(std::map<int,bool> &socketTriggeredList);
|
||||
@@ -91,6 +98,28 @@ protected:
|
||||
class ClientSocket: public Socket{
|
||||
public:
|
||||
void connect(const Ip &ip, int port);
|
||||
|
||||
static std::vector<string> discoverServers();
|
||||
};
|
||||
|
||||
class BroadCastSocketThread : public Thread
|
||||
{
|
||||
private:
|
||||
Mutex mutexRunning;
|
||||
Mutex mutexQuit;
|
||||
|
||||
bool quit;
|
||||
bool running;
|
||||
|
||||
void setRunningStatus(bool value);
|
||||
void setQuitStatus(bool value);
|
||||
|
||||
public:
|
||||
BroadCastSocketThread();
|
||||
virtual void execute();
|
||||
void signalQuit();
|
||||
bool getQuitStatus();
|
||||
bool getRunningStatus();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@@ -99,9 +128,18 @@ public:
|
||||
|
||||
class ServerSocket: public Socket{
|
||||
public:
|
||||
ServerSocket();
|
||||
virtual ~ServerSocket();
|
||||
void bind(int port);
|
||||
void listen(int connectionQueueSize= SOMAXCONN);
|
||||
Socket *accept();
|
||||
void stopBroadCastThread();
|
||||
|
||||
protected:
|
||||
|
||||
BroadCastSocketThread *broadCastThread;
|
||||
void startBroadCastThread();
|
||||
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
@@ -108,6 +108,7 @@ public:
|
||||
// Misc
|
||||
// =====================================================
|
||||
int MessageBox(int handle, const char *msg, const char *title, int buttons);
|
||||
void Tokenize(const string& str,vector<string>& tokens,const string& delimiters = " ");
|
||||
bool isdir(const char *path);
|
||||
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound=false);
|
||||
void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa
|
||||
// Copyright (C) 2001-2008 Martio Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
@@ -101,6 +101,7 @@ public:
|
||||
// =====================================================
|
||||
// Misc
|
||||
// =====================================================
|
||||
void Tokenize(const string& str,vector<string>& tokens,const string& delimiters = " ");
|
||||
bool isdir(const char *path);
|
||||
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound=false);
|
||||
void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
|
||||
|
@@ -103,10 +103,15 @@ public:
|
||||
// =====================================================
|
||||
|
||||
class ServerSocket: public Socket{
|
||||
|
||||
public:
|
||||
void bind(int port);
|
||||
void listen(int connectionQueueSize= SOMAXCONN);
|
||||
Socket *accept();
|
||||
|
||||
protected:
|
||||
|
||||
void broadcast_thread();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
Reference in New Issue
Block a user