Clean up:
Remove unused NetworkArg, NetworkStatus. Remove global NetworkNumInterfaces, NetLocalAddrs
This commit is contained in:
parent
8b407bedf4
commit
8534741819
6 changed files with 23 additions and 52 deletions
src
include
network
stratagus
|
@ -115,12 +115,6 @@ private:
|
|||
Socket MaxSockFD;
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
extern unsigned long NetLocalAddrs[]; /// Local IP-Addrs of this host (net format)
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
@ -133,7 +127,7 @@ extern void NetExit();
|
|||
/// Resolve host in name or or colon dot notation.
|
||||
extern unsigned long NetResolveHost(const std::string &host);
|
||||
/// Get local IP from network file descriptor
|
||||
extern int NetSocketAddr(const Socket sock);
|
||||
extern int NetSocketAddr(const Socket sock, unsigned long *ips, int maxAddr);
|
||||
|
||||
/// Open a UDP Socket port.
|
||||
extern Socket NetOpenUDP(const char *addr, int port);
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
//@{
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
|
@ -212,7 +211,6 @@ enum _net_client_con_state_ {
|
|||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
extern std::string NetworkArg; /// Network command line argument
|
||||
extern int NetPlayers; /// Network players
|
||||
extern char *NetworkAddr; /// Local network address to use
|
||||
extern int NetworkPort; /// Local network port to use
|
||||
|
|
|
@ -45,8 +45,6 @@
|
|||
// Declarations
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#define MAX_LOC_IP 10
|
||||
|
||||
#ifdef USE_WIN32
|
||||
typedef const char *setsockopttype;
|
||||
typedef char *recvfrombuftype;
|
||||
|
@ -62,12 +60,6 @@ typedef const void *sendtobuftype;
|
|||
typedef const void *sendbuftype;
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Variables
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
unsigned long NetLocalAddrs[MAX_LOC_IP]; /// Local IP-Addrs of this host (net format)
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Low level functions
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -209,9 +201,10 @@ unsigned long NetResolveHost(const std::string &host)
|
|||
|
||||
/**
|
||||
** Get IP-addrs of local interfaces from Network file descriptor
|
||||
** and store them in the NetLocalAddrs array.
|
||||
**
|
||||
** @param sock local socket.
|
||||
** @param sock local socket.
|
||||
** @param ips where to stock ip addrs.
|
||||
** @param maxAddr size of ips.
|
||||
**
|
||||
** @return number of IP-addrs found.
|
||||
*/
|
||||
|
@ -220,9 +213,9 @@ unsigned long NetResolveHost(const std::string &host)
|
|||
// I also found a way for winsock1.1 (= win95), but
|
||||
// that one was too complex to start with.. -> trouble
|
||||
// Lookout for INTRFC.EXE on the MS web site...
|
||||
int NetSocketAddr(const Socket sock)
|
||||
int NetSocketAddr(const Socket sock, unsigned long *ips, int maxAddr)
|
||||
{
|
||||
INTERFACE_INFO localAddr[MAX_LOC_IP]; // Assume there will be no more than MAX_LOC_IP interfaces
|
||||
INTERFACE_INFO localAddr[maxAddr]; // Assume there will be no more than maxAddr interfaces
|
||||
int nif = 0;
|
||||
|
||||
if (sock != static_cast<Socket>(-1)) {
|
||||
|
@ -244,9 +237,9 @@ int NetSocketAddr(const Socket sock)
|
|||
continue;
|
||||
}
|
||||
SOCKADDR_IN *pAddrInet = (SOCKADDR_IN *)&localAddr[i].iiAddress;
|
||||
NetLocalAddrs[nif] = pAddrInet->sin_addr.s_addr;
|
||||
ips[nif] = pAddrInet->sin_addr.s_addr;
|
||||
++nif;
|
||||
if (nif == MAX_LOC_IP) {
|
||||
if (nif == maxAddr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -257,7 +250,7 @@ int NetSocketAddr(const Socket sock)
|
|||
// ARI: I knew how to write this for a unix environment,
|
||||
// but am quite certain that porting this can cause you
|
||||
// trouble..
|
||||
int NetSocketAddr(const Socket sock)
|
||||
int NetSocketAddr(const Socket sock, unsigned long *ips, int maxAddr)
|
||||
{
|
||||
if (sock == static_cast<Socket>(-1)) {
|
||||
return 0;
|
||||
|
@ -296,7 +289,7 @@ int NetSocketAddr(const Socket sock)
|
|||
}
|
||||
struct sockaddr_in *sap = (struct sockaddr_in *)&ifr->ifr_addr;
|
||||
struct sockaddr_in sa = *sap;
|
||||
NetLocalAddrs[nif] = sap->sin_addr.s_addr;
|
||||
ips[nif] = sap->sin_addr.s_addr;
|
||||
if (ifreq.ifr_flags & IFF_POINTOPOINT) {
|
||||
if (ioctl(sock, SIOCGIFDSTADDR, (char *)&ifreq) < 0) {
|
||||
DebugPrint("%s: SIOCGIFDSTADDR - errno %d\n" _C_
|
||||
|
@ -312,7 +305,7 @@ int NetSocketAddr(const Socket sock)
|
|||
if (nif) {
|
||||
int i;
|
||||
for (i = 0; i < nif; ++i) {
|
||||
if (sa.sin_addr.s_addr == NetLocalAddrs[i]) {
|
||||
if (sa.sin_addr.s_addr == ips[i]) {
|
||||
i = -1;
|
||||
break;
|
||||
}
|
||||
|
@ -322,7 +315,7 @@ int NetSocketAddr(const Socket sock)
|
|||
}
|
||||
}
|
||||
++nif;
|
||||
if (nif == MAX_LOC_IP) {
|
||||
if (nif == maxAddr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -330,9 +323,9 @@ int NetSocketAddr(const Socket sock)
|
|||
}
|
||||
#else // } {
|
||||
// Beos?? Mac??
|
||||
int NetSocketAddr(const Socket sock)
|
||||
int NetSocketAddr(const Socket sock, unsigned long *ips, int maxAddr)
|
||||
{
|
||||
NetLocalAddrs[0] = htonl(0x7f000001);
|
||||
ips[0] = htonl(0x7f000001);
|
||||
return 1;
|
||||
}
|
||||
#endif // }
|
||||
|
|
|
@ -61,7 +61,6 @@
|
|||
// Variables
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
std::string NetworkArg; /// Network command line argument
|
||||
int NetPlayers; /// How many network players
|
||||
char *NetworkAddr = NULL; /// Local network address to use
|
||||
int NetworkPort = NetworkDefaultPort; /// Local network port to use
|
||||
|
@ -86,7 +85,7 @@ std::string NetworkMapName; /// Name of the map recieved with ICMMap
|
|||
/// For now just specify with the -P port command line arg...
|
||||
static int NetworkServerPort = NetworkDefaultPort; /// Server network port to use
|
||||
|
||||
int NoRandomPlacementMultiplayer = 0; /// Disable the random placement of players in muliplayer mode
|
||||
static int NoRandomPlacementMultiplayer = 0; /// Disable the random placement of players in muliplayer mode
|
||||
|
||||
/**
|
||||
** Client and server selection state for Multiplayer clients
|
||||
|
|
|
@ -256,12 +256,10 @@ public:
|
|||
// Variables
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
static int NetworkNumInterfaces; /// Network number of interfaces
|
||||
Socket NetworkFildes = static_cast<Socket>(-1); /// Network file descriptor
|
||||
int NetworkInSync = 1; /// Network is in sync
|
||||
int NetworkUpdates = 5; /// Network update each # game cycles
|
||||
int NetworkLag = 10; /// Network lag in # game cycles
|
||||
static unsigned long NetworkStatus[PlayerMax]; /// Network status
|
||||
static unsigned long NetworkLastFrame[PlayerMax]; /// Last frame received packet
|
||||
static const int NetworkTimeout = 45; /// Number of seconds until player times out
|
||||
|
||||
|
@ -492,7 +490,6 @@ void InitNetwork1()
|
|||
{
|
||||
NetworkFildes = static_cast<Socket>(-1);
|
||||
NetworkInSync = 1;
|
||||
NetworkNumInterfaces = 0;
|
||||
|
||||
NetInit(); // machine dependent setup
|
||||
|
||||
|
@ -522,15 +519,13 @@ void InitNetwork1()
|
|||
return;
|
||||
}
|
||||
|
||||
#if 1
|
||||
// FIXME: need a working interface check
|
||||
NetworkNumInterfaces = 1;
|
||||
#else
|
||||
NetworkNumInterfaces = NetSocketAddr(NetworkFildes);
|
||||
if (NetworkNumInterfaces) {
|
||||
DebugPrint("Num IP: %d\n" _C_ NetworkNumInterfaces);
|
||||
for (int i = 0; i < NetworkNumInterfaces; ++i) {
|
||||
DebugPrint("IP: %d.%d.%d.%d\n" _C_ NIPQUAD(ntohl(NetLocalAddrs[i])));
|
||||
#if 0 // FIXME: need a working interface check
|
||||
unsigned long ips[10];
|
||||
int networkNumInterfaces = NetSocketAddr(NetworkFildes, ips, 10);
|
||||
if (networkNumInterfaces) {
|
||||
DebugPrint("Num IP: %d\n" _C_ networkNumInterfaces);
|
||||
for (int i = 0; i < networkNumInterfaces; ++i) {
|
||||
DebugPrint("IP: %d.%d.%d.%d\n" _C_ NIPQUAD(ntohl(ips[i])));
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "NETWORK: Not connected to any external IPV4-network, aborting\n");
|
||||
|
@ -609,7 +604,6 @@ void InitNetwork2()
|
|||
memset(NetworkSyncSeeds, 0, sizeof(NetworkSyncSeeds));
|
||||
memset(NetworkSyncHashs, 0, sizeof(NetworkSyncHashs));
|
||||
memset(PlayerQuit, 0, sizeof(PlayerQuit));
|
||||
memset(NetworkStatus, 0, sizeof(NetworkStatus));
|
||||
memset(NetworkLastFrame, 0, sizeof(NetworkLastFrame));
|
||||
}
|
||||
|
||||
|
@ -979,9 +973,6 @@ void NetworkEvent()
|
|||
}
|
||||
|
||||
// Receive statistic
|
||||
if (n > NetworkStatus[player]) {
|
||||
NetworkStatus[player] = n;
|
||||
}
|
||||
NetworkLastFrame[player] = FrameCounter;
|
||||
|
||||
// Place in network in
|
||||
|
|
|
@ -438,7 +438,6 @@ static void Usage()
|
|||
"\t-I addr\t\tNetwork address to use\n"
|
||||
"\t-l\t\tDisable command log\n"
|
||||
"\t-L lag\t\tNetwork lag in # frames (default 10 = 333ms)\n"
|
||||
"\t-n server\tNetwork server host preset\n"
|
||||
"\t-N name\t\tName of the player\n"
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
"\t-o\t\tDo not use OpenGL or OpenGL ES 1.1\n"
|
||||
|
@ -500,7 +499,7 @@ static void RedirectOutput()
|
|||
void ParseCommandLine(int argc, char **argv, Parameters ¶meters)
|
||||
{
|
||||
for (;;) {
|
||||
switch (getopt(argc, argv, "c:d:D:eE:FhI:lL:n:N:oOP:s:S:U:v:W?")) {
|
||||
switch (getopt(argc, argv, "c:d:D:eE:FhI:lL:N:oOP:s:S:U:v:W?")) {
|
||||
case 'c':
|
||||
parameters.luaStartFilename = optarg;
|
||||
continue;
|
||||
|
@ -539,9 +538,6 @@ void ParseCommandLine(int argc, char **argv, Parameters ¶meters)
|
|||
ExitFatal(-1);
|
||||
}
|
||||
continue;
|
||||
case 'n':
|
||||
NetworkArg = optarg;
|
||||
continue;
|
||||
case 'N':
|
||||
parameters.LocalPlayerName = optarg;
|
||||
continue;
|
||||
|
|
Loading…
Add table
Reference in a new issue