A simple hack to make 'host player Id' visible to all players,I dont have
the time to test it atm,though it should be a good start for bigger changes.

I browsed thru the netcode stuff,seems with hostId visible to all
players,the synchronization can be improved dramatically if we can find a
way to tell whether a client's request is valid or not,my ideas to make
current netcode more usable/less desync:

1.Clients send update requests to Host instead of broadcasting the packets
blindly(just some simple player id changes to netsend functions)
2.Host/Clients update their own copy of game,this is unavoidable due to the
way the current gameloop works(requires no changes)
3.Host do validity checks on the requests.(not sure how to implement
yet,maybe just skip this step if we want something usable soon)
4.Host update its copy of game upon the valid requests(require minimal
checks)
5.Host sends 'sync checks' to all clients.(just remove netsend/broadcast for
'clients' players)
6.Clients only do sync stuff against Host's copy of game instead of sync
with all other players'.(remove sync stuff from host player)

Any thoughts/Ideas? =)
Index: lib/netplay/netplay.c
===================================================================
--- lib/netplay/netplay.c       (revision 1631)
+++ lib/netplay/netplay.c       (working copy)
@@ -1470,6 +1470,9 @@
                        strcpy(players[NetPlay.dpidPlayer].name, playername);
                        players[NetPlay.dpidPlayer].flags = 0;
 
+                       //Watermelon:request the host id
+                       requestHostId();
+
                        return TRUE;
                }
        }
Index: lib/netplay/netplay.h
===================================================================
--- lib/netplay/netplay.h       (revision 1631)
+++ lib/netplay/netplay.h       (working copy)
@@ -93,6 +93,7 @@
 typedef struct {
        GAMESTRUCT      games[MaxGames];                // the collection of 
games
        PLAYER          players[MaxNumberOfPlayers];    // the array of players.
+       UBYTE           hostId;                                 
//Watermelon:the host player id
        uint32_t        playercount;                    // number of players in 
game.
 
        uint32_t        dpidPlayer;                     // ID of player created
Index: src/multiplay.c
===================================================================
--- src/multiplay.c     (revision 1631)
+++ src/multiplay.c     (working copy)
@@ -715,6 +715,27 @@
                        case NET_LASSAT:
                                recvLasSat(&msg);
                                break;
+                       //Watermelon:give the host id out upon request via 
broadcast
+                       case NET_HOSTID_REQ:
+                               if (NetPlay.bHost)
+                               {
+                                       sendHostId(&msg);
+                               }
+                               break;
+                       //Watermelon:recv the host id
+                       case NET_HOSTID:
+                               recvHostId(&msg);
+                               break;
+                       //Watermelon:recv the host test request,reply 'ok' if 
reciever is host
+                       case NET_HOST_TEST_REQ:
+                               if (NetPlay.bHost)
+                               {
+                                       sendHostOK(&msg);
+                               }
+                               break;
+                       case NET_HOST_TEST_OK:
+                               recvHostOK(&msg);
+                               break;
 
                        default:
                                break;
@@ -1964,3 +1985,86 @@
 
        return i;
 }
+
+BOOL requestHostId(void)
+{
+       NETMSG m;
+       
+       m.body[0] = (char)selectedPlayer;
+
+       m.size = sizeof(char);
+
+       m.type = NET_HOSTID_REQ;
+
+       return( NETbcast(&m,FALSE) );
+}
+
+//Sends hostId to all connected players
+BOOL sendHostId(void)
+{
+       NETMSG m;
+
+       m.body[0] = (char)selectedPlayer;                       // send player 
number
+
+       m.size = sizeof(char);
+
+       m.type = NET_HOSTID;
+
+       return( NETbcast(&m,FALSE)      );
+}
+
+//recv host id from host
+void recvHostId(NETMSG *m)
+{
+       UBYTE   player;
+
+       player = m->body[0];
+
+       ASSERT(player < MAX_PLAYERS, "host player id out of range!");
+
+       NetPlay.hostId = player;
+}
+
+//send a test request to see if host is still up
+BOOL sendHostTest(void)
+{
+       NETMSG m;
+
+       m.body[0] = (char)selectedPlayer;                       // send player 
number
+
+       m.size = sizeof(char);
+
+       m.type = NET_HOST_TEST_REQ;
+
+       return( NETsend(&m, NetPlay.hostId, FALSE) );
+}
+
+//response to test request
+BOOL sendHostOK(NETMSG *msg)
+{
+       NETMSG m;
+       UBYTE player = (UBYTE)msg->body[0];
+
+       ASSERT(player < MAX_PLAYERS, "host player id out of range!");
+
+       m.body[0] = msg->body[0];                       // send player number
+
+       m.size = sizeof(char);
+
+       m.type = NET_HOST_TEST_OK;
+
+       return( NETsend(&m, player, TRUE) );
+}
+
+//recv test OK results
+BOOL recvHostOK(NETMSG *m)
+{
+       UBYTE   player;
+
+       player = m->body[0];
+
+       ASSERT(player < MAX_PLAYERS, "host player id out of range!");
+
+       return TRUE;
+}
+
Index: src/multiplay.h
===================================================================
--- src/multiplay.h     (revision 1631)
+++ src/multiplay.h     (working copy)
@@ -90,7 +90,12 @@
        NET_TEAMS_ON,
        NET_BEACONMSG,
        NET_SET_TEAMS,
-       NET_TEAMREQUEST
+       NET_TEAMREQUEST,
+       
+       NET_HOSTID,                             //host player id
+       NET_HOSTID_REQ,                 //requesting for host player id
+       NET_HOST_TEST_REQ,              //test whether host is still up or not
+       NET_HOST_TEST_OK,               //host's response to NET_HOST_TEST_REQ
 
 } MESSAGE_TYPES;
 
Index: src/multirecv.h
===================================================================
--- src/multirecv.h     (revision 1631)
+++ src/multirecv.h     (working copy)
@@ -71,3 +71,9 @@
 
 extern BOOL recvTextMessageAI          (NETMSG *pMsg);         //AI 
multiplayer message
 extern BOOL    recvTeamRequest                 (NETMSG *pMsg);
+
+extern BOOL sendHostId(void);
+extern void recvHostId(NETMSG *m);
+extern BOOL sendHostTest(void)
+extern BOOL sendHostOK(NETMSG *msg)
+extern BOOL recvHostOK(NETMSG *m)
_______________________________________________
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev

Reply via email to