Old network api leftovers removed.
This commit is contained in:
parent
9f9a8da6d4
commit
571064df43
6 changed files with 8 additions and 569 deletions
doc
src
|
@ -841,6 +841,7 @@
|
|||
<LI>Fixed bug #562548: Number of opponents doesn't matter (from
|
||||
Jimmy Salmon).
|
||||
<LI>Added support for repeating keys in input fields (from Jimmy Salmon).
|
||||
<LI>Old command line network setup api is gone.
|
||||
</UL>
|
||||
</UL>
|
||||
|
||||
|
|
|
@ -181,32 +181,6 @@ global void CreateGame(char* filename, WorldMap* map)
|
|||
if (s) {
|
||||
free(s);
|
||||
}
|
||||
|
||||
#if 0 /* WILL NOW BE DONE BY MENU CODE.. */
|
||||
//
|
||||
// Network by command line
|
||||
//
|
||||
if( NetworkFildes!=-1 ) {
|
||||
if( NetPlayers>1 || NetworkArg ) {
|
||||
//
|
||||
// Server
|
||||
//
|
||||
if (NetPlayers > 1) {
|
||||
NetworkServerSetup(map);
|
||||
DebugLevel0Fn("Server setup ready\n");
|
||||
//
|
||||
// Client
|
||||
//
|
||||
} else if (NetworkArg) {
|
||||
NetworkClientSetup(map);
|
||||
DebugLevel0Fn("Client setup ready\n");
|
||||
}
|
||||
} else {
|
||||
ExitNetwork1();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
GameCycle=0;
|
||||
|
|
|
@ -193,9 +193,6 @@ extern ServerSetup LocalSetupState; /// Network menu: Multiplayer Client Menu se
|
|||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
extern void NetworkServerSetup(WorldMap *map); /// Connection server setup
|
||||
extern void NetworkClientSetup(WorldMap *map); /// Connection client setup
|
||||
extern void NetworkSetupArgs(void); /// Setup command line connection parameters
|
||||
extern void NetworkServerStartGame(void); /// Server user has finally hit the start game button
|
||||
extern void NetworkConnectSetupGame(void); /// Assign Player slot, evaluate Setup state..
|
||||
|
||||
|
|
|
@ -87,529 +87,8 @@ local int NetworkServerPort = NetworkDefaultPort; /// Server network port to use
|
|||
/**@name api */
|
||||
//@{
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// OLD API init..
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
** Setup command line connection parameters
|
||||
*/
|
||||
global void NetworkSetupArgs(void)
|
||||
{
|
||||
int i;
|
||||
char* s;
|
||||
|
||||
DebugLevel0Fn("%d players\n" _C_ NetPlayers);
|
||||
DebugLevel0Fn("%s arg\n" _C_ NetworkArg);
|
||||
|
||||
if (NetworkPort == NetworkDefaultPort && NetworkArg) {
|
||||
i = strtol(NetworkArg, &s, 0);
|
||||
if (s != NetworkArg && (*s == ':' || *s == '\0')) {
|
||||
if (*s == ':')
|
||||
s++;
|
||||
NetworkArg = s;
|
||||
NetworkPort = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
** Server Setup.
|
||||
*/
|
||||
global void NetworkServerSetup(WorldMap *map)
|
||||
{
|
||||
int i, j, n;
|
||||
char buf[1024];
|
||||
InitMessage *msg;
|
||||
InitMessage message;
|
||||
Acknowledge acknowledge;
|
||||
int num[PlayerMax];
|
||||
|
||||
// Prepare reply message:
|
||||
message.Type = MessageInitConfig;
|
||||
message.SubType = ICMGameFull; // default: reject connnection
|
||||
|
||||
message.FreeCraft = htonl(FreeCraftVersion);
|
||||
message.Version = htonl(NetworkProtocolVersion);
|
||||
message.Lag = htonl(NetworkLag);
|
||||
message.Updates = htonl(NetworkUpdates);
|
||||
if (map->Info) {
|
||||
message.MapUID = htonl(map->Info->MapUID);
|
||||
} else {
|
||||
message.MapUID = 0L;
|
||||
}
|
||||
|
||||
//
|
||||
// Wait for all clients to connect.
|
||||
//
|
||||
DebugLevel1Fn("Waiting for %d client(s)\n", NetPlayers - 1);
|
||||
acknowledge.Type = MessageInitReply;
|
||||
msg = (InitMessage *)buf;
|
||||
for (i = 1; i < NetPlayers;) {
|
||||
if ((n = NetRecvUDP(NetworkFildes, &buf, sizeof(buf))) < 0) {
|
||||
ExitFatal(-1);
|
||||
}
|
||||
|
||||
if (msg->Type != MessageInitHello || n != sizeof(*msg)) {
|
||||
DebugLevel0Fn("Wrong message\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// FIXME: ARI: Ignoring all non-supported subtypes here - add chat, client-quit, etc...
|
||||
if (msg->SubType != ICMHello) {
|
||||
DebugLevel0Fn("Unsupported InitHello Subtype %d\n", (int)msg->SubType);
|
||||
continue;
|
||||
}
|
||||
|
||||
DebugLevel0Fn("Received InitHello %d:%d(%d) from %d.%d.%d.%d:%d\n",
|
||||
msg->Type, msg->SubType, n, NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort));
|
||||
|
||||
if (ntohl(msg->FreeCraft) != FreeCraftVersion) {
|
||||
fprintf(stderr, "Incompatible FreeCraft version "
|
||||
FreeCraftFormatString " <-> "
|
||||
FreeCraftFormatString "\n",
|
||||
FreeCraftFormatArgs((int)ntohl(msg->FreeCraft)),
|
||||
FreeCraftFormatArgs(FreeCraftVersion));
|
||||
message.SubType = ICMEngineMismatch; // FreeCraft engine version doesn't match
|
||||
n = NetSendUDP(NetworkFildes, NetLastHost, NetLastPort, &message,
|
||||
sizeof(message));
|
||||
DebugLevel0Fn("Sending InitConfig Message EngineMismatch: (%d) to %d.%d.%d.%d:%d\n",
|
||||
n, NIPQUAD(ntohl(NetLastHost)),ntohs(NetLastPort));
|
||||
continue;
|
||||
// ExitFatal(-1);
|
||||
}
|
||||
|
||||
if (ntohl(msg->Version) != NetworkProtocolVersion) {
|
||||
fprintf(stderr, "Incompatible network protocol version "
|
||||
NetworkProtocolFormatString " <-> "
|
||||
NetworkProtocolFormatString "\n",
|
||||
NetworkProtocolFormatArgs((int)ntohl(msg->Version)),
|
||||
NetworkProtocolFormatArgs(NetworkProtocolVersion));
|
||||
message.SubType = ICMProtocolMismatch; // Network protocol version doesn't match
|
||||
n = NetSendUDP(NetworkFildes, NetLastHost, NetLastPort, &message,
|
||||
sizeof(message));
|
||||
DebugLevel0Fn("Sending InitConfig Message ProtocolMismatch: (%d) to %d.%d.%d.%d:%d\n",
|
||||
n, NIPQUAD(ntohl(NetLastHost)),ntohs(NetLastPort));
|
||||
continue;
|
||||
// ExitFatal(-1);
|
||||
}
|
||||
n = 0;
|
||||
if (map->Info) {
|
||||
if (ntohl(msg->MapUID) != map->Info->MapUID) {
|
||||
n = 1;
|
||||
}
|
||||
} else {
|
||||
if (ntohl(msg->MapUID) != 0L) {
|
||||
n = 1;
|
||||
}
|
||||
}
|
||||
if (n) {
|
||||
fprintf(stderr,
|
||||
"FreeCraft maps do not match (0x%08x) <-> (0x%08x)\n",
|
||||
map->Info ? (unsigned int)map->Info->MapUID : 0,
|
||||
(unsigned int)ntohl(msg->MapUID));
|
||||
message.SubType = ICMMapUidMismatch; // MAP Uid doesn't match
|
||||
n = NetSendUDP(NetworkFildes, NetLastHost, NetLastPort, &message,
|
||||
sizeof(message));
|
||||
DebugLevel0Fn("Sending InitConfig Message MapUIDMismatch: (%d) to %d.%d.%d.%d:%d\n",
|
||||
n, NIPQUAD(ntohl(NetLastHost)),ntohs(NetLastPort));
|
||||
continue;
|
||||
// ExitFatal(-1);
|
||||
}
|
||||
|
||||
DebugLevel0Fn("Version=" FreeCraftFormatString
|
||||
", Network=" NetworkProtocolFormatString
|
||||
", Lag=%ld, Updates=%ld\n",
|
||||
FreeCraftFormatArgs((int)ntohl(msg->FreeCraft)),
|
||||
NetworkProtocolFormatArgs((int)ntohl(msg->Version)),
|
||||
(long)ntohl(msg->Lag), (long)ntohl(msg->Updates));
|
||||
|
||||
//
|
||||
// Warning: Server should control it!
|
||||
//
|
||||
if (ntohl(msg->Lag) != NetworkLag) {
|
||||
fprintf(stderr, "Incompatible network lag %ld-%d\n",
|
||||
(long)ntohl(msg->Lag), NetworkLag);
|
||||
}
|
||||
|
||||
if (ntohl(msg->Updates) != NetworkUpdates) {
|
||||
fprintf(stderr, "Incompatible network updates %ld-%d\n",
|
||||
(long)ntohl(msg->Updates), NetworkUpdates);
|
||||
}
|
||||
|
||||
// Lookup, if host is already known.
|
||||
for (n = 0; n < HostsCount; ++n) {
|
||||
if (Hosts[n].Host == NetLastHost && Hosts[n].Port == NetLastPort) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// A new client
|
||||
if (n == HostsCount) {
|
||||
Hosts[HostsCount].Host = NetLastHost;
|
||||
Hosts[HostsCount].Port = NetLastPort;
|
||||
memcpy(Hosts[HostsCount].PlyName, msg->u.Hosts[0].PlyName, 16);
|
||||
DebugLevel0Fn("New client %d.%d.%d.%d:%d [%s]\n",
|
||||
NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort), Hosts[HostsCount].PlyName);
|
||||
HostsCount++;
|
||||
++i;
|
||||
}
|
||||
|
||||
// Acknowledge the packet.
|
||||
n = NetSendUDP(NetworkFildes, NetLastHost, NetLastPort, &acknowledge,
|
||||
sizeof(acknowledge));
|
||||
DebugLevel0Fn("Sending ACK for InitHello (%d)\n", n);
|
||||
}
|
||||
|
||||
//
|
||||
// Assign the players.
|
||||
//
|
||||
// FIXME: ARI: selectable by 'Position' selector in Network setup menus!
|
||||
|
||||
// Make a list of the player slots.
|
||||
for (n = i = 0; i < NumPlayers; ++i) {
|
||||
if (Players[i].Type == PlayerPerson) {
|
||||
num[n] = i;
|
||||
DebugLevel3Fn("Player slot %i is available for a person\n", i);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
if (n < NetPlayers) {
|
||||
fprintf(stderr, "Not enough person slots\n");
|
||||
ExitFatal(-1);
|
||||
}
|
||||
|
||||
// Randomize them.
|
||||
for(i = 0; i<NetPlayers; ++i) {
|
||||
if(n>0) {
|
||||
int chosen=MyRand()%n;
|
||||
|
||||
DebugLevel2Fn("Assigning player %i to slot %i\n", i, chosen);
|
||||
Hosts[i].PlyNr=num[chosen];
|
||||
num[chosen]=num[n-1];
|
||||
--n;
|
||||
} else {
|
||||
Hosts[i].PlyNr=num[0];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Send all clients host:ports to all clients.
|
||||
//
|
||||
|
||||
// Prepare config message:
|
||||
message.SubType = ICMConfig;
|
||||
message.HostsCount = HostsCount + 1;
|
||||
for (i = 0; i < HostsCount; ++i) {
|
||||
message.u.Hosts[i].Host = Hosts[i].Host;
|
||||
message.u.Hosts[i].Port = Hosts[i].Port;
|
||||
memcpy(message.u.Hosts[i].PlyName, Hosts[i].PlyName, 16);
|
||||
message.u.Hosts[i].PlyNr = htons(Hosts[i].PlyNr);
|
||||
PlayerSetName(&Players[Hosts[i].PlyNr], Hosts[i].PlyName);
|
||||
}
|
||||
message.u.Hosts[i].Host = 0;
|
||||
message.u.Hosts[i].Port = 0; // marks the server
|
||||
memcpy(message.u.Hosts[i].PlyName, NetworkName, 16);
|
||||
message.u.Hosts[i].PlyNr = htons(Hosts[i].PlyNr);
|
||||
|
||||
DebugLevel3Fn("Player here %d\n", Hosts[i].PlyNr);
|
||||
ThisPlayer = &Players[Hosts[i].PlyNr];
|
||||
PlayerSetName(ThisPlayer, NetworkName);
|
||||
|
||||
DebugLevel1Fn("Ready, sending InitConfig to %d host(s)\n", HostsCount);
|
||||
//
|
||||
// Send all clients host:ports to all clients.
|
||||
//
|
||||
for (j = HostsCount; j;) {
|
||||
|
||||
// Send to all clients.
|
||||
for (i = 0; i < HostsCount; ++i) {
|
||||
if (num[i] != -1) { // already acknowledged
|
||||
unsigned long host;
|
||||
int port;
|
||||
|
||||
host = message.u.Hosts[i].Host;
|
||||
port = message.u.Hosts[i].Port;
|
||||
message.u.Hosts[i].Host = message.u.Hosts[i].Port = 0;
|
||||
n = NetSendUDP(NetworkFildes, host, port, &message,
|
||||
sizeof(message));
|
||||
DebugLevel0Fn("Sending InitConfig Message Config (%d) to %d.%d.%d.%d:%d\n",
|
||||
n, NIPQUAD(ntohl(host)), ntohs(port));
|
||||
message.u.Hosts[i].Host = host;
|
||||
message.u.Hosts[i].Port = port;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for acknowledge
|
||||
while (j && NetSocketReady(NetworkFildes, 1000)) {
|
||||
if ((n = NetRecvUDP(NetworkFildes, &buf, sizeof(buf))) < 0) {
|
||||
DebugLevel0Fn("*Receive ack failed: (%d) from %d.%d.%d.%d:%d\n",
|
||||
n, NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort));
|
||||
continue;
|
||||
}
|
||||
|
||||
// DebugLevel0Fn("Received ack %d(%d) from %d.%d.%d.%d:%d\n",
|
||||
// msg->Type,n,
|
||||
// NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort));
|
||||
|
||||
if (msg->Type == MessageInitHello && n == sizeof(*msg)) {
|
||||
DebugLevel0Fn("Acknowledge for InitHello was lost\n");
|
||||
|
||||
// Acknowledge the hello packets.
|
||||
acknowledge.Type = MessageInitReply;
|
||||
n = NetSendUDP(NetworkFildes, NetLastHost, NetLastPort, &acknowledge,
|
||||
sizeof(acknowledge));
|
||||
DebugLevel0Fn("Sending ack for InitHello (%d)\n", n);
|
||||
} else {
|
||||
DebugLevel0Fn("Got ack for InitConfig: (%d) from %d.%d.%d.%d:%d\n",
|
||||
n, NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort));
|
||||
|
||||
for (i = 0; i < HostsCount; ++i) {
|
||||
if (NetLastHost == Hosts[i].Host
|
||||
&& NetLastPort == Hosts[i].Port
|
||||
&& msg->Type == MessageInitReply
|
||||
&& n == 1) {
|
||||
if (num[i] != -1) {
|
||||
num[i] = -1;
|
||||
j--;
|
||||
DebugLevel0Fn("Removing host (j = %d)\n", j);
|
||||
} else {
|
||||
DebugLevel0Fn("Already removed host\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DebugLevel0Fn("DONE: All configs acked - starting game\n");
|
||||
}
|
||||
|
||||
/**
|
||||
** Client Setup.
|
||||
*/
|
||||
global void NetworkClientSetup(WorldMap *map)
|
||||
{
|
||||
char buf[1024];
|
||||
InitMessage *msg;
|
||||
InitMessage message;
|
||||
Acknowledge acknowledge;
|
||||
unsigned long host;
|
||||
int port;
|
||||
char *cp;
|
||||
int i;
|
||||
int n;
|
||||
|
||||
// Parse server address.
|
||||
cp = strchr(NetworkArg, ':');
|
||||
if (cp) {
|
||||
*cp = '\0';
|
||||
port = htons(atoi(cp + 1));
|
||||
NetworkServerPort = htons(port);
|
||||
host = NetResolveHost(NetworkArg);
|
||||
*cp = ':';
|
||||
} else {
|
||||
port = htons(NetworkPort);
|
||||
NetworkServerPort = htons(port);
|
||||
host = NetResolveHost(NetworkArg);
|
||||
}
|
||||
if (host == INADDR_NONE) {
|
||||
fprintf(stderr, "Can't resolve host %s\n", NetworkArg);
|
||||
ExitFatal(-1);
|
||||
}
|
||||
DebugLevel0Fn("Server host:port %d.%d.%d.%d:%d\n",
|
||||
NIPQUAD(ntohl(host)), ntohs(port));
|
||||
|
||||
//
|
||||
// Connecting to server
|
||||
//
|
||||
|
||||
HostsCount = 0;
|
||||
|
||||
message.Type = MessageInitHello;
|
||||
message.SubType = ICMHello;
|
||||
message.FreeCraft = htonl(FreeCraftVersion);
|
||||
message.Version = htonl(NetworkProtocolVersion);
|
||||
message.Lag = htonl(NetworkLag);
|
||||
message.Updates = htonl(NetworkUpdates);
|
||||
memcpy(message.u.Hosts[0].PlyName, NetworkName, 16);
|
||||
if (map->Info) {
|
||||
message.MapUID = htonl(map->Info->MapUID);
|
||||
} else {
|
||||
message.MapUID = 0L;
|
||||
}
|
||||
msg = (InitMessage *)buf;
|
||||
for (;;) {
|
||||
n = NetSendUDP(NetworkFildes, host, port, &message, sizeof(message));
|
||||
DebugLevel0Fn("Sending hello (%d)\n", n);
|
||||
|
||||
// Wait for answer (timeout 1/2s)
|
||||
if (NetSocketReady(NetworkFildes, 500)) {
|
||||
if ((n = NetRecvUDP(NetworkFildes, &buf, sizeof(buf))) < 0) {
|
||||
ExitFatal(-1);
|
||||
}
|
||||
DebugLevel0Fn("Received reply? %d:%d(%d) %d.%d.%d.%d:%d\n",
|
||||
msg->Type, msg->SubType, n,
|
||||
NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort));
|
||||
|
||||
IfDebug(
|
||||
if (NetLastHost == MyHost && NetLastPort == MyPort) {
|
||||
fprintf(stderr, "Network client setup: Talking to myself!\n");
|
||||
ExitFatal(-1);
|
||||
}
|
||||
);
|
||||
|
||||
if (NetLastHost == host && NetLastPort == port) {
|
||||
if (msg->Type == MessageInitReply && n == 1) {
|
||||
break;
|
||||
}
|
||||
if (msg->Type == MessageInitConfig && n == sizeof(InitMessage)) {
|
||||
if (msg->SubType == ICMConfig) {
|
||||
// lost ACK - but Config got through!
|
||||
break;
|
||||
}
|
||||
switch(msg->SubType) {
|
||||
case ICMEngineMismatch:
|
||||
fprintf(stderr, "Incompatible FreeCraft version "
|
||||
FreeCraftFormatString " <-> "
|
||||
FreeCraftFormatString "\n",
|
||||
FreeCraftFormatArgs((int)ntohl(msg->FreeCraft)),
|
||||
FreeCraftFormatArgs(FreeCraftVersion));
|
||||
ExitFatal(-1);
|
||||
|
||||
case ICMProtocolMismatch:
|
||||
fprintf(stderr, "Incompatible network protocol version "
|
||||
NetworkProtocolFormatString " <-> "
|
||||
NetworkProtocolFormatString "\n",
|
||||
NetworkProtocolFormatArgs((int)ntohl(msg->Version)),
|
||||
NetworkProtocolFormatArgs(NetworkProtocolVersion));
|
||||
ExitFatal(-1);
|
||||
|
||||
case ICMEngineConfMismatch: // FIXME: Not Implemented yet
|
||||
ExitFatal(-1);
|
||||
|
||||
case ICMMapUidMismatch:
|
||||
fprintf(stderr, "FreeCraft maps do not match (0x%08x) <-> (0x%08x)\n",
|
||||
map->Info ?
|
||||
(unsigned int)map->Info->MapUID : 0,
|
||||
(unsigned int)ntohl(msg->MapUID));
|
||||
ExitFatal(-1);
|
||||
|
||||
case ICMGameFull:
|
||||
fprintf(stderr, "Server is full!\n");
|
||||
ExitFatal(-1);
|
||||
|
||||
case ICMServerQuit:
|
||||
fprintf(stderr, "Server has quit!\n");
|
||||
ExitFatal(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DebugLevel0Fn("Received wrong packet\n");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Wait for addresses of other clients.
|
||||
//
|
||||
DebugLevel0Fn("Waiting for ClientConfig\n");
|
||||
acknowledge.Type = MessageInitReply;
|
||||
for (;;) {
|
||||
if ((n = NetRecvUDP(NetworkFildes, &buf, sizeof(buf))) < 0) {
|
||||
ExitFatal(-1);
|
||||
}
|
||||
|
||||
DebugLevel0Fn("Received config? %d(%d) %d.%d.%d.%d:%d\n",
|
||||
msg->Type,n,
|
||||
NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort));
|
||||
|
||||
if (NetLastHost != host || NetLastPort != port
|
||||
|| msg->Type != MessageInitConfig || n != sizeof(InitMessage)) {
|
||||
DebugLevel0Fn("Received wrong packet\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// FIXME: ARI: add switch over SubType here (ServerQuit, etc)
|
||||
|
||||
DebugLevel0Fn("Received ClientConfig (HostsCount = %d)\n", (int)msg->HostsCount);
|
||||
|
||||
NetworkLag = ntohl(msg->Lag);
|
||||
NetworkUpdates = ntohl(msg->Updates);
|
||||
|
||||
for (i = 0; i < msg->HostsCount - 1; ++i) {
|
||||
if (msg->u.Hosts[i].Host || msg->u.Hosts[i].Port) {
|
||||
Hosts[HostsCount].Host = msg->u.Hosts[i].Host;
|
||||
Hosts[HostsCount].Port = msg->u.Hosts[i].Port;
|
||||
Hosts[HostsCount].PlyNr = ntohs(msg->u.Hosts[i].PlyNr);
|
||||
memcpy(Hosts[HostsCount].PlyName, msg->u.Hosts[i].PlyName, 16);
|
||||
PlayerSetName(&Players[Hosts[HostsCount].PlyNr], Hosts[HostsCount].PlyName);
|
||||
HostsCount++;
|
||||
DebugLevel0Fn("Client %d = %d.%d.%d.%d:%d [%s]\n",
|
||||
ntohs(msg->u.Hosts[i].PlyNr), NIPQUAD(ntohl(msg->u.Hosts[i].Host)),
|
||||
ntohs(msg->u.Hosts[i].Port), msg->u.Hosts[i].PlyName);
|
||||
} else { // Own client
|
||||
DebugLevel0Fn("SELF %d [%s]\n", ntohs(msg->u.Hosts[i].PlyNr),
|
||||
msg->u.Hosts[i].PlyName);
|
||||
ThisPlayer = &Players[ntohs(msg->u.Hosts[i].PlyNr)];
|
||||
PlayerSetName(ThisPlayer, NetworkName);
|
||||
}
|
||||
}
|
||||
|
||||
Hosts[HostsCount].Host = host;
|
||||
Hosts[HostsCount].Port = port;
|
||||
DebugLevel0Fn("SERVER %d [%s]\n", ntohs(msg->u.Hosts[i].PlyNr),
|
||||
msg->u.Hosts[i].PlyName);
|
||||
Hosts[HostsCount].PlyNr = ntohs(msg->u.Hosts[i].PlyNr);
|
||||
memcpy(Hosts[HostsCount].PlyName, msg->u.Hosts[i].PlyName, 16);
|
||||
PlayerSetName(&Players[Hosts[HostsCount].PlyNr], Hosts[HostsCount].PlyName);
|
||||
HostsCount++;
|
||||
|
||||
// Acknowledge the packet.
|
||||
n = NetSendUDP(NetworkFildes, NetLastHost, NetLastPort, &acknowledge,
|
||||
sizeof(acknowledge));
|
||||
DebugLevel0Fn("Sending ClientConfig ack (%d)\n", n);
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Wait for lost acknowledge (timeout 3s)
|
||||
//
|
||||
while (NetSocketReady(NetworkFildes, 3000)) {
|
||||
if ((n = NetRecvUDP(NetworkFildes, &buf, sizeof(buf))) < 0) {
|
||||
ExitFatal(-1);
|
||||
}
|
||||
|
||||
DebugLevel3Fn("Received config? %d(%d) %d.%d.%d.%d:%d\n",
|
||||
msg->Type, n,
|
||||
NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort));
|
||||
|
||||
if (NetLastHost == host && NetLastPort == port
|
||||
&& msg->Type == MessageInitConfig && n == sizeof(InitMessage)) {
|
||||
|
||||
DebugLevel0Fn("Received DUP ClientConfig (SERVER LOST ACK)\n");
|
||||
|
||||
// Acknowledge the packets.
|
||||
n = NetSendUDP(NetworkFildes, NetLastHost, NetLastPort, &acknowledge,
|
||||
sizeof(acknowledge));
|
||||
DebugLevel0Fn("Sending DUP ClientConfig ack (%d)\n", n);
|
||||
continue;
|
||||
}
|
||||
|
||||
// if (msg->Type > MessageInitConfig && n == sizeof(NetworkPacket))
|
||||
if (msg->Type > MessageInitConfig) {
|
||||
DebugLevel0Fn("Game message received - server has started game\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
DebugLevel3Fn("DONE: All client have received config - starting game\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// NEW API
|
||||
// Functions
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
@ -901,10 +380,6 @@ global void NetworkServerStartGame(void)
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
printf("\n"); for (i=0;i<PlayerMax;i++) printf("% 2d: %d\n", i, org[i]); printf("\n");
|
||||
#endif
|
||||
|
||||
// Compact host list.. (account for computer/closed slots in the middle..)
|
||||
for (i = 1; i < h; i++) {
|
||||
if (Hosts[i].PlyNr == 0) {
|
||||
|
@ -962,10 +437,6 @@ global void NetworkServerStartGame(void)
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
printf("\n"); for (i=0;i<PlayerMax;i++) printf("% 2d: %d\n", i, org[i]); printf("\n");
|
||||
#endif
|
||||
|
||||
// Complete all setup states for the assigned slots.
|
||||
for (i = 0; i < PlayerMax; i++) {
|
||||
num[i] = 1;
|
||||
|
|
|
@ -294,7 +294,7 @@ global void CreatePlayer(int type)
|
|||
// Take first slot for person on this computer,
|
||||
// fill other with computer players.
|
||||
//
|
||||
if( type==PlayerPerson && !NetPlayers && !NetworkArg ) {
|
||||
if( type==PlayerPerson && !NetPlayers ) {
|
||||
if( !ThisPlayer ) {
|
||||
ThisPlayer=player;
|
||||
} else {
|
||||
|
|
|
@ -1049,7 +1049,7 @@ Use it at your own risk.\n\n");
|
|||
|
||||
InitUnitsMemory(); // Units memory management
|
||||
PreMenuSetup(); // Load everything needed for menus
|
||||
NetworkSetupArgs(); // Evaluate optional command line parameters
|
||||
|
||||
WaitForInput(20); // Show game intro
|
||||
|
||||
MenuLoop(MapName,&TheMap); // Enter the menu loop
|
||||
|
@ -1115,11 +1115,10 @@ local void Usage(void)
|
|||
\t-f factor\tComputer units cost factor\n\
|
||||
\t-h\t\tHelp shows this page\n\
|
||||
\t-l\t\tEnable command log to \"command.log\"\n\
|
||||
\t-p players\tDON'T USE! Number of players\n\
|
||||
\t-P port\t\tNetwork port to use (menu code only)\n\
|
||||
\t-n [localport:]host[:port]\tNetwork argument (port default 6660)\n\
|
||||
\t-P port\t\tNetwork port to use\n\
|
||||
\t-n server\tNetwork server host preset\n\
|
||||
\t-L lag\t\tNetwork lag in # frames (default 10 = 333ms)\n\
|
||||
\t-U update\tNetwork update rate in # frames (default 5=6x pro s)\n\
|
||||
\t-U update\tNetwork update rate in # frames (default 5=6x per s)\n\
|
||||
\t-N name\t\tName of the player\n\
|
||||
\t-s sleep\tNumber of frames for the AI to sleep before it starts\n\
|
||||
\t-t factor\tComputer units built time factor\n\
|
||||
|
@ -1169,7 +1168,7 @@ global int main(int argc,char** argv)
|
|||
// Parse commandline
|
||||
//
|
||||
for( ;; ) {
|
||||
switch( getopt(argc,argv,"c:d:f:hln:p:P:s:t:v:wD:N:FL:S:U:W?") ) {
|
||||
switch( getopt(argc,argv,"c:d:f:hln:P:s:t:v:wD:N:FL:S:U:W?") ) {
|
||||
case 'c':
|
||||
CclStartFile=optarg;
|
||||
continue;
|
||||
|
@ -1182,9 +1181,6 @@ global int main(int argc,char** argv)
|
|||
case 'l':
|
||||
CommandLogEnabled=1;
|
||||
continue;
|
||||
case 'p':
|
||||
NetPlayers=atoi(optarg);
|
||||
continue;
|
||||
case 'P':
|
||||
NetworkPort=atoi(optarg);
|
||||
continue;
|
||||
|
|
Loading…
Add table
Reference in a new issue