diff options
Diffstat (limited to 'src/net_structrw.c')
-rw-r--r-- | src/net_structrw.c | 242 |
1 files changed, 223 insertions, 19 deletions
diff --git a/src/net_structrw.c b/src/net_structrw.c index c2e878fa..84c115fa 100644 --- a/src/net_structrw.c +++ b/src/net_structrw.c @@ -21,16 +21,46 @@ // Reading and writing various structures into packets // +#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <ctype.h> -#include "doomdef.h" +#include "doomtype.h" #include "net_packet.h" #include "net_structrw.h" +void NET_WriteConnectData(net_packet_t *packet, net_connect_data_t *data) +{ + NET_WriteInt8(packet, data->gamemode); + NET_WriteInt8(packet, data->gamemission); + NET_WriteInt8(packet, data->lowres_turn); + NET_WriteInt8(packet, data->drone); + NET_WriteInt8(packet, data->max_players); + NET_WriteInt8(packet, data->is_freedoom); + NET_WriteMD5Sum(packet, data->wad_md5sum); + NET_WriteMD5Sum(packet, data->deh_md5sum); + NET_WriteInt8(packet, data->player_class); +} + +boolean NET_ReadConnectData(net_packet_t *packet, net_connect_data_t *data) +{ + return NET_ReadInt8(packet, (unsigned int *) &data->gamemode) + && NET_ReadInt8(packet, (unsigned int *) &data->gamemission) + && NET_ReadInt8(packet, (unsigned int *) &data->lowres_turn) + && NET_ReadInt8(packet, (unsigned int *) &data->drone) + && NET_ReadInt8(packet, (unsigned int *) &data->max_players) + && NET_ReadInt8(packet, (unsigned int *) &data->is_freedoom) + && NET_ReadMD5Sum(packet, data->wad_md5sum) + && NET_ReadMD5Sum(packet, data->deh_md5sum) + && NET_ReadInt8(packet, (unsigned int *) &data->player_class); +} + void NET_WriteSettings(net_packet_t *packet, net_gamesettings_t *settings) { + int i; + NET_WriteInt8(packet, settings->ticdup); NET_WriteInt8(packet, settings->extratics); NET_WriteInt8(packet, settings->deathmatch); @@ -45,24 +75,52 @@ void NET_WriteSettings(net_packet_t *packet, net_gamesettings_t *settings) NET_WriteInt8(packet, settings->new_sync); NET_WriteInt32(packet, settings->timelimit); NET_WriteInt8(packet, settings->loadgame); + NET_WriteInt8(packet, settings->num_players); + NET_WriteInt8(packet, settings->consoleplayer); + + for (i = 0; i < settings->num_players; ++i) + { + NET_WriteInt8(packet, settings->player_classes[i]); + } } boolean NET_ReadSettings(net_packet_t *packet, net_gamesettings_t *settings) { - return NET_ReadInt8(packet, (unsigned int *) &settings->ticdup) - && NET_ReadInt8(packet, (unsigned int *) &settings->extratics) - && NET_ReadInt8(packet, (unsigned int *) &settings->deathmatch) - && NET_ReadInt8(packet, (unsigned int *) &settings->nomonsters) - && NET_ReadInt8(packet, (unsigned int *) &settings->fast_monsters) - && NET_ReadInt8(packet, (unsigned int *) &settings->respawn_monsters) - && NET_ReadInt8(packet, (unsigned int *) &settings->episode) - && NET_ReadInt8(packet, (unsigned int *) &settings->map) - && NET_ReadSInt8(packet, &settings->skill) - && NET_ReadInt8(packet, (unsigned int *) &settings->gameversion) - && NET_ReadInt8(packet, (unsigned int *) &settings->lowres_turn) - && NET_ReadInt8(packet, (unsigned int *) &settings->new_sync) - && NET_ReadInt32(packet, (unsigned int *) &settings->timelimit) - && NET_ReadSInt8(packet, (signed int *) &settings->loadgame); + boolean success; + int i; + + success = NET_ReadInt8(packet, (unsigned int *) &settings->ticdup) + && NET_ReadInt8(packet, (unsigned int *) &settings->extratics) + && NET_ReadInt8(packet, (unsigned int *) &settings->deathmatch) + && NET_ReadInt8(packet, (unsigned int *) &settings->nomonsters) + && NET_ReadInt8(packet, (unsigned int *) &settings->fast_monsters) + && NET_ReadInt8(packet, (unsigned int *) &settings->respawn_monsters) + && NET_ReadInt8(packet, (unsigned int *) &settings->episode) + && NET_ReadInt8(packet, (unsigned int *) &settings->map) + && NET_ReadSInt8(packet, &settings->skill) + && NET_ReadInt8(packet, (unsigned int *) &settings->gameversion) + && NET_ReadInt8(packet, (unsigned int *) &settings->lowres_turn) + && NET_ReadInt8(packet, (unsigned int *) &settings->new_sync) + && NET_ReadInt32(packet, (unsigned int *) &settings->timelimit) + && NET_ReadSInt8(packet, (signed int *) &settings->loadgame) + && NET_ReadInt8(packet, (unsigned int *) &settings->num_players) + && NET_ReadSInt8(packet, (signed int *) &settings->consoleplayer); + + if (!success) + { + return false; + } + + for (i = 0; i < settings->num_players; ++i) + { + if (!NET_ReadInt8(packet, + (unsigned int *) &settings->player_classes[i])) + { + return false; + } + } + + return true; } boolean NET_ReadQueryData(net_packet_t *packet, net_querydata_t *query) @@ -131,6 +189,16 @@ void NET_WriteTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff, NET_WriteInt8(packet, diff->cmd.consistancy); if (diff->diff & NET_TICDIFF_CHATCHAR) NET_WriteInt8(packet, diff->cmd.chatchar); + if (diff->diff & NET_TICDIFF_RAVEN) + { + NET_WriteInt8(packet, diff->cmd.lookfly); + NET_WriteInt8(packet, diff->cmd.arti); + } + if (diff->diff & NET_TICDIFF_STRIFE) + { + NET_WriteInt8(packet, diff->cmd.buttons2); + NET_WriteInt8(packet, diff->cmd.inventory); + } } boolean NET_ReadTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff, @@ -197,6 +265,28 @@ boolean NET_ReadTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff, diff->cmd.chatchar = val; } + if (diff->diff & NET_TICDIFF_RAVEN) + { + if (!NET_ReadInt8(packet, &val)) + return false; + diff->cmd.lookfly = val; + + if (!NET_ReadInt8(packet, &val)) + return false; + diff->cmd.arti = val; + } + + if (diff->diff & NET_TICDIFF_STRIFE) + { + if (!NET_ReadInt8(packet, &val)) + return false; + diff->cmd.buttons2 = val; + + if (!NET_ReadInt8(packet, &val)) + return false; + diff->cmd.inventory = val; + } + return true; } @@ -217,6 +307,16 @@ void NET_TiccmdDiff(ticcmd_t *tic1, ticcmd_t *tic2, net_ticdiff_t *diff) diff->diff |= NET_TICDIFF_CONSISTANCY; if (tic2->chatchar != 0) diff->diff |= NET_TICDIFF_CHATCHAR; + + // Heretic/Hexen-specific + + if (tic1->lookfly != tic2->lookfly || tic2->arti != 0) + diff->diff |= NET_TICDIFF_RAVEN; + + // Strife-specific + + if (tic1->buttons2 != tic2->buttons2 || tic2->inventory != 0) + diff->diff |= NET_TICDIFF_STRIFE; } void NET_TiccmdPatch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest) @@ -240,6 +340,30 @@ void NET_TiccmdPatch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest) dest->chatchar = diff->cmd.chatchar; else dest->chatchar = 0; + + // Heretic/Hexen specific: + + if (diff->diff & NET_TICDIFF_RAVEN) + { + dest->lookfly = diff->cmd.lookfly; + dest->arti = diff->cmd.arti; + } + else + { + dest->arti = 0; + } + + // Strife-specific: + + if (diff->diff & NET_TICDIFF_STRIFE) + { + dest->buttons2 = diff->cmd.buttons2; + dest->inventory = diff->cmd.inventory; + } + else + { + dest->inventory = 0; + } } // @@ -265,14 +389,14 @@ boolean NET_ReadFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean return false; } - for (i=0; i<MAXPLAYERS; ++i) + for (i=0; i<NET_MAXPLAYERS; ++i) { cmd->playeringame[i] = (bitfield & (1 << i)) != 0; } // Read cmds - for (i=0; i<MAXPLAYERS; ++i) + for (i=0; i<NET_MAXPLAYERS; ++i) { if (cmd->playeringame[i]) { @@ -300,7 +424,7 @@ void NET_WriteFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean l bitfield = 0; - for (i=0; i<MAXPLAYERS; ++i) + for (i=0; i<NET_MAXPLAYERS; ++i) { if (cmd->playeringame[i]) { @@ -312,7 +436,7 @@ void NET_WriteFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean l // Write player ticcmds - for (i=0; i<MAXPLAYERS; ++i) + for (i=0; i<NET_MAXPLAYERS; ++i) { if (cmd->playeringame[i]) { @@ -321,6 +445,67 @@ void NET_WriteFullTiccmd(net_packet_t *packet, net_full_ticcmd_t *cmd, boolean l } } +void NET_WriteWaitData(net_packet_t *packet, net_waitdata_t *data) +{ + int i; + + NET_WriteInt8(packet, data->num_players); + NET_WriteInt8(packet, data->num_drones); + NET_WriteInt8(packet, data->max_players); + NET_WriteInt8(packet, data->is_controller); + NET_WriteInt8(packet, data->consoleplayer); + + for (i = 0; i < data->num_players && i < NET_MAXPLAYERS; ++i) + { + NET_WriteString(packet, data->player_names[i]); + NET_WriteString(packet, data->player_addrs[i]); + } + + NET_WriteMD5Sum(packet, data->wad_md5sum); + NET_WriteMD5Sum(packet, data->deh_md5sum); + NET_WriteInt8(packet, data->is_freedoom); +} + +boolean NET_ReadWaitData(net_packet_t *packet, net_waitdata_t *data) +{ + int i; + char *s; + + if (!NET_ReadInt8(packet, (unsigned int *) &data->num_players) + || !NET_ReadInt8(packet, (unsigned int *) &data->num_drones) + || !NET_ReadInt8(packet, (unsigned int *) &data->max_players) + || !NET_ReadInt8(packet, (unsigned int *) &data->is_controller) + || !NET_ReadSInt8(packet, (unsigned int *) &data->consoleplayer)) + { + return false; + } + + for (i = 0; i < data->num_players && i < NET_MAXPLAYERS; ++i) + { + s = NET_ReadString(packet); + + if (s == NULL || strlen(s) >= MAXPLAYERNAME) + { + return false; + } + + strcpy(data->player_names[i], s); + + s = NET_ReadString(packet); + + if (s == NULL || strlen(s) >= MAXPLAYERNAME) + { + return false; + } + + strcpy(data->player_addrs[i], s); + } + + return NET_ReadMD5Sum(packet, data->wad_md5sum) + && NET_ReadMD5Sum(packet, data->deh_md5sum) + && NET_ReadInt8(packet, (unsigned int *) &data->is_freedoom); +} + boolean NET_ReadMD5Sum(net_packet_t *packet, md5_digest_t digest) { unsigned int b; @@ -349,3 +534,22 @@ void NET_WriteMD5Sum(net_packet_t *packet, md5_digest_t digest) } } +// "Safe" version of puts, for displaying messages received from the +// network. + +void NET_SafePuts(char *s) +{ + char *p; + + // Do not do a straight "puts" of the string, as this could be + // dangerous (sending control codes to terminals can do all + // kinds of things) + + for (p=s; *p; ++p) + { + if (isprint(*p)) + putchar(*p); + } + + putchar('\n'); +} |