From fa75b6a63fd8f99c6effb30b940c54655d9d6c94 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Thu, 14 Feb 2002 09:05:33 +0000 Subject: [PATCH] Lotsa networking stuff from d1x --- main/multipow.c | 20 + main/multipow.h | 28 ++ main/netlist.c | 710 ++++++++++++++++++++++++++++++++ main/netpkt.c | 1032 +++++++++++++++++++++++++++++++++++++++++++++++ main/netpkt.h | 28 ++ main/reorder.h | 20 + 6 files changed, 1838 insertions(+) create mode 100644 main/multipow.c create mode 100644 main/multipow.h create mode 100644 main/netlist.c create mode 100644 main/netpkt.c create mode 100644 main/netpkt.h create mode 100644 main/reorder.h diff --git a/main/multipow.c b/main/multipow.c new file mode 100644 index 00000000..5969e15c --- /dev/null +++ b/main/multipow.c @@ -0,0 +1,20 @@ +#include "powerup.h" +#include "multipow.h" +#include "text.h" + +int multi_allow_powerup_mask[MAX_POWERUP_TYPES] = +{ NETFLAG_DOINVUL, 0, 0, NETFLAG_DOLASER, 0, 0, 0, 0, 0, 0, 0, 0, NETFLAG_DOQUAD, + NETFLAG_DOVULCAN, NETFLAG_DOSPREAD, NETFLAG_DOPLASMA, NETFLAG_DOFUSION, + NETFLAG_DOPROXIM, NETFLAG_DOHOMING, NETFLAG_DOHOMING, NETFLAG_DOSMART, + NETFLAG_DOMEGA, NETFLAG_DOVULCAN, NETFLAG_DOCLOAK, 0, NETFLAG_DOINVUL, 0, 0, 0 }; + +#if 0 +char *multi_allow_powerup_text[MULTI_ALLOW_POWERUP_MAX] = +{ "Laser upgrade", TXT_QUAD_LASERS, TXT_W_VULCAN, TXT_W_SPREADFIRE, TXT_W_PLASMA, + TXT_W_FUSION, TXT_W_H_MISSILE, TXT_W_S_MISSILE, TXT_W_M_MISSILE, TXT_W_P_BOMB, + "Cloaking", TXT_INVULNERABILITY }; +#endif +char *multi_allow_powerup_text[MULTI_ALLOW_POWERUP_MAX] = +{ "Laser upgrade", "Quad lasers", "Vulcan cannon", "Spreadfire cannon", "Plasma cannon", + "Fusion cannon", "Homing missiles", "Smart missiles", "Mega missiles", "Proximity bombs", + "Cloaking", "Invulnerability" }; diff --git a/main/multipow.h b/main/multipow.h new file mode 100644 index 00000000..d432680e --- /dev/null +++ b/main/multipow.h @@ -0,0 +1,28 @@ +#ifndef _MULTIPOW_H +#define _MULTIPOW_H +#include "powerup.h" + +#define NETFLAG_DOLASER 1 // 0x0000001 +#define NETFLAG_DOQUAD 2 // 0x0000002 +#define NETFLAG_DOVULCAN 4 // 0x0000004 +#define NETFLAG_DOSPREAD 8 // 0x0000008 +#define NETFLAG_DOPLASMA 16 // 0x0000010 +#define NETFLAG_DOFUSION 32 // 0x0000020 +#define NETFLAG_DOHOMING 64 // 0x0000040 +#define NETFLAG_DOSMART 128 // 0x0000080 +#define NETFLAG_DOMEGA 256 // 0x0000100 +#define NETFLAG_DOPROXIM 512 // 0x0000200 +#define NETFLAG_DOCLOAK 1024 // 0x0000400 +#define NETFLAG_DOINVUL 2048 // 0x0000800 +#define NETFLAG_DOPOWERUP 4095 // 0x0000fff mask for all powerup flags + +#define NETFLAG_SHORTPACKETS 0x1000000 +#define NETFLAG_DROP_VULCAN_AMMO 0x2000000 +#define NETFLAG_ENABLE_IGNORE_GHOST 0x4000000 +#define NETFLAG_ENABLE_RADAR 0x8000000 +#define NETFLAG_ENABLE_ALT_VULCAN 0x0100000 + +#define MULTI_ALLOW_POWERUP_MAX 12 +int multi_allow_powerup_mask[MAX_POWERUP_TYPES]; +extern char *multi_allow_powerup_text[MULTI_ALLOW_POWERUP_MAX]; +#endif diff --git a/main/netlist.c b/main/netlist.c new file mode 100644 index 00000000..95aa09db --- /dev/null +++ b/main/netlist.c @@ -0,0 +1,710 @@ +/* + * $Source: /cvs/cvsroot/d2x/main/netlist.c,v $ + * $Revision: 1.1 $ + * $Author: bradleyb $ + * $Date: 2002-02-14 09:05:33 $ + * + * Descent II-a-like network game join menu + * Arne de Bruijn, 1998 + * + * $Log: not supported by cvs2svn $ + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "pstypes.h" +#include "timer.h" +#include "gr.h" +#include "palette.h" +#include "inferno.h" +#include "mono.h" +#include "key.h" +#include "error.h" +#include "netmisc.h" +#include "network.h" +#include "ipx.h" +#include "game.h" +#include "multi.h" +#include "text.h" +//added 4/18/99 Matt Mueller - show radar in game info +#include "multipow.h" +//end addition -MM + +#include "gamefont.h" +#include "u_mem.h" + +#include "string.h" + +//added on 1/5/99 by Victor Rachels for missiondir +#include "cfile.h" +//end this section addition + +#define LINE_ITEMS 8 +#define MAX_TEXT_LEN 25 +// from network.c +extern int Network_games_changed; +extern netgame_info Active_games[MAX_ACTIVE_NETGAMES]; +extern AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES]; +extern int num_active_games; +extern int Network_socket; +void network_listen(); +void network_send_game_list_request(); +// bitblt.c +void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest); + +typedef struct bkg { + grs_canvas * menu_canvas; + grs_bitmap * saved; // The background under the menu. + grs_bitmap * background; + int background_is_sub; +} bkg; + +extern grs_bitmap nm_background; + +struct line_item { + int x, y; + int width; + char *value; +}; + +void network_draw_game(const netgame_info *game) { +} + +char *network_mode_text(const netgame_info *game) { + //edit 4/18/99 Matt Mueller - GTEAM? heh. Should be "TEAM" I think. + static char *names[4]={"ANRCHY", "TEAM", "ROBO", "COOP"}; + //end edit -MM +#ifndef SHAREWARE + if (game->gamemode >= 4 || + (game->protocol_version != MULTI_PROTO_VERSION && + (game->protocol_version != MULTI_PROTO_DXX_VER || + game->required_subprotocol > MULTI_PROTO_DXX_MINOR))) + return "UNSUP"; +#endif + return names[game->gamemode]; +} + +char *network_status_text(const netgame_info *game, int activeplayers) { + switch (game->game_status) { + case NETSTAT_STARTING: + return "Forming"; + case NETSTAT_PLAYING: + if (game->game_flags & NETGAME_FLAG_CLOSED) + return "Closed"; + else if (activeplayers == game->max_numplayers) + return "Full"; + else + return "Open"; + default: + return "Between"; + } +} + +static void network_update_item(const netgame_info *game, const AllNetPlayers_info *players, struct line_item li[]) { + int i, activeplayers = 0; + // get number of active players + for (i = 0; i < game->numplayers; i++) + if (players->players[i].connected) + activeplayers++; + strcpy(li[1].value, game->protocol_version == MULTI_PROTO_DXX_VER ? "+" : ""); + strcpy(li[2].value, game->game_name); + strcpy(li[3].value, network_mode_text(game)); + + sprintf(li[4].value, "%d/%d", activeplayers, game->max_numplayers); +#ifndef SHAREWARE + strcpy(li[5].value, game->mission_title); +#else + strcpy(li[5].value, "Descent: First Strike"); +#endif + if (game->levelnum < 0) + sprintf(li[6].value, "S%d", -game->levelnum); + else + sprintf(li[6].value, "%d", game->levelnum); + strcpy(li[7].value, network_status_text(game, activeplayers)); +} + +static void update_items(struct line_item lis[MAX_ACTIVE_NETGAMES][LINE_ITEMS]) { + int i, j; + + for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) { + if (i >= num_active_games) { + for (j = 1; j < LINE_ITEMS; j++) + lis[i][j].value[0] = 0; + } else + network_update_item(&Active_games[i], &ActiveNetPlayers[i], lis[i]); + } +} + +int network_menu_hskip=4; +int network_menu_width[LINE_ITEMS] = { 10, 6, 72, 37, 38, 66, 25, 40 }; +int ref_network_menu_width[LINE_ITEMS] = { 10, 6, 72, 37, 38, 66, 25, 40 }; +char *network_menu_title[LINE_ITEMS] = { "", "", "Game", "Mode", "#Plrs", "Mission", "Lev", "Status" }; + +static int selected_game; + +static void draw_back(bkg *b, int x, int y, int w, int h) { + gr_bm_bitblt(b->background->bm_w-15, h, 5, y, 5, y, b->background, &(grd_curcanv->cv_bitmap) ); +} + +static void draw_item(bkg *b, struct line_item *li, int is_current) { + int i, w, h, aw, max_w, pad_w, y; + char str[MAX_TEXT_LEN], *p; + + y = li[0].y; + if (is_current) + gr_set_fontcolor(BM_XRGB(31, 27, 6), -1); + else + gr_set_fontcolor(BM_XRGB(17, 17, 26), -1); + gr_get_string_size(" ...", &pad_w, &h, &aw); + draw_back(b, li[0].x, y, + li[LINE_ITEMS-1].x + li[LINE_ITEMS-1].width - li[0].x, h); + for (i = 0; i < LINE_ITEMS; i++) { + strcpy(str, li[i].value); + gr_get_string_size(str, &w, &h, &aw); + if (w > li[i].width) { + max_w = li[i].width - pad_w; + p = str + strlen(str); + while (p > str && w > max_w) { + *(--p) = 0; + gr_get_string_size(str, &w, &h, &aw); + } + strcpy(p, " ..."); + } + gr_ustring(li[i].x, y, str); + } +} + +static void draw_list(bkg *bg, + struct line_item lis[MAX_ACTIVE_NETGAMES][LINE_ITEMS]) { + int i; + update_items(lis); + for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) { + draw_item(bg, lis[i], i == selected_game); + } +} +static void init_background(bkg *bg, int x, int y, int w, int h) { + bg->menu_canvas = gr_create_sub_canvas( &grd_curscreen->sc_canvas, x, y, w, h ); + gr_set_current_canvas( bg->menu_canvas ); + + // Save the background under the menu... + bg->saved = gr_create_bitmap( w, h ); + Assert( bg->saved != NULL ); + gr_bm_bitblt(w, h, 0, 0, 0, 0, &grd_curcanv->cv_bitmap, bg->saved ); + gr_set_current_canvas( NULL ); + nm_draw_background(x,y,x+w-1,y+h-1); + if (w > nm_background.bm_w || h > nm_background.bm_h){ + bg->background=gr_create_bitmap(w,h); + gr_bitmap_scale_to(&nm_background,bg->background); + bg->background_is_sub=0; + }else{ + bg->background = gr_create_sub_bitmap(&nm_background,0,0,w,h); + bg->background_is_sub=1; + } + gr_set_current_canvas( bg->menu_canvas ); +} + +static void done_background(bkg *bg) { + gr_set_current_canvas(bg->menu_canvas); + gr_bitmap(0, 0, bg->saved); + gr_free_bitmap(bg->saved); + if (bg->background_is_sub) + gr_free_sub_bitmap( bg->background ); + else + gr_free_bitmap( bg->background ); + gr_free_sub_canvas( bg->menu_canvas ); +} + + +//added on 9/16-18/98 by Victor Rachels to add info boxes to netgameslist +void show_game_players(netgame_info game, AllNetPlayers_info players) +{ + char pilots[(CALLSIGN_LEN+2)*MAX_PLAYERS]; + int i; + + memset(pilots,0,sizeof(char)*(CALLSIGN_LEN+2)*MAX_PLAYERS); + + for(i=0;i=1 +#endif +){ +#ifndef SHAREWARE + int i=0,b=0; + char sep0=':'; + if(game.flags & NETFLAG_ENABLE_RADAR) + info+=sprintf(info,"\n Radar"); + if(game.flags & NETFLAG_ENABLE_ALT_VULCAN) + info+=sprintf(info,"\n Alt Vulcan"); + info+=sprintf(info,"\n Banned"); +#define NETFLAG_SHOW_BANNED(D,V) if (!(game.flags&NETFLAG_DO ## D)) {if (i>3) i=0; else i++; info+=sprintf(info,"%c %s",i?sep0:'\n',#V);b++;sep0=',';} + NETFLAG_SHOW_BANNED(LASER,laser); + NETFLAG_SHOW_BANNED(QUAD,quad); + NETFLAG_SHOW_BANNED(VULCAN,vulcan); + NETFLAG_SHOW_BANNED(SPREAD,spread); + NETFLAG_SHOW_BANNED(PLASMA,plasma); + NETFLAG_SHOW_BANNED(FUSION,fusion); + NETFLAG_SHOW_BANNED(HOMING,homing); + NETFLAG_SHOW_BANNED(SMART,smart); + NETFLAG_SHOW_BANNED(MEGA,mega); + NETFLAG_SHOW_BANNED(PROXIM,proxim); + NETFLAG_SHOW_BANNED(CLOAK,cloak); + NETFLAG_SHOW_BANNED(INVUL,invuln); + if (b==0) info+=sprintf(info,": none"); +#endif /* ! SHAREWARE */ + } + //end edit -MM + //end edit -MM + if (awesomeflag){ + int c; + while (1){ + c=nm_messagebox("Stats", 3, "Players","Scores","Join Game", rinfo); + if (c==0) + show_game_players(game, players); + else if (c==1) + show_game_score(game, players); + else if (c==2) + return 1; + else + return 0; + } + }else{ + nm_messagebox("Stats", 1, TXT_OK, rinfo); + return 0; + } +} +//end this section addition - Victor Rachels + +//added on 11/12/98 by Victor Rachels to maybe fix some bugs +void alphanumize(char *string, int length); + +void alphanumize(char *string, int length) +{ + int i=0; + while(i=97) || + (string[i]<=90 &&string[i]>=65) || + (string[i]<=57 &&string[i]>=48) || + (string[i]=='\n') || + (string[i]==' ') || + (string[i]=='-') + ) ) + string[i] = '_'; + i++; + } +} + +//added on 10/12/98 by Victor Rachels to show netgamelist scores +void show_game_score(netgame_info game, AllNetPlayers_info players) +{ + char scores[2176]="",info[2048]="",deaths[128]="",tmp[10]; + int i,j,k; + + strcat(scores,"Pilots "); + strcat(deaths," "); + + for(i=0;i0) + { + strcat(info," "); + sprintf(tmp,"-%i",game.kills[i][j]); + } + else + { + strcat(info," "); + sprintf(tmp,"%i",game.kills[i][j]); + } + strcat(info,tmp); + for(k=strlen(tmp);k<3;k++) + strcat(info," "); + } + sprintf(tmp," %i",game.player_kills[i]); + strcat(info,tmp); + strcat(info,"\n\n"); + sprintf(tmp," %i",game.killed[i]); + strcat(deaths,tmp); + } + strcat(scores," Total\n\n"); + strcat(scores,info); + strcat(deaths," \n\n"); + strcat(scores,deaths); + alphanumize(scores,sizeof(scores)); + nm_messagebox_fixedfont("Score\n", 1, TXT_OK, scores); +} +//end this section addition - Victor Rachels + +//added on 2000/01/29 by Matt Mueller for direct ip join. +#include "netpkt.h" +int network_do_join_game(netgame_info *jgame); +int get_and_show_netgame_info(ubyte *server, ubyte *node, ubyte *net_address){ + sequence_packet me; + fix nextsend; + int numsent; + fix curtime; + + if (setjmp(LeaveGame)) + return 0; + num_active_games = 0; + Network_games_changed = 0; + Network_status = NETSTAT_BROWSING; + memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES); + + nextsend=0;numsent=0; + + while (1){ + curtime=timer_get_fixed_seconds(); + if (nextsend=5) + return 0;//timeout + nextsend=curtime+F1_0*3; + numsent++; + mprintf((0, "Sending game_list request.\n")); + memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 ); + memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 ); + memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 ); + me.type = PID_DXX_GAME_INFO_REQ;//get full info. + + send_sequence_packet( me, server,node,net_address); + } + + network_listen(); + + if (Network_games_changed){ + if (num_active_games<1){ + Network_games_changed=0; + continue; + } + if (show_game_stats(Active_games[0], ActiveNetPlayers[0], 1)) + return (network_do_join_game(&Active_games[0])); + else + return 0; + } + if (key_inkey()==KEY_ESC) + return 0; + + } + return 0; +} +//end addition -MM + +//added on 1/5/99 by Victor Rachels for missiondir +void change_missiondir() +{ + newmenu_item m[1]; + int i=1; + char thogdir[64]; + + sprintf(thogdir,AltHogDir); + + m[0].type = NM_TYPE_INPUT; m[0].text = thogdir; m[0].text_len = 64; + + i=newmenu_do1(NULL, "Mission Directory", 1, m, NULL, 0); + + if(i==0) + { + cfile_use_alternate_hogdir(thogdir); + sprintf(thogdir,AltHogDir); + m[0].text=thogdir; + } +} +//end this section addition - VR + +//added/changed on 9/17/98 by Victor Rachels for netgame info screen redraw +//this was mostly a bunch of random moves and copies from the main function +//if you can figure this out more elegantly, go for it. +void netlist_redraw(bkg bg, + char menu_text[MAX_ACTIVE_NETGAMES][LINE_ITEMS][MAX_TEXT_LEN], + struct line_item lis[MAX_ACTIVE_NETGAMES][LINE_ITEMS]) +{ + int i,j,k,yp; + + gr_set_current_canvas( NULL ); + + init_background(&bg, 0, 7, grd_curcanv->cv_bitmap.bm_w, + grd_curcanv->cv_bitmap.bm_h - 14); + + yp=22; + gr_set_curfont(Gamefonts[GFONT_BIG_1]); + gr_string(0x8000, yp, "Netgames");//yp was 22 + yp+=grd_curcanv->cv_font->ft_h+network_menu_hskip*3+Gamefonts[GFONT_SMALL]->ft_h;//need to account for size of current socket, drawn elsewhere + // draw titles + gr_set_curfont(Gamefonts[GFONT_SMALL]); + gr_set_fontcolor(BM_XRGB(27, 27, 27), -1); + k = 15; + for (j = 0; j < LINE_ITEMS; j++) { + gr_ustring(k, yp, network_menu_title[j]);//yp was 61 + k += network_menu_width[j]; + } + + + for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) { + struct line_item *li = lis[i]; + k=15; + + yp+=grd_curcanv->cv_font->ft_h+network_menu_hskip; + for (j = 0; j < LINE_ITEMS; j++) { + li[j].x = k; + li[j].y = yp; + // li[j].y = 70 + i * 9; + li[j].width = network_menu_width[j] - (j > 1 ? 4 : 0); // HACK! + k += network_menu_width[j]; + li[j].value = menu_text[i][j]; + } + sprintf(li[0].value, "%d.", i + 1); + } + +} +//end this section addition - Victor Rachels + +int network_join_game_menu() { + char menu_text[MAX_ACTIVE_NETGAMES][LINE_ITEMS][MAX_TEXT_LEN]; + struct line_item lis[MAX_ACTIVE_NETGAMES][LINE_ITEMS]; + int k; + int old_select, old_socket, done, last_num_games; + grs_canvas * save_canvas; + grs_font * save_font; + bkg bg; + fix t, req_timer = 0; + + selected_game = 0; + gr_palette_fade_in( gr_palette, 32, 0 ); + save_canvas = grd_curcanv; + gr_set_current_canvas( NULL ); + save_font = grd_curcanv->cv_font; + + for (k=0;kcv_bitmap.bm_w/320; + network_menu_hskip=(grd_curcanv->cv_bitmap.bm_h-Gamefonts[GFONT_BIG_1]->ft_h-22-Gamefonts[GFONT_SMALL]->ft_h*17)/17; + + init_background(&bg, 0, 7, grd_curcanv->cv_bitmap.bm_w, + grd_curcanv->cv_bitmap.bm_h - 14); + + game_flush_inputs(); + +//added/changed on 9/17/98 by Victor Rachels for netgame info screen redraw + netlist_redraw(bg,menu_text,lis); +//end this section addition - Victor Rachels + + Network_games_changed = 1; + old_socket = -32768; + old_select = -1; + last_num_games = 0; + if ( gr_palette_faded_out ) { + gr_palette_fade_in( gr_palette, 32, 0 ); + } + + done = 0; + + while (!done) { + if (Network_socket != old_socket) { + gr_set_fontcolor(BM_XRGB(27, 27, 27), -1); + draw_back(&bg, 30, 22+Gamefonts[GFONT_BIG_1]->ft_h+network_menu_hskip*2, 250, Gamefonts[GFONT_SMALL]->ft_h+4);//was 52,250,9 + gr_printf(30, 22+Gamefonts[GFONT_BIG_1]->ft_h+network_menu_hskip*2, "Current IPX socket is %+d " + "(PgUp/PgDn to change)", Network_socket); + if (old_socket != -32768) { /* changed by user? */ + network_listen(); + ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket ); + num_active_games = 0; + } + req_timer -= F1_0 * 5; /* force send request */ + Network_games_changed = 1; + } + if (Network_games_changed) { + if (num_active_games > last_num_games) /* new game? */ + digi_play_sample(SOUND_HUD_MESSAGE, F1_0); + last_num_games = num_active_games; + Network_games_changed = 0; + draw_list(&bg, lis); + //added on 9/13/98 by adb to make update-needing arch's work + gr_update(); + //end addition - adb + + } else if (selected_game != old_select) { + draw_item(&bg, lis[old_select], 0); + draw_item(&bg, lis[selected_game], 1); + //added on 9/13/98 by adb to make update-needing arch's work + gr_update(); + //end addition - adb + } + old_socket = Network_socket; + old_select = selected_game; + + t = timer_get_approx_seconds(); + if (t < req_timer || t > req_timer + F1_0 * 5) { + req_timer = timer_get_approx_seconds(); + network_send_game_list_request(); + } + network_listen(); + + k = key_inkey(); + switch (k) { +//added 9/16-17/98 by Victor Rachels for netgamelist info + //edit 4/18/99 Matt Mueller - use KEY_? defines so it actually works on non-dos + case KEY_U: //U = 0x16 + if(selected_game -99) Network_socket--; + break; + case KEY_PAD5: + Network_socket = 0; + break; + case KEY_TAB + KEY_SHIFTED: + case KEY_UP: + case KEY_PAD8: + if (selected_game-- == 0) + selected_game = MAX_ACTIVE_NETGAMES - 1; + break; + case KEY_TAB: + case KEY_DOWN: + case KEY_PAD2: + if (++selected_game == MAX_ACTIVE_NETGAMES) + selected_game = 0; + break; + case KEY_ENTER: + case KEY_PADENTER: + done = 1; + break; +#if 0 + //added on 11/20/99 by Victor Rachels to add observer mode + case KEY_O: + I_am_observer=1; + done = 1; + break; + //end this section addition - VR +#endif + case KEY_ESC: + selected_game = -1; + done = 1; + break; + case KEYS_GR_TOGGLE_FULLSCREEN: + gr_toggle_fullscreen_menu(); + break; + } + } + done_background(&bg); + //edited 05/18/99 Matt Mueller - restore the font *after* the canvas, or else we are writing into the free'd memory + gr_set_current_canvas( save_canvas ); + grd_curcanv->cv_font = save_font; + //end edit -MM + return selected_game; +} diff --git a/main/netpkt.c b/main/netpkt.c new file mode 100644 index 00000000..4de26c20 --- /dev/null +++ b/main/netpkt.c @@ -0,0 +1,1032 @@ +/* +THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX +SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO +END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A +ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS +IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS +SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE +FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE +CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS +AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. +COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. +*/ + +/* + * $Source: /cvs/cvsroot/d2x/main/netpkt.c,v $ + * $Revision: 1.1 $ + * $Author: bradleyb $ + * $Date: 2002-02-14 09:05:33 $ + * + * Network packet conversions + * Based on macnet.c from MAC version of Descent 1 + * + * $Log: not supported by cvs2svn $ + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include "pstypes.h" +#include "multi.h" +#include "network.h" +#include "object.h" +#include "powerup.h" +#include "error.h" +#include "ipx.h" +#include "netpkt.h" + +void receive_netplayer_info(ubyte *data, netplayer_info *info, int dxx) +{ + int loc = 0; + + memcpy(info->callsign, &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN; + info->callsign[CALLSIGN_LEN] = 0; + if (!dxx) loc++; + memcpy(&(info->network.ipx.server), &(data[loc]), 4); loc += 4; + memcpy(&(info->network.ipx.node), &(data[loc]), 6); loc += 6; + memcpy(&(info->socket), &(data[loc]), 2); loc += 2; +//MWA don't think we need to swap this because we need it in high order info->socket = swapshort(info->socket); + info->connected = data[loc]; loc++; + #ifndef SHAREWARE + //edited 03/04/99 Matt Mueller - sub_protocol was being set wrong in non-dxx games.. I still think its screwed somewhere else too though + if (dxx){ + info->sub_protocol = data[loc]; loc++; +// printf ("%i "__FUNCTION__ " name=%s sub_protocol=%i\n",Player_num,info->callsign,info->sub_protocol); + }else + info->sub_protocol = 0; +//end edit -MM + #endif +} + +void send_sequence_packet(sequence_packet seq, ubyte *server, ubyte *node, ubyte *net_address) +{ + short tmps; + int loc; + + loc = 0; + memset(out_buffer, 0, sizeof(out_buffer)); + out_buffer[0] = seq.type; loc++; + memcpy(&(out_buffer[loc]), seq.player.callsign, CALLSIGN_LEN+1); loc += CALLSIGN_LEN+1; + memcpy(&(out_buffer[loc]), seq.player.network.ipx.server, 4); loc += 4; + memcpy(&(out_buffer[loc]), seq.player.network.ipx.node, 6); loc += 6; + tmps = swapshort(seq.player.socket); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + out_buffer[loc] = seq.player.connected; loc++; + out_buffer[loc] = MULTI_PROTO_DXX_MINOR; loc++; + + if (net_address != NULL) + ipx_send_packet_data( out_buffer, loc, server, node, net_address); + else if ((server == NULL) && (node == NULL)) + ipx_send_broadcast_packet_data( out_buffer, loc ); + else + ipx_send_internetwork_packet_data( out_buffer, loc, server, node); +} + +void receive_sequence_packet(ubyte *data, sequence_packet *seq) +{ + int loc = 0; + + seq->type = data[0]; loc++; + receive_netplayer_info(&(data[loc]), &(seq->player), 0); +} + + +void send_netgame_packet(ubyte *server, ubyte *node) +{ + uint tmpi; + ushort tmps; + int i, j; + int loc = 0; + +#ifndef SHAREWARE + if (Netgame.protocol_version == MULTI_PROTO_DXX_VER) { + send_dxx_netgame_packet(server, node); + return; + } +#endif + memset(out_buffer, 0, IPX_MAX_DATA_SIZE); + out_buffer[loc] = Netgame.type; loc++; + memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1); + memcpy(&(out_buffer[loc]), Netgame.team_name, 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1); + out_buffer[loc] = Netgame.gamemode; loc++; + out_buffer[loc] = Netgame.difficulty; loc++; + out_buffer[loc] = Netgame.game_status; loc++; + out_buffer[loc] = Netgame.numplayers; loc++; + out_buffer[loc] = Netgame.max_numplayers; loc++; + out_buffer[loc] = Netgame.game_flags; loc++; + for (i = 0; i < MAX_PLAYERS; i++) { + memcpy(&(out_buffer[loc]), NetPlayers.players[i].callsign, CALLSIGN_LEN+1); loc += CALLSIGN_LEN+1; + memcpy(&(out_buffer[loc]), NetPlayers.players[i].network.ipx.server, 4); loc += 4; + memcpy(&(out_buffer[loc]), NetPlayers.players[i].network.ipx.node, 6); loc += 6; + memcpy(&(out_buffer[loc]), &(NetPlayers.players[i].socket), 2); loc += 2; + memcpy(&(out_buffer[loc]), &(NetPlayers.players[i].connected), 1); loc++; + } + if (Netgame.protocol_version == MULTI_PROTO_DXX_VER) { + for (i = 0; i < MAX_PLAYERS; i++) { + out_buffer[loc] = Netgame.locations[i]; loc++; + } + } else { + for (i = 0; i < MAX_PLAYERS; i++) { + tmpi = swapint(Netgame.locations[i]); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP HERE!!! + } + } + + for (i = 0; i < MAX_PLAYERS; i++) { + for (j = 0; j < MAX_PLAYERS; j++) { + tmps = swapshort(Netgame.kills[i][j]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! + } + } + + tmpi = swapint(Netgame.levelnum); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE + out_buffer[loc] = Netgame.protocol_version; loc++; + out_buffer[loc] = Netgame.team_vector; loc++; + tmps = swapshort(Netgame.segments_checksum); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE + tmps = swapshort(Netgame.team_kills[0]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE + tmps = swapshort(Netgame.team_kills[1]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE + for (i = 0; i < MAX_PLAYERS; i++) { + tmps = swapshort(Netgame.killed[i]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! + } + for (i = 0; i < MAX_PLAYERS; i++) { + tmps = swapshort(Netgame.player_kills[i]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! + } + +#ifndef SHAREWARE + tmpi = swapint(Netgame.level_time); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE + tmpi = swapint(Netgame.control_invul_time); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE + tmpi = swapint(Netgame.monitor_vector); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE + for (i = 0; i < 8; i++) { + tmpi = swapint(Netgame.player_score[i]); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE + } + for (i = 0; i < 8; i++) { + memcpy(&(out_buffer[loc]), &(Netgame.player_flags[i]), 1); loc++; + } + memcpy(&(out_buffer[loc]), Netgame.mission_name, 9); loc += 9; + memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1); + if (Netgame.protocol_version == MULTI_PROTO_DXX_VER) { + out_buffer[loc] = Netgame.PacketsPerSec; loc++; + tmpi = swapint(Netgame.flags); + memcpy(&out_buffer[loc], &tmpi, 4); loc += 4; + } +#endif + + if (server == NULL) + ipx_send_broadcast_packet_data(out_buffer, loc); + else + ipx_send_internetwork_packet_data( out_buffer, loc, server, node ); +} + +void receive_netgame_packet(ubyte *data, netgame_info *netgame, AllNetPlayers_info *netplayers, int dxx) +{ + int i, j; + int loc = 0; +#ifndef SHAREWARE + if (dxx) { + receive_dxx_netgame_packet(data, netgame, netplayers); + return; + } +#endif + + netgame->type = data[loc]; loc++; + memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1); + memcpy(netgame->team_name, &(data[loc]), 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1); + netgame->gamemode = data[loc]; loc++; + netgame->difficulty = data[loc]; loc++; + netgame->game_status = data[loc]; loc++; + netgame->numplayers = data[loc]; loc++; + netgame->max_numplayers = data[loc]; loc++; + netgame->game_flags = data[loc]; loc++; + for (i = 0; i < MAX_PLAYERS; i++) { + receive_netplayer_info(&(data[loc]), &(netplayers->players[i]), 0); + loc += sizeof(netplayer_info);//NETPLAYER_ORIG_SIZE; + } +#if 0 + if (dxx) { + for (i = 0; i < MAX_PLAYERS; i++) { + netgame->locations[i] = data[loc]; loc++; + } + } else +#endif + { + for (i = 0; i < MAX_PLAYERS; i++) { + memcpy(&(netgame->locations[i]), &(data[loc]), 4); loc += 4; // SWAP HERE!!! + netgame->locations[i] = swapint(netgame->locations[i]); + } + } + + for (i = 0; i < MAX_PLAYERS; i++) { + for (j = 0; j < MAX_PLAYERS; j++) { + memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! + netgame->kills[i][j] = swapshort(netgame->kills[i][j]); + } + } + + memcpy(&(netgame->levelnum), &(data[loc]), 4); loc += 4; // SWAP_HERE + netgame->levelnum = swapint(netgame->levelnum); + netgame->protocol_version = data[loc]; loc++; + netgame->team_vector = data[loc]; loc++; + memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2; // SWAP_HERE + netgame->segments_checksum = swapshort(netgame->segments_checksum); + memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2; // SWAP_HERE + netgame->team_kills[0] = swapshort(netgame->team_kills[0]); + memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2; // SWAP_HERE + netgame->team_kills[1] = swapshort(netgame->team_kills[1]); + for (i = 0; i < MAX_PLAYERS; i++) { + memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! + netgame->killed[i] = swapshort(netgame->killed[i]); + } + for (i = 0; i < MAX_PLAYERS; i++) { + memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! + netgame->player_kills[i] = swapshort(netgame->player_kills[i]); + } + +#ifndef SHAREWARE + memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4; // SWAP_HERE + netgame->level_time = swapint(netgame->level_time); + memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4; // SWAP_HERE + netgame->control_invul_time = swapint(netgame->control_invul_time); + memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4; // SWAP_HERE + netgame->monitor_vector = swapint(netgame->monitor_vector); + for (i = 0; i < 8; i++) { + memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4; // SWAP_HERE + netgame->player_score[i] = swapint(netgame->player_score[i]); + } + memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8; +#if 0 + for (i = 0; i < 8; i++) { + memcpy(&(netgame->player_flags[i]), &(data[loc]), 1); loc++; + } +#endif + + memcpy(netgame->mission_name, &(data[loc]), 9); loc += 9; + memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1); +#if 0 + if (dxx && netgame->protocol_version == MULTI_PROTO_DXX_VER) { + netgame->packets_per_sec = data[loc]; loc++; + memcpy(&netgame->flags, &data[loc], 4); loc += 4; + netgame->flags = swapint(netgame->flags); + } +#endif +#endif +} + +#ifndef SHAREWARE +void store_netplayer_info(ubyte *data, netplayer_info *player, int dxx) +{ + memcpy(data, player->callsign, CALLSIGN_LEN); data += CALLSIGN_LEN; + if (!dxx) *(data++) = 0; + memcpy(data, player->network.ipx.server, 4); data += 4; + memcpy(data, player->network.ipx.node, 6); data += 6; + memcpy(data, &player->socket, 2); data += 2; + *data = player->connected; data++; + if (dxx) { + *data = player->sub_protocol; data++; +// printf ("%i "__FUNCTION__ " name=%s sub_protocol=%i\n",Player_num,player->callsign,player->sub_protocol); + } +} + +void send_dxx_netgame_packet(ubyte *server, ubyte *node) +{ + uint tmpi; + ushort tmps; + int i, j; + int loc = 0; + + memset(out_buffer, 0, IPX_MAX_DATA_SIZE); + out_buffer[loc] = Netgame.type; loc++; + out_buffer[loc] = MULTI_PROTO_DXX_VER; loc++; + out_buffer[loc] = Netgame.subprotocol; loc++; + out_buffer[loc] = Netgame.required_subprotocol; loc++; + memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN; + memcpy(&(out_buffer[loc]), Netgame.mission_name, 8); loc += 8; + memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN); loc += MISSION_NAME_LEN; + out_buffer[loc] = Netgame.levelnum; loc++; + out_buffer[loc] = Netgame.gamemode; loc++; + out_buffer[loc] = Netgame.difficulty; loc++; + out_buffer[loc] = Netgame.game_status; loc++; + out_buffer[loc] = Netgame.game_flags; loc++; + out_buffer[loc] = Netgame.max_numplayers; loc++; + out_buffer[loc] = Netgame.team_vector; loc++; + if (Netgame.type == PID_DXX_GAME_LITE) { + int master = -1; + j = 0; + for (i = 0; i < Netgame.numplayers; i++) + if (Players[i].connected) { + if (master == -1) + master = i; + j++; + } + out_buffer[loc] = j; loc++; /* numconnected */ + if (master == -1) /* should not happen, but... */ + master = Player_num; + store_netplayer_info(&(out_buffer[loc]), &NetPlayers.players[master], 1); loc += sizeof(netplayer_info); //NETPLAYER_DXX_SIZE; + //added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them + tmpi = swapint(Netgame.flags); + memcpy(&out_buffer[loc], &tmpi, 4); loc += 4; + //end addition -MM + } else { + out_buffer[loc] = Netgame.numplayers; loc++; + out_buffer[loc] = sizeof(netplayer_info); //NETPLAYER_DXX_SIZE; // sizeof netplayer struct + loc++; + for (i = 0; i < MAX_PLAYERS; i++) { + store_netplayer_info(&(out_buffer[loc]), &NetPlayers.players[i], 1); + loc += sizeof(netplayer_info); //NETPLAYER_DXX_SIZE; + } + memcpy(&(out_buffer[loc]), Netgame.team_name[0], CALLSIGN_LEN); loc += CALLSIGN_LEN; + memcpy(&(out_buffer[loc]), Netgame.team_name[1], CALLSIGN_LEN); loc += CALLSIGN_LEN; + for (i = 0; i < MAX_PLAYERS; i++) { + out_buffer[loc] = Netgame.locations[i]; loc++; + } + for (i = 0; i < MAX_PLAYERS; i++) { + for (j = 0; j < MAX_PLAYERS; j++) { + tmps = swapshort(Netgame.kills[i][j]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! + } + } + tmps = swapshort(Netgame.segments_checksum); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE + tmps = swapshort(Netgame.team_kills[0]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE + tmps = swapshort(Netgame.team_kills[1]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE + for (i = 0; i < MAX_PLAYERS; i++) { + tmps = swapshort(Netgame.killed[i]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! + } + for (i = 0; i < MAX_PLAYERS; i++) { + tmps = swapshort(Netgame.player_kills[i]); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! + } + tmpi = swapint(Netgame.level_time); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE + tmpi = swapint(Netgame.control_invul_time); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE + tmpi = swapint(Netgame.monitor_vector); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE + for (i = 0; i < 8; i++) { + tmpi = swapint(Netgame.player_score[i]); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE + } + memcpy(&(out_buffer[loc]), Netgame.player_flags, MAX_PLAYERS); loc += MAX_PLAYERS; + out_buffer[loc] = Netgame.PacketsPerSec; loc++; + tmpi = swapint(Netgame.flags); + memcpy(&out_buffer[loc], &tmpi, 4); loc += 4; + } + + if (server == NULL) + ipx_send_broadcast_packet_data(out_buffer, loc); + else + ipx_send_internetwork_packet_data(out_buffer, loc, server, node); +} + +void receive_dxx_netgame_packet(ubyte *data, netgame_info *netgame, AllNetPlayers_info *netplayers) { + int i, j; + int loc = 0; + + netgame->type = data[loc]; loc++; + if (netgame->type == PID_DXX_GAME_LITE) { + memset(netgame, 0, sizeof(netgame_info)); + netgame->type = PID_DXX_GAME_LITE; + } + netgame->protocol_version = data[loc]; loc++; + netgame->subprotocol = data[loc]; loc++; + netgame->required_subprotocol = data[loc]; loc++; + memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN; + netgame->game_name[NETGAME_NAME_LEN] = 0; + memcpy(netgame->mission_name, &(data[loc]), 8); loc += 8; + netgame->mission_name[8] = 0; + memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN); loc += MISSION_NAME_LEN; + netgame->mission_title[MISSION_NAME_LEN] = 0; + netgame->levelnum = ((signed char *)data)[loc]; loc++; + netgame->gamemode = data[loc]; loc++; + netgame->difficulty = data[loc]; loc++; + netgame->game_status = data[loc]; loc++; + netgame->game_flags = data[loc]; loc++; + netgame->max_numplayers = data[loc]; loc++; + netgame->team_vector = data[loc]; loc++; + if (netgame->type == PID_DXX_GAME_LITE) { + j = netgame->numplayers = data[loc]; loc++; + for (i = 0; i < j; i++) + netplayers->players[i].connected = 1; + receive_netplayer_info(&(data[loc]), &(netplayers->players[0]), 1);loc += sizeof(netplayer_info); //NETPLAYER_DXX_SIZE; + //added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them + if (netgame->subprotocol>=1){ + memcpy(&netgame->flags, &data[loc], 4); loc += 4; + netgame->flags = swapint(netgame->flags); + } + //end addition -MM + } else { + netgame->numplayers = data[loc]; loc++; + j = data[loc]; loc++; // sizeof netplayer struct + if (j > 29) { /* sanity: 304+29*8=536, just below IPX_MAX=542 */ + netgame->protocol_version = 0; return; + } + for (i = 0; i < MAX_PLAYERS; i++) { + receive_netplayer_info(&(data[loc]), &(netplayers->players[i]), 1); + loc += j; + } + memcpy(netgame->team_name[0], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN; + netgame->team_name[0][CALLSIGN_LEN] = 0; + memcpy(netgame->team_name[1], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN; + netgame->team_name[1][CALLSIGN_LEN] = 0; + for (i = 0; i < MAX_PLAYERS; i++) { + netgame->locations[i] = data[loc]; loc++; + } + for (i = 0; i < MAX_PLAYERS; i++) { + for (j = 0; j < MAX_PLAYERS; j++) { + memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! + netgame->kills[i][j] = swapshort(netgame->kills[i][j]); + } + } + memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2; // SWAP_HERE + netgame->segments_checksum = swapshort(netgame->segments_checksum); + memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2; // SWAP_HERE + netgame->team_kills[0] = swapshort(netgame->team_kills[0]); + memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2; // SWAP_HERE + netgame->team_kills[1] = swapshort(netgame->team_kills[1]); + for (i = 0; i < MAX_PLAYERS; i++) { + memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! + netgame->killed[i] = swapshort(netgame->killed[i]); + } + for (i = 0; i < MAX_PLAYERS; i++) { + memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! + netgame->player_kills[i] = swapshort(netgame->player_kills[i]); + } + memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4; // SWAP_HERE + netgame->level_time = swapint(netgame->level_time); + memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4; // SWAP_HERE + netgame->control_invul_time = swapint(netgame->control_invul_time); + memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4; // SWAP_HERE + netgame->monitor_vector = swapint(netgame->monitor_vector); + for (i = 0; i < 8; i++) { + memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4; // SWAP_HERE + netgame->player_score[i] = swapint(netgame->player_score[i]); + } + memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8; + netgame->PacketsPerSec = data[loc]; loc++; + memcpy(&netgame->flags, &data[loc], 4); loc += 4; + netgame->flags = swapint(netgame->flags); + } +} +#endif + +void send_frameinfo_packet(ubyte *server, ubyte *node, ubyte *address, int short_packet) +{ + int loc, tmpi; + short tmps; +#ifndef SHAREWARE + ushort tmpus; +#endif + object *pl_obj = &Objects[Players[Player_num].objnum]; + + loc = 0; + memset(out_buffer, 0, IPX_MAX_DATA_SIZE); +#ifdef SHAREWARE + out_buffer[0] = PID_PDATA; loc++; + tmpi = swapint(MySyncPack.numpackets); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmps = swapshort(Players[Player_num].objnum); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + out_buffer[loc] = Player_num; loc++; + tmps = swapshort(pl_obj->segnum); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + + tmpi = swapint((int)pl_obj->pos.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->pos.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->pos.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + + tmpi = swapint((int)pl_obj->orient.rvec.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.rvec.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.rvec.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.uvec.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.uvec.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.uvec.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.fvec.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.fvec.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.fvec.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + + tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.mass); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.drag); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.brakes); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmps = swapshort((short)pl_obj->mtype.phys_info.turnroll); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + tmps = swapshort(pl_obj->mtype.phys_info.flags); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + + out_buffer[loc] = pl_obj->render_type; loc++; + out_buffer[loc] = Current_level_num; loc++; + tmps = swapshort(MySyncPack.data_size); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + memcpy(&(out_buffer[loc]), MySyncPack.data, MySyncPack.data_size); + loc += MySyncPack.data_size; +#else + if (short_packet == 1) { + loc = 0; + out_buffer[loc] = PID_SHORTPDATA; loc++; + out_buffer[loc] = Player_num; loc++; + out_buffer[loc] = pl_obj->render_type; loc++; + out_buffer[loc] = Current_level_num; loc++; + create_shortpos((shortpos *)(out_buffer + loc), pl_obj, 0); + loc += 9+2*3+2+2*3; // go past shortpos structure + *(ushort *)(out_buffer + loc) = MySyncPack.data_size; loc += 2; + memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size); + loc += MySyncPack.data_size; + } else if (short_packet == 2) { + loc = 0; + out_buffer[loc] = PID_PDATA_SHORT2; loc++; + out_buffer[loc] = MySyncPack.numpackets & 255; loc++; + create_shortpos((shortpos *)(out_buffer + loc), pl_obj, 0); + loc += 9+2*3+2+2*3; // go past shortpos structure + tmpus = MySyncPack.data_size | (Player_num << 12) | (pl_obj->render_type << 15); + *(ushort *)(out_buffer + loc) = tmpus; loc += 2; + out_buffer[loc] = Current_level_num; loc++; + memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size); + loc += MySyncPack.data_size; + } else { + out_buffer[0] = PID_PDATA; loc++; loc += 3; // skip three for pad byte + tmpi = swapint(MySyncPack.numpackets); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + + tmpi = swapint((int)pl_obj->pos.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->pos.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->pos.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + + tmpi = swapint((int)pl_obj->orient.rvec.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.rvec.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.rvec.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.uvec.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.uvec.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.uvec.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.fvec.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.fvec.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->orient.fvec.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + + tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + + tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.x); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.y); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.z); + memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; + + tmps = swapshort(pl_obj->segnum); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + tmps = swapshort(MySyncPack.data_size); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + + out_buffer[loc] = Player_num; loc++; + out_buffer[loc] = pl_obj->render_type; loc++; + out_buffer[loc] = Current_level_num; loc++; + memcpy(&(out_buffer[loc]), MySyncPack.data, MySyncPack.data_size); + loc += MySyncPack.data_size; + } +#endif +#if 0 // adb: not possible (always array passed) + if (address == NULL) + ipx_send_internetwork_packet_data( out_buffer, loc, server, node ); + else +#endif + ipx_send_packet_data( out_buffer, loc, server, node, address); +} + +void receive_frameinfo_packet(ubyte *data, frame_info *info, int short_packet) +{ + int loc; + +#ifdef SHAREWARE + loc = 0; + + info->type = data[0]; loc++; + memcpy(&(info->numpackets), &(data[loc]), 4); loc += 4; + info->numpackets = swapint(info->numpackets); + memcpy(&(info->objnum), &(data[loc]), 2); loc += 2; + info->objnum = swapshort(info->objnum); + info->playernum = data[loc]; loc++; + + memcpy(&(info->obj_segnum), &(data[loc]), 2); loc += 2; + info->obj_segnum = swapshort(info->obj_segnum); + + memcpy(&(info->obj_pos.x), &(data[loc]), 4); loc += 4; + info->obj_pos.x = (fix)swapint((int)info->obj_pos.x); + memcpy(&(info->obj_pos.y), &(data[loc]), 4); loc += 4; + info->obj_pos.y = (fix)swapint((int)info->obj_pos.y); + memcpy(&(info->obj_pos.z), &(data[loc]), 4); loc += 4; + info->obj_pos.z = (fix)swapint((int)info->obj_pos.z); + + memcpy(&(info->obj_orient.rvec.x), &(data[loc]), 4); loc += 4; + info->obj_orient.rvec.x = (fix)swapint((int)info->obj_orient.rvec.x); + memcpy(&(info->obj_orient.rvec.y), &(data[loc]), 4); loc += 4; + info->obj_orient.rvec.y = (fix)swapint((int)info->obj_orient.rvec.y); + memcpy(&(info->obj_orient.rvec.z), &(data[loc]), 4); loc += 4; + info->obj_orient.rvec.z = (fix)swapint((int)info->obj_orient.rvec.z); + memcpy(&(info->obj_orient.uvec.x), &(data[loc]), 4); loc += 4; + info->obj_orient.uvec.x = (fix)swapint((int)info->obj_orient.uvec.x); + memcpy(&(info->obj_orient.uvec.y), &(data[loc]), 4); loc += 4; + info->obj_orient.uvec.y = (fix)swapint((int)info->obj_orient.uvec.y); + memcpy(&(info->obj_orient.uvec.z), &(data[loc]), 4); loc += 4; + info->obj_orient.uvec.z = (fix)swapint((int)info->obj_orient.uvec.z); + memcpy(&(info->obj_orient.fvec.x), &(data[loc]), 4); loc += 4; + info->obj_orient.fvec.x = (fix)swapint((int)info->obj_orient.fvec.x); + memcpy(&(info->obj_orient.fvec.y), &(data[loc]), 4); loc += 4; + info->obj_orient.fvec.y = (fix)swapint((int)info->obj_orient.fvec.y); + memcpy(&(info->obj_orient.fvec.z), &(data[loc]), 4); loc += 4; + info->obj_orient.fvec.z = (fix)swapint((int)info->obj_orient.fvec.z); + + memcpy(&(info->obj_phys_info.velocity.x), &(data[loc]), 4); loc += 4; + info->obj_phys_info.velocity.x = (fix)swapint((int)info->obj_phys_info.velocity.x); + memcpy(&(info->obj_phys_info.velocity.y), &(data[loc]), 4); loc += 4; + info->obj_phys_info.velocity.y = (fix)swapint((int)info->obj_phys_info.velocity.y); + memcpy(&(info->obj_phys_info.velocity.z), &(data[loc]), 4); loc += 4; + info->obj_phys_info.velocity.z = (fix)swapint((int)info->obj_phys_info.velocity.z); + + memcpy(&(info->obj_phys_info.thrust.x), &(data[loc]), 4); loc += 4; + info->obj_phys_info.thrust.x = (fix)swapint((int)info->obj_phys_info.thrust.x); + memcpy(&(info->obj_phys_info.thrust.y), &(data[loc]), 4); loc += 4; + info->obj_phys_info.thrust.y = (fix)swapint((int)info->obj_phys_info.thrust.y); + memcpy(&(info->obj_phys_info.thrust.z), &(data[loc]), 4); loc += 4; + info->obj_phys_info.thrust.z = (fix)swapint((int)info->obj_phys_info.thrust.z); + + memcpy(&(info->obj_phys_info.mass), &(data[loc]), 4); loc += 4; + info->obj_phys_info.mass = (fix)swapint((int)info->obj_phys_info.mass); + memcpy(&(info->obj_phys_info.drag), &(data[loc]), 4); loc += 4; + info->obj_phys_info.drag = (fix)swapint((int)info->obj_phys_info.drag); + memcpy(&(info->obj_phys_info.brakes), &(data[loc]), 4); loc += 4; + info->obj_phys_info.brakes = (fix)swapint((int)info->obj_phys_info.brakes); + + memcpy(&(info->obj_phys_info.rotvel.x), &(data[loc]), 4); loc += 4; + info->obj_phys_info.rotvel.x = (fix)swapint((int)info->obj_phys_info.rotvel.x); + memcpy(&(info->obj_phys_info.rotvel.y), &(data[loc]), 4); loc += 4; + info->obj_phys_info.rotvel.y = (fix)swapint((int)info->obj_phys_info.rotvel.y); + memcpy(&(info->obj_phys_info.rotvel.z), &(data[loc]), 4); loc += 4; + info->obj_phys_info.rotvel.z = (fix)swapint((int)info->obj_phys_info.rotvel.z); + + memcpy(&(info->obj_phys_info.rotthrust.x), &(data[loc]), 4); loc += 4; + info->obj_phys_info.rotthrust.x = (fix)swapint((int)info->obj_phys_info.rotthrust.x); + memcpy(&(info->obj_phys_info.rotthrust.y), &(data[loc]), 4); loc += 4; + info->obj_phys_info.rotthrust.y = (fix)swapint((int)info->obj_phys_info.rotthrust.y); + memcpy(&(info->obj_phys_info.rotthrust.z), &(data[loc]), 4); loc += 4; + info->obj_phys_info.rotthrust.z = (fix)swapint((int)info->obj_phys_info.rotthrust.z); + + memcpy(&(info->obj_phys_info.turnroll), &(data[loc]), 2); loc += 2; + info->obj_phys_info.turnroll = (fixang)swapshort((short)info->obj_phys_info.turnroll); + + memcpy(&(info->obj_phys_info.flags), &(data[loc]), 2); loc += 2; + info->obj_phys_info.flags = (ushort)swapshort(info->obj_phys_info.flags); + + info->obj_render_type = data[loc]; loc++; + info->level_num = data[loc]; loc++; + memcpy( &(info->data_size), &(data[loc]), 2); loc += 2; + info->data_size = swapshort(info->data_size); + memcpy(info->data, &(data[loc]), info->data_size); +#else + if (short_packet == 1) { + loc = 0; + info->type = data[loc]; loc++; + info->playernum = data[loc]; loc++; + info->obj_render_type = data[loc]; loc++; + info->level_num = data[loc]; loc++; + loc += 9+2*3+2+2*3; // skip shortpos structure + info->data_size = *(ushort *)(data + loc); loc+=2; + memcpy(info->data, &(data[loc]), info->data_size); + } else if (short_packet == 2) { + ushort tmpus; + + loc = 0; + info->type = data[loc]; loc++; + info->numpackets = data[loc]; loc++; + loc += 9+2*3+2+2*3; // skip shortpos structure + tmpus = *(ushort *)(data + loc); loc+=2; + info->data_size = tmpus & 0xfff; + info->playernum = (tmpus >> 12) & 7; + info->obj_render_type = tmpus >> 15; + info->numpackets |= Players[info->playernum].n_packets_got & (~255); + if (info->numpackets - Players[info->playernum].n_packets_got > 224) + info->numpackets -= 256; + else if (Players[info->playernum].n_packets_got - info->numpackets > 128) + info->numpackets += 256; + info->level_num = data[loc]; loc++; + memcpy(info->data, &(data[loc]), info->data_size); + } else { + loc = 0; + info->type = data[loc]; loc++; loc += 3; // skip three for pad byte + memcpy(&(info->numpackets), &(data[loc]), 4); loc += 4; + info->numpackets = swapint(info->numpackets); + + memcpy(&(info->obj_pos.x), &(data[loc]), 4); loc += 4; + info->obj_pos.x = swapint((int)info->obj_pos.x); + memcpy(&(info->obj_pos.y), &(data[loc]), 4); loc += 4; + info->obj_pos.y = swapint((int)info->obj_pos.y); + memcpy(&(info->obj_pos.z), &(data[loc]), 4); loc += 4; + info->obj_pos.z = swapint((int)info->obj_pos.z); + + memcpy(&(info->obj_orient.rvec.x), &(data[loc]), 4); loc += 4; + info->obj_orient.rvec.x = swapint((int)info->obj_orient.rvec.x); + memcpy(&(info->obj_orient.rvec.y), &(data[loc]), 4); loc += 4; + info->obj_orient.rvec.y = swapint((int)info->obj_orient.rvec.y); + memcpy(&(info->obj_orient.rvec.z), &(data[loc]), 4); loc += 4; + info->obj_orient.rvec.z = swapint((int)info->obj_orient.rvec.z); + memcpy(&(info->obj_orient.uvec.x), &(data[loc]), 4); loc += 4; + info->obj_orient.uvec.x = swapint((int)info->obj_orient.uvec.x); + memcpy(&(info->obj_orient.uvec.y), &(data[loc]), 4); loc += 4; + info->obj_orient.uvec.y = swapint((int)info->obj_orient.uvec.y); + memcpy(&(info->obj_orient.uvec.z), &(data[loc]), 4); loc += 4; + info->obj_orient.uvec.z = swapint((int)info->obj_orient.uvec.z); + memcpy(&(info->obj_orient.fvec.x), &(data[loc]), 4); loc += 4; + info->obj_orient.fvec.x = swapint((int)info->obj_orient.fvec.x); + memcpy(&(info->obj_orient.fvec.y), &(data[loc]), 4); loc += 4; + info->obj_orient.fvec.y = swapint((int)info->obj_orient.fvec.y); + memcpy(&(info->obj_orient.fvec.z), &(data[loc]), 4); loc += 4; + info->obj_orient.fvec.z = swapint((int)info->obj_orient.fvec.z); + + memcpy(&(info->phys_velocity.x), &(data[loc]), 4); loc += 4; + info->phys_velocity.x = swapint((int)info->phys_velocity.x); + memcpy(&(info->phys_velocity.y), &(data[loc]), 4); loc += 4; + info->phys_velocity.y = swapint((int)info->phys_velocity.y); + memcpy(&(info->phys_velocity.z), &(data[loc]), 4); loc += 4; + info->phys_velocity.z = swapint((int)info->phys_velocity.z); + + memcpy(&(info->phys_rotvel.x), &(data[loc]), 4); loc += 4; + info->phys_rotvel.x = swapint((int)info->phys_rotvel.x); + memcpy(&(info->phys_rotvel.y), &(data[loc]), 4); loc += 4; + info->phys_rotvel.y = swapint((int)info->phys_rotvel.y); + memcpy(&(info->phys_rotvel.z), &(data[loc]), 4); loc += 4; + info->phys_rotvel.z = swapint((int)info->phys_rotvel.z); + + memcpy(&(info->obj_segnum), &(data[loc]), 2); loc += 2; + info->obj_segnum = swapshort(info->obj_segnum); + memcpy(&(info->data_size), &(data[loc]), 2); loc += 2; + info->data_size = swapshort(info->data_size); + + info->playernum = data[loc]; loc++; + info->obj_render_type = data[loc]; loc++; + info->level_num = data[loc]; loc++; + memcpy(info->data, &(data[loc]), info->data_size); + } +#endif +} + +void send_endlevel_packet(endlevel_info *info, ubyte *server, ubyte *node, ubyte *address) +{ + int i, j; + int loc = 0; + ushort tmps; + + memset(out_buffer, 0, IPX_MAX_DATA_SIZE); + out_buffer[loc] = info->type; loc++; + out_buffer[loc] = info->player_num; loc++; + out_buffer[loc] = info->connected; loc++; + for (i = 0; i < MAX_PLAYERS; i++) { + for (j = 0; j < MAX_PLAYERS; j++) { + tmps = swapshort(info->kill_matrix[i][j]); + memcpy(&(out_buffer[loc]), &tmps, 2); + loc += 2; + } + } + tmps = swapshort(info->kills); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + tmps = swapshort(info->killed); + memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; + out_buffer[loc] = info->seconds_left; loc++; + + ipx_send_packet_data( out_buffer, loc, server, node, address); +} + +void receive_endlevel_packet(ubyte *data, endlevel_info *info) +{ + int i, j; + int loc = 0; + + info->type = data[loc]; loc++; + info->player_num = data[loc]; loc++; + info->connected = data[loc]; loc++; + + for (i = 0; i < MAX_PLAYERS; i++) { + for (j = 0; j < MAX_PLAYERS; j++) { + memcpy(&(info->kill_matrix[i][j]), &(data[loc]), 2); loc += 2; + info->kill_matrix[i][j] = swapshort(info->kill_matrix[i][j]); + } + } + memcpy(&(info->kills), &(data[loc]), 2); loc += 2; + info->kills = swapshort(info->kills); + memcpy(&(info->killed), &(data[loc]), 2); loc += 2; + info->killed = swapshort(info->killed); + info->seconds_left = data[loc]; +} + +void swap_object(object *obj) +{ +// swap the short and int entries for this object + obj->signature = swapint(obj->signature); + obj->next = swapshort(obj->next); + obj->prev = swapshort(obj->prev); + obj->segnum = swapshort(obj->segnum); + obj->attached_obj = swapshort(obj->attached_obj); + obj->pos.x = swapint(obj->pos.x); + obj->pos.y = swapint(obj->pos.y); + obj->pos.z = swapint(obj->pos.z); + + obj->orient.rvec.x = swapint(obj->orient.rvec.x); + obj->orient.rvec.y = swapint(obj->orient.rvec.y); + obj->orient.rvec.z = swapint(obj->orient.rvec.z); + obj->orient.fvec.x = swapint(obj->orient.fvec.x); + obj->orient.fvec.y = swapint(obj->orient.fvec.y); + obj->orient.fvec.z = swapint(obj->orient.fvec.z); + obj->orient.uvec.x = swapint(obj->orient.uvec.x); + obj->orient.uvec.y = swapint(obj->orient.uvec.y); + obj->orient.uvec.z = swapint(obj->orient.uvec.z); + + obj->size = swapint(obj->size); + obj->shields = swapint(obj->shields); + + obj->last_pos.x = swapint(obj->last_pos.x); + obj->last_pos.y = swapint(obj->last_pos.y); + obj->last_pos.z = swapint(obj->last_pos.z); + + obj->lifeleft = swapint(obj->lifeleft); + + switch (obj->movement_type) { + + case MT_PHYSICS: + + obj->mtype.phys_info.velocity.x = swapint(obj->mtype.phys_info.velocity.x); + obj->mtype.phys_info.velocity.y = swapint(obj->mtype.phys_info.velocity.y); + obj->mtype.phys_info.velocity.z = swapint(obj->mtype.phys_info.velocity.z); + + obj->mtype.phys_info.thrust.x = swapint(obj->mtype.phys_info.thrust.x); + obj->mtype.phys_info.thrust.y = swapint(obj->mtype.phys_info.thrust.y); + obj->mtype.phys_info.thrust.z = swapint(obj->mtype.phys_info.thrust.z); + + obj->mtype.phys_info.mass = swapint(obj->mtype.phys_info.mass); + obj->mtype.phys_info.drag = swapint(obj->mtype.phys_info.drag); + obj->mtype.phys_info.brakes = swapint(obj->mtype.phys_info.brakes); + + obj->mtype.phys_info.rotvel.x = swapint(obj->mtype.phys_info.rotvel.x); + obj->mtype.phys_info.rotvel.y = swapint(obj->mtype.phys_info.rotvel.y); + obj->mtype.phys_info.rotvel.z = swapint(obj->mtype.phys_info.rotvel.z); + + obj->mtype.phys_info.rotthrust.x = swapint(obj->mtype.phys_info.rotthrust.x); + obj->mtype.phys_info.rotthrust.y = swapint(obj->mtype.phys_info.rotthrust.y); + obj->mtype.phys_info.rotthrust.z = swapint(obj->mtype.phys_info.rotthrust.z); + + obj->mtype.phys_info.turnroll = swapint(obj->mtype.phys_info.turnroll); + obj->mtype.phys_info.flags = swapshort(obj->mtype.phys_info.flags); + + break; + + case MT_SPINNING: + + obj->mtype.spin_rate.x = swapint(obj->mtype.spin_rate.x); + obj->mtype.spin_rate.y = swapint(obj->mtype.spin_rate.y); + obj->mtype.spin_rate.z = swapint(obj->mtype.spin_rate.z); + break; + } + + switch (obj->control_type) { + + case CT_WEAPON: + obj->ctype.laser_info.parent_type = swapshort(obj->ctype.laser_info.parent_type); + obj->ctype.laser_info.parent_num = swapshort(obj->ctype.laser_info.parent_num); + obj->ctype.laser_info.parent_signature = swapshort(obj->ctype.laser_info.parent_signature); + obj->ctype.laser_info.creation_time = swapint(obj->ctype.laser_info.creation_time); + obj->ctype.laser_info.last_hitobj = swapint(obj->ctype.laser_info.last_hitobj); + obj->ctype.laser_info.multiplier = swapint(obj->ctype.laser_info.multiplier); + break; + + case CT_EXPLOSION: + obj->ctype.expl_info.spawn_time = swapint(obj->ctype.expl_info.spawn_time); + obj->ctype.expl_info.delete_time = swapint(obj->ctype.expl_info.delete_time); + obj->ctype.expl_info.delete_objnum = swapshort(obj->ctype.expl_info.delete_objnum); + obj->ctype.expl_info.attach_parent = swapshort(obj->ctype.expl_info.attach_parent); + obj->ctype.expl_info.prev_attach = swapshort(obj->ctype.expl_info.prev_attach); + obj->ctype.expl_info.next_attach = swapshort(obj->ctype.expl_info.next_attach); + break; + + case CT_AI: + obj->ctype.ai_info.hide_segment = swapshort(obj->ctype.ai_info.hide_segment); + obj->ctype.ai_info.hide_index = swapshort(obj->ctype.ai_info.hide_index); + obj->ctype.ai_info.path_length = swapshort(obj->ctype.ai_info.path_length); + obj->ctype.ai_info.cur_path_index = swapshort(obj->ctype.ai_info.cur_path_index); +// obj->ctype.ai_info.follow_path_start_seg = swapshort(obj->ctype.ai_info.follow_path_start_seg); +// obj->ctype.ai_info.follow_path_end_seg = swapshort(obj->ctype.ai_info.follow_path_end_seg); + obj->ctype.ai_info.danger_laser_signature = swapint(obj->ctype.ai_info.danger_laser_signature); + obj->ctype.ai_info.danger_laser_num = swapshort(obj->ctype.ai_info.danger_laser_num); + break; + + case CT_LIGHT: + obj->ctype.light_info.intensity = swapint(obj->ctype.light_info.intensity); + break; + + case CT_POWERUP: + obj->ctype.powerup_info.count = swapint(obj->ctype.powerup_info.count); + if (obj->id == POW_VULCAN_WEAPON) + obj->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT; + break; + + } + + switch (obj->render_type) { + + case RT_MORPH: + case RT_POLYOBJ: { + int i; + + obj->rtype.pobj_info.model_num = swapint(obj->rtype.pobj_info.model_num); + + for (i=0;irtype.pobj_info.anim_angles[i].p = swapint(obj->rtype.pobj_info.anim_angles[i].p); + obj->rtype.pobj_info.anim_angles[i].b = swapint(obj->rtype.pobj_info.anim_angles[i].b); + obj->rtype.pobj_info.anim_angles[i].h = swapint(obj->rtype.pobj_info.anim_angles[i].h); + } + + obj->rtype.pobj_info.subobj_flags = swapint(obj->rtype.pobj_info.subobj_flags); + obj->rtype.pobj_info.tmap_override = swapint(obj->rtype.pobj_info.tmap_override); + obj->rtype.pobj_info.alt_textures = swapint(obj->rtype.pobj_info.alt_textures); + break; + } + + case RT_WEAPON_VCLIP: + case RT_HOSTAGE: + case RT_POWERUP: + case RT_FIREBALL: + obj->rtype.vclip_info.vclip_num = swapint(obj->rtype.vclip_info.vclip_num); + obj->rtype.vclip_info.frametime = swapint(obj->rtype.vclip_info.frametime); + break; + + case RT_LASER: + break; + + } +// END OF SWAPPING OBJECT STRUCTURE + +} diff --git a/main/netpkt.h b/main/netpkt.h new file mode 100644 index 00000000..7785876f --- /dev/null +++ b/main/netpkt.h @@ -0,0 +1,28 @@ +#ifndef _NETPKTOR_H +#define _NETPKTOR_H + +//Changed 9/19 -Geoff Coovert - moved from netpkt.c +//edited 03/04/99 Matt Mueller - moved to byteswap.h +#include "byteswap.h" +//#define swapint(x) x +//#define swapshort(x) x +//end edit -MM + +byte out_buffer[IPX_MAX_DATA_SIZE]; // used for tmp netgame packets as well as sending object data +extern frame_info MySyncPack; +void send_dxx_netgame_packet(ubyte *server, ubyte *node); +void receive_dxx_netgame_packet(ubyte *data, netgame_info *netgame, AllNetPlayers_info *netplayers); +//end change + +void receive_netplayer_info(ubyte *data, netplayer_info *info, int dxx); +void send_sequence_packet(sequence_packet seq, ubyte *server, ubyte *node, ubyte *net_address); +void receive_sequence_packet(ubyte *data, sequence_packet *seq); +void send_netgame_packet(ubyte *server, ubyte *node); +void receive_netgame_packet(ubyte *data, netgame_info *netgame, AllNetPlayers_info *netplayers, int dxx); +void send_frameinfo_packet(ubyte *server, ubyte *node, ubyte *address, int short_packet); +void receive_frameinfo_packet(ubyte *data, frame_info *info, int short_packet); +void send_endlevel_packet(endlevel_info *info, ubyte *server, ubyte *node, ubyte *address); +void receive_endlevel_packet(ubyte *data, endlevel_info *info); +void swap_object(object *obj); + +#endif diff --git a/main/reorder.h b/main/reorder.h new file mode 100644 index 00000000..80e9b8e3 --- /dev/null +++ b/main/reorder.h @@ -0,0 +1,20 @@ +/* + * $Source: /cvs/cvsroot/d2x/main/reorder.h,v $ + * $Revision: 1.1 $ + * $Author: bradleyb $ + * $Date: 2002-02-14 09:05:33 $ + * + * User interface+data for weapon autoselect order selection + * + * $Log: not supported by cvs2svn $ + * + */ + +#ifndef _REORDER_H +#define _REORDER_H + +/* These are defined in weapon.c */ +extern void ReorderPrimary(); +extern void ReorderSecondary(); + +#endif -- 2.39.2