From 44d1924e96464f7f624c06467fbccaedbbf6304b Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 5 Jul 2014 16:48:12 +0000 Subject: [PATCH] Use special type for player callsign --- common/main/config.h | 2 +- common/main/multi.h | 6 +-- common/main/player.h | 68 +++++++++++++++++++++++++++-- similar/main/collide.cpp | 4 +- similar/main/config.cpp | 9 ++-- similar/main/gamerend.cpp | 8 ++-- similar/main/gauges.cpp | 16 ++++--- similar/main/inferno.cpp | 10 +++-- similar/main/kmatrix.cpp | 4 +- similar/main/menu.cpp | 26 +++++------ similar/main/multi.cpp | 89 ++++++++++++++++++------------------- similar/main/net_udp.cpp | 92 ++++++++++++++++++++------------------- similar/main/newdemo.cpp | 36 +++++++-------- similar/main/playsave.cpp | 14 +++--- similar/main/scores.cpp | 26 +++++------ similar/main/state.cpp | 24 +++++----- 16 files changed, 248 insertions(+), 186 deletions(-) diff --git a/common/main/config.h b/common/main/config.h index 0d872fddd..9499d3f7d 100644 --- a/common/main/config.h +++ b/common/main/config.h @@ -45,7 +45,7 @@ struct Cfg : public prohibit_void_ptr char CMLevelMusicPath[PATH_MAX+1]; char CMMiscMusic[5][PATH_MAX+1]; int GammaLevel; - char LastPlayer[CALLSIGN_LEN+1]; + callsign_t LastPlayer; char LastMission[MISSION_NAME_LEN+1]; int ResolutionX; int ResolutionY; diff --git a/common/main/multi.h b/common/main/multi.h index 7c45b5992..24ed6db78 100644 --- a/common/main/multi.h +++ b/common/main/multi.h @@ -469,7 +469,7 @@ struct netplayer_info : prohibit_void_ptr #endif } protocol; #endif - char callsign[CALLSIGN_LEN+1]; + callsign_t callsign; sbyte connected; ubyte rank; fix ping; @@ -497,7 +497,7 @@ struct netgame_info : prohibit_void_ptr #endif } protocol; #endif - struct netplayer_info players[MAX_PLAYERS+4]; + array players; char game_name[NETGAME_NAME_LEN+1]; char mission_title[MISSION_NAME_LEN+1]; char mission_name[9]; @@ -522,7 +522,7 @@ struct netgame_info : prohibit_void_ptr short ShowEnemyNames; short BrightPlayers; short InvulAppear; - char team_name[2][CALLSIGN_LEN+1]; + callsign_t team_name[2]; int locations[MAX_PLAYERS]; short kills[MAX_PLAYERS][MAX_PLAYERS]; ushort segments_checksum; diff --git a/common/main/player.h b/common/main/player.h index a74bf1316..2390c45e0 100644 --- a/common/main/player.h +++ b/common/main/player.h @@ -33,9 +33,15 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef __cplusplus +#include +#include #include "pack.h" +#include "dxxsconf.h" +#include "compiler-array.h" +#include "compiler-begin.h" +#include "compiler-static_assert.h" -#define MAX_PLAYERS 8 +#define MAX_PLAYERS 8u #define MAX_MULTI_PLAYERS MAX_PLAYERS+3 // Initial player stat values @@ -86,12 +92,68 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II) + +struct callsign_t +{ + typedef array array_t; + array_t a; + static char lower_predicate(char c) + { + return std::tolower(static_cast(c)); + } + callsign_t &zero_terminate(array_t::iterator i) + { + std::fill(i, end(a), 0); + return *this; + } + callsign_t ©(const char *s, std::size_t N) + { + return zero_terminate(std::copy_n(s, std::min(a.size() - 1, N), begin(a))); + } + callsign_t ©_lower(const char *s, std::size_t N) + { + return zero_terminate(std::transform(s, std::next(s, std::min(a.size() - 1, N)), begin(a), lower_predicate)); + } + void lower() + { + auto ba = begin(a); + std::transform(ba, std::prev(end(a)), ba, lower_predicate); + a.back() = 0; + } + char (& buffer())[CALLSIGN_LEN + 1] + { + return reinterpret_cast(*a.data()); + } + template + callsign_t &operator=(const char (&s)[N]) + { + static_assert(N <= CALLSIGN_LEN + 1, "string too long"); + return copy(s, N); + } + template + void copy_lower(const char (&s)[N]) + { + static_assert(N <= CALLSIGN_LEN + 1, "string too long"); + return copy_lower(s, N); + } + void fill(char c) { a.fill(c); } + const char &operator[](std::size_t i) const + { + return a[i]; + } + operator const char *() const + { + return &a[0]; + }; +}; +static_assert(sizeof(callsign_t) == CALLSIGN_LEN + 1, "callsign_t too big"); + // When this structure changes, increment the constant // SAVE_FILE_VERSION in playsave.c struct player : public prohibit_void_ptr { // Who am I data - char callsign[CALLSIGN_LEN+1]; // The callsign of this player, for net purposes. + callsign_t callsign; // The callsign of this player, for net purposes. sbyte connected; // Is the player connected or not? int objnum; // What object number this player is. (made an int by mk because it's very often referenced) @@ -145,7 +207,7 @@ struct player : public prohibit_void_ptr struct player_rw { // Who am I data - char callsign[CALLSIGN_LEN+1]; // The callsign of this player, for net purposes. + callsign_t callsign; // The callsign of this player, for net purposes. ubyte net_address[6]; // The network address of the player. sbyte connected; // Is the player connected or not? int objnum; // What object number this player is. (made an int by mk because it's very often referenced) diff --git a/similar/main/collide.cpp b/similar/main/collide.cpp index 50cf788c5..0d51c025c 100644 --- a/similar/main/collide.cpp +++ b/similar/main/collide.cpp @@ -1145,7 +1145,7 @@ static void collide_player_and_marker( objptridx_t marker, object * playerobj, if (Game_mode & GM_MULTI) { - drawn = HUD_init_message(HM_DEFAULT|HM_MAYDUPL, "MARKER %s: %s",Players[marker->id/2].callsign,&MarkerMessage[marker->id][0]); + drawn = HUD_init_message(HM_DEFAULT|HM_MAYDUPL, "MARKER %s: %s", static_cast(Players[marker->id/2].callsign), &MarkerMessage[marker->id][0]); } else { @@ -1334,7 +1334,7 @@ void do_final_boss_hacks(void) Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE; } if (!(Game_mode & GM_MULTI)) - buddy_message("Nice job, %s!", Players[Player_num].callsign); + buddy_message("Nice job, %s!", static_cast(Players[Player_num].callsign)); Final_boss_is_dead = 1; } diff --git a/similar/main/config.cpp b/similar/main/config.cpp index 1a8391923..a8b78b464 100644 --- a/similar/main/config.cpp +++ b/similar/main/config.cpp @@ -118,7 +118,7 @@ int ReadConfigFile() snprintf(GameCfg.CMMiscMusic[SONG_ENDGAME], PATH_MAX, "%s%s", PHYSFS_getUserDir(), "Music/iTunes/iTunes Music/Insanity/Descent/14 Insanity.mp3"); #endif GameCfg.GammaLevel = 0; - memset(GameCfg.LastPlayer,0,CALLSIGN_LEN+1); + GameCfg.LastPlayer.fill(0); memset(GameCfg.LastMission,0,MISSION_NAME_LEN+1); GameCfg.ResolutionX = 640; GameCfg.ResolutionY = 480; @@ -211,10 +211,7 @@ int ReadConfigFile() gr_palette_set_gamma( GameCfg.GammaLevel ); } else if (!strcmp(token, LastPlayerStr)) { - char * p; - strncpy( GameCfg.LastPlayer, value, CALLSIGN_LEN ); - p = strchr( GameCfg.LastPlayer, '\n'); - if ( p ) *p = 0; + GameCfg.LastPlayer.copy_lower(value, std::distance(value, std::find(value, const_cast(line.get()) + max_len, '\n'))); } else if (!strcmp(token, LastMissionStr)) { char * p; @@ -289,7 +286,7 @@ int WriteConfigFile() PHYSFSX_printf(infile, "%s=%s\n", CMMiscMusic3Str, GameCfg.CMMiscMusic[SONG_ENDGAME]); PHYSFSX_printf(infile, "%s=%s\n", CMMiscMusic4Str, GameCfg.CMMiscMusic[SONG_CREDITS]); PHYSFSX_printf(infile, "%s=%d\n", GammaLevelStr, GameCfg.GammaLevel); - PHYSFSX_printf(infile, "%s=%s\n", LastPlayerStr, Players[Player_num].callsign); + PHYSFSX_printf(infile, "%s=%s\n", LastPlayerStr, static_cast(Players[Player_num].callsign)); PHYSFSX_printf(infile, "%s=%s\n", LastMissionStr, GameCfg.LastMission); PHYSFSX_printf(infile, "%s=%i\n", ResolutionXStr, SM_W(Game_screen_mode)); PHYSFSX_printf(infile, "%s=%i\n", ResolutionYStr, SM_H(Game_screen_mode)); diff --git a/similar/main/gamerend.cpp b/similar/main/gamerend.cpp index e1fe1a92b..084f40127 100644 --- a/similar/main/gamerend.cpp +++ b/similar/main/gamerend.cpp @@ -195,7 +195,7 @@ static void show_netplayerinfo() else color=i; gr_set_fontcolor( BM_XRGB(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b),-1 ); - gr_printf(x,y,"%s\n",Players[i].callsign); + gr_printf(x,y,"%s\n",static_cast(Players[i].callsign)); if (Game_mode & GM_MULTI_COOP) gr_printf(x+FSPACX(8)*7,y,"%-6d",Players[i].score); else @@ -219,11 +219,11 @@ static void show_netplayerinfo() gr_string(x+FSPACX(8)*8,y,"score"); y+=LINE_SPACING; gr_set_fontcolor(BM_XRGB(player_rgb[0].r,player_rgb[0].g,player_rgb[0].b),-1 ); - gr_printf(x,y,"%s:",Netgame.team_name[0]); + gr_printf(x,y,"%s:",static_cast(Netgame.team_name[0])); gr_printf(x+FSPACX(8)*8,y,"%i",team_kills[0]); y+=LINE_SPACING; gr_set_fontcolor(BM_XRGB(player_rgb[1].r,player_rgb[1].g,player_rgb[1].b),-1 ); - gr_printf(x,y,"%s:",Netgame.team_name[1]); + gr_printf(x,y,"%s:",static_cast(Netgame.team_name[1])); gr_printf(x+FSPACX(8)*8,y,"%i",team_kills[1]); y+=LINE_SPACING*2; } @@ -243,7 +243,7 @@ static void show_netplayerinfo() if (PhallicMan==-1) gr_string(0x8000,y,"There is no record yet for this level."); else - gr_printf(0x8000,y,"%s has the record at %d points.",Players[PhallicMan].callsign,PhallicLimit); + gr_printf(0x8000,y,"%s has the record at %d points.", static_cast(Players[PhallicMan].callsign), PhallicLimit); } else #endif diff --git a/similar/main/gauges.cpp b/similar/main/gauges.cpp index 9b0ffc51d..7663ce173 100644 --- a/similar/main/gauges.cpp +++ b/similar/main/gauges.cpp @@ -2692,7 +2692,7 @@ static void hud_show_kill_list() for (i=0;i=n_left) { @@ -2742,14 +2742,16 @@ static void hud_show_kill_list() } if (Show_kill_list == 3) - strcpy(name, Netgame.team_name[i]); + name = Netgame.team_name[i]; else if (Game_mode & GM_BOUNTY && player_num == Bounty_target && GameTime64&0x10000) - strcpy(name,"[TARGET]"); + { + name = "[TARGET]"; + } else - strcpy(name,Players[player_num].callsign); // Note link to above if!! - gr_get_string_size(name,&sw,&sh,&aw); + name = Players[player_num].callsign; // Note link to above if!! + gr_get_string_size(static_cast(name),&sw,&sh,&aw); while (sw > (x1-x0-FSPACX(2))) { - name[strlen(name)-1]=0; + name.buffer()[strlen(name)-1]=0; gr_get_string_size(name,&sw,&sh,&aw); } gr_string(x0,y,name); @@ -2853,7 +2855,7 @@ void show_HUD_names() if( Game_mode & GM_BOUNTY && pnum == Bounty_target ) name = "Target"; else if (show_name) - name = Players[pnum].callsign; + name = static_cast(Players[pnum].callsign); const char *trailer = NULL; if (show_typing) { diff --git a/similar/main/inferno.cpp b/similar/main/inferno.cpp index d2e23dec7..abfa9d6bd 100644 --- a/similar/main/inferno.cpp +++ b/similar/main/inferno.cpp @@ -100,6 +100,9 @@ char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPOR #include "net_udp.h" #endif +#include "dxxsconf.h" +#include "compiler-begin.h" + int Screen_mode=-1; //game screen or editor screen? #if defined(DXX_BUILD_DESCENT_I) @@ -475,7 +478,7 @@ int main(int argc, char *argv[]) con_printf( CON_DEBUG, "\nRunning game..." ); init_game(); - Players[Player_num].callsign[0] = '\0'; + Players[Player_num].callsign.fill(0); #if defined(DXX_BUILD_DESCENT_I) key_flush(); @@ -485,7 +488,7 @@ int main(int argc, char *argv[]) #ifdef EDITOR if (GameArg.EdiAutoLoad) { strcpy(Auto_file, GameArg.EdiAutoLoad); - strcpy(Players[0].callsign, "dummy"); + Players[0].callsign = "dummy"; } else #endif #endif @@ -510,7 +513,8 @@ int main(int argc, char *argv[]) if(PHYSFSX_exists(filename,0)) { filename[j - 4] = 0; - strcpy(Players[Player_num].callsign, GameArg.SysUsePlayersDir? &filename[8] : filename); + char *b = GameArg.SysUsePlayersDir? &filename[8] : filename; + Players[Player_num].callsign.copy(b, std::distance(b, end(filename))); read_player_file(); WriteConfigFile(); } diff --git a/similar/main/kmatrix.cpp b/similar/main/kmatrix.cpp index 1555d86c1..86af42887 100644 --- a/similar/main/kmatrix.cpp +++ b/similar/main/kmatrix.cpp @@ -71,7 +71,7 @@ static void kmatrix_draw_item( int i, int *sorted ) char temp[10]; y = FSPACY(50+i*9); - gr_string( FSPACX(CENTERING_OFFSET(N_players)), y, Players[sorted[i]].callsign ); + gr_string(FSPACX(CENTERING_OFFSET(N_players)), y, static_cast(Players[sorted[i]].callsign)); for (j=0; j(Players[sorted[i]].callsign)); x = CENTERSCREEN; gr_set_fontcolor( BM_XRGB(60,40,10),-1 ); gr_printf( x, y, "%d", Players[sorted[i]].score ); diff --git a/similar/main/menu.cpp b/similar/main/menu.cpp index 76a366fcd..6d0cf28e7 100644 --- a/similar/main/menu.cpp +++ b/similar/main/menu.cpp @@ -87,6 +87,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "ogl_init.h" #endif +#include "dxxsconf.h" +#include "compiler-begin.h" // Menu IDs... enum MENUS @@ -201,12 +203,10 @@ static int MakeNewPlayerFile(int allow_abort) int x; char filename[PATH_MAX]; newmenu_item m; - char text[CALLSIGN_LEN+9]=""; - - strncpy(text, Players[Player_num].callsign,CALLSIGN_LEN); + callsign_t text = Players[Player_num].callsign; try_again: - nm_set_item_input(&m, CALLSIGN_LEN, text); + nm_set_item_input(&m, CALLSIGN_LEN, text.buffer()); Newmenu_allowed_chars = playername_allowed_chars; x = newmenu_do( NULL, TXT_ENTER_PILOT_NAME, 1, &m, unused_newmenu_subfunction, unused_newmenu_userdata ); @@ -220,21 +220,20 @@ try_again: if (text[0]==0) //null string goto try_again; - d_strlwr(text); + text.lower(); - snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%s.plr"), text ); + snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%s.plr"), static_cast(text) ); if (PHYSFSX_exists(filename,0)) { - nm_messagebox(NULL, 1, TXT_OK, "%s '%s' %s", TXT_PLAYER, text, TXT_ALREADY_EXISTS ); + nm_messagebox(NULL, 1, TXT_OK, "%s '%s' %s", TXT_PLAYER, static_cast(text), TXT_ALREADY_EXISTS ); goto try_again; } if ( !new_player_config() ) goto try_again; // They hit Esc during New player config - strncpy(Players[Player_num].callsign, text, CALLSIGN_LEN); - d_strlwr(Players[Player_num].callsign); + Players[Player_num].callsign = text; write_player_file(); @@ -316,8 +315,7 @@ static int player_menu_handler( listbox *lb, d_event *event, char **list ) } else { - strncpy(Players[Player_num].callsign,items[citem] + ((items[citem][0]=='$')?1:0), CALLSIGN_LEN); - d_strlwr(Players[Player_num].callsign); + Players[Player_num].callsign.copy_lower(items[citem], ~0u); } break; @@ -353,13 +351,13 @@ int RegisterPlayer() { if (GameCfg.LastPlayer[0]==0) { - strncpy( Players[Player_num].callsign, "player", CALLSIGN_LEN ); + Players[Player_num].callsign = "player"; allow_abort_flag = 0; } else { // Read the last player's name from config file, not lastplr.txt - strncpy( Players[Player_num].callsign, GameCfg.LastPlayer, CALLSIGN_LEN ); + Players[Player_num].callsign = GameCfg.LastPlayer; } } @@ -413,7 +411,7 @@ int RegisterPlayer() qsort(&m[1], NumItems - 1, sizeof(char *), (int (*)( const void *, const void * ))string_array_sort_func); for ( i=0; i(Players[Player_num].callsign), m[i]) ) citem = i; newmenu_listbox1(TXT_SELECT_PILOT, NumItems, m, allow_abort_flag, citem, player_menu_handler, list); diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index 8018469b6..e23ad4573 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -596,11 +596,11 @@ static const char *prepare_kill_name(unsigned pnum, char (&buf)[(CALLSIGN_LEN*2) { if (Game_mode & GM_TEAM) { - snprintf(buf, sizeof(buf), "%s (%s)", Players[pnum].callsign, Netgame.team_name[get_team(pnum)]); + snprintf(buf, sizeof(buf), "%s (%s)", static_cast(Players[pnum].callsign), static_cast(Netgame.team_name[get_team(pnum)])); return buf; } else - return Players[pnum].callsign; + return static_cast(Players[pnum].callsign); } static void multi_compute_kill(int killer, int killed) @@ -824,7 +824,7 @@ static void multi_compute_kill(int killer, int killed) Players[Player_num].shields=i2f(200); } else - HUD_init_message(HM_MULTI, "%s has reached the kill goal!",Players[killer_pnum].callsign); + HUD_init_message(HM_MULTI, "%s has reached the kill goal!", static_cast(Players[killer_pnum].callsign)); HUD_init_message_literal(HM_MULTI, "The control center has been destroyed!"); net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN)); @@ -1119,7 +1119,7 @@ static void multi_message_feedback(void) std::size_t feedlen = snprintf(feedback_result, sizeof(feedback_result), "%s ", TXT_MESSAGE_SENT_TO); if ((Game_mode & GM_TEAM) && (Network_message[0] == '1' || Network_message[0] == '2')) { - snprintf(feedback_result + feedlen, sizeof(feedback_result) - feedlen, "%s '%s'", TXT_TEAM, Netgame.team_name[Network_message[0] - '1']); + snprintf(feedback_result + feedlen, sizeof(feedback_result) - feedlen, "%s '%s'", TXT_TEAM, static_cast(Netgame.team_name[Network_message[0] - '1'])); found = 1; } if (Game_mode & GM_TEAM) @@ -1128,18 +1128,17 @@ static void multi_message_feedback(void) { if (!d_strnicmp(Netgame.team_name[i], Network_message, colon-Network_message)) { - if (found) - strcat(feedback_result, ", "); + const char *comma = found ? ", " : ""; found++; - if (!(found % 4)) - strcat(feedback_result, "\n"); - sprintf(feedback_result+strlen(feedback_result), "%s '%s'", TXT_TEAM, Netgame.team_name[i]); + const char *newline = (!(found % 4)) ? "\n" : ""; + size_t l = strlen(feedback_result); + snprintf(feedback_result + l, sizeof(feedback_result) - l, "%s%s%s '%s'", comma, newline, TXT_TEAM, static_cast(Netgame.team_name[i])); } } } for (i = 0; i < N_players; i++) { - if ((!d_strnicmp(Players[i].callsign, Network_message, colon-Network_message)) && (i != Player_num) && (Players[i].connected)) + if ((!d_strnicmp(static_cast(Players[i].callsign), Network_message, colon-Network_message)) && (i != Player_num) && (Players[i].connected)) { const char *comma = found ? ", " : ""; found++; @@ -1229,11 +1228,11 @@ static void multi_send_message_end() StartingShields=10; if (StartingShields>100) { - sprintf (Network_message,"%s has tried to cheat!",Players[Player_num].callsign); + snprintf (Network_message, sizeof(Network_message), "%s has tried to cheat!",static_cast(Players[Player_num].callsign)); StartingShields=100; } else - sprintf (Network_message,"%s handicap is now %d",Players[Player_num].callsign,StartingShields); + snprintf (Network_message, sizeof(Network_message), "%s handicap is now %d",static_cast(Players[Player_num].callsign), StartingShields); HUD_init_message(HM_MULTI, "Telling others of your handicap of %d!",StartingShields); StartingShields=i2f(StartingShields); @@ -1249,7 +1248,7 @@ static void multi_send_message_end() if (!multi_i_am_master()) { - HUD_init_message(HM_MULTI, "Only %s can move players!",Players[multi_who_is_master()].callsign); + HUD_init_message(HM_MULTI, "Only %s can move players!",static_cast(Players[multi_who_is_master()].callsign)); return; } @@ -1260,7 +1259,7 @@ static void multi_send_message_end() } for (i = 0; i < N_players; i++) - if ((!d_strnicmp(Players[i].callsign, &Network_message[name_index], strlen(Network_message)-name_index)) && (Players[i].connected)) + if ((!d_strnicmp(static_cast(Players[i].callsign), &Network_message[name_index], strlen(Network_message)-name_index)) && (Players[i].connected)) { #if defined(DXX_BUILD_DESCENT_II) if (game_mode_capture_flag() && (Players[i].flags & PLAYER_FLAGS_FLAG)) @@ -1281,14 +1280,14 @@ static void multi_send_message_end() multi_send_gmode_update(); - sprintf (Network_message,"%s has changed teams!",Players[i].callsign); + snprintf (Network_message, sizeof(Network_message), "%s has changed teams!", static_cast(Players[i].callsign)); if (i==Player_num) { HUD_init_message_literal(HM_MULTI, "You have changed teams!"); reset_cockpit(); } else - HUD_init_message(HM_MULTI, "Moving %s to other team.",Players[i].callsign); + HUD_init_message(HM_MULTI, "Moving %s to other team.", static_cast(Players[i].callsign)); break; } } @@ -1303,7 +1302,7 @@ static void multi_send_message_end() if (!multi_i_am_master()) { - HUD_init_message(HM_MULTI, "Only %s can kick others out!",Players[multi_who_is_master()].callsign); + HUD_init_message(HM_MULTI, "Only %s can kick others out!", static_cast(Players[multi_who_is_master()].callsign)); multi_message_index = 0; multi_sending_message[Player_num] = msgsend_none; #if defined(DXX_BUILD_DESCENT_II) @@ -1354,7 +1353,7 @@ static void multi_send_message_end() for (i = 0; i < N_players; i++) - if ((!d_strnicmp(Players[i].callsign, &Network_message[name_index], strlen(Network_message)-name_index)) && (i != Player_num) && (Players[i].connected)) { + if ((!d_strnicmp(static_cast(Players[i].callsign), &Network_message[name_index], strlen(Network_message)-name_index)) && (i != Player_num) && (Players[i].connected)) { kick_player:; switch (multi_protocol) { @@ -1368,7 +1367,7 @@ static void multi_send_message_end() break; } - HUD_init_message(HM_MULTI, "Dumping %s...",Players[i].callsign); + HUD_init_message(HM_MULTI, "Dumping %s...", static_cast(Players[i].callsign)); multi_message_index = 0; multi_sending_message[Player_num] = msgsend_none; #if defined(DXX_BUILD_DESCENT_II) @@ -1381,7 +1380,7 @@ static void multi_send_message_end() else if (!d_strnicmp (Network_message,"/killreactor",12) && (Game_mode & GM_NETWORK) && !Control_center_destroyed) { if (!multi_i_am_master()) - HUD_init_message(HM_MULTI, "Only %s can kill the reactor this way!",Players[multi_who_is_master()].callsign); + HUD_init_message(HM_MULTI, "Only %s can kill the reactor this way!", static_cast(Players[multi_who_is_master()].callsign)); else { net_destroy_controlcen(object_none); @@ -1612,12 +1611,12 @@ static multi_do_message(const ubyte *cbuf) color = (int)buf[1]; char xrgb = BM_XRGB(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b); digi_play_sample(SOUND_HUD_MESSAGE, F1_0); - HUD_init_message(HM_MULTI, "%c%c%s:%c%c %s", CC_COLOR, xrgb, Players[(int)buf[1]].callsign, CC_COLOR, BM_XRGB(0, 31, 0), buf+2); + HUD_init_message(HM_MULTI, "%c%c%s:%c%c %s", CC_COLOR, xrgb, static_cast(Players[(int)buf[1]].callsign), CC_COLOR, BM_XRGB(0, 31, 0), buf+2); multi_sending_message[(int)buf[1]] = msgsend_none; } else { - if ( (!d_strnicmp(Players[Player_num].callsign, buf+loc, colon-(buf+loc))) || + if ( (!d_strnicmp(static_cast(Players[Player_num].callsign), buf+loc, colon-(buf+loc))) || ((Game_mode & GM_TEAM) && ( (get_team(Player_num) == atoi(buf+loc)-1) || !d_strnicmp(Netgame.team_name[get_team(Player_num)], buf+loc, colon-(buf+loc)))) ) { int color = 0; @@ -1628,7 +1627,7 @@ static multi_do_message(const ubyte *cbuf) char xrgb = BM_XRGB(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b); digi_play_sample(SOUND_HUD_MESSAGE, F1_0); - HUD_init_message(HM_MULTI, "%c%c%s:%c%c %s", CC_COLOR, xrgb, Players[(int)buf[1]].callsign, CC_COLOR, BM_XRGB(0, 31, 0), colon+2); + HUD_init_message(HM_MULTI, "%c%c%s:%c%c %s", CC_COLOR, xrgb, static_cast(Players[(int)buf[1]].callsign), CC_COLOR, BM_XRGB(0, 31, 0), colon+2); multi_sending_message[(int)buf[1]] = msgsend_none; } } @@ -1835,7 +1834,7 @@ static void multi_do_controlcen_destroy(const ubyte *buf) if (Control_center_destroyed != 1) { if ((who < N_players) && (who != Player_num)) { - HUD_init_message(HM_MULTI, "%s %s", Players[who].callsign, TXT_HAS_DEST_CONTROL); + HUD_init_message(HM_MULTI, "%s %s", static_cast(Players[who].callsign), TXT_HAS_DEST_CONTROL); } else if (who == Player_num) HUD_init_message_literal(HM_MULTI, TXT_YOU_DEST_CONTROL); @@ -1863,7 +1862,7 @@ static multi_do_escape(const ubyte *buf) if (buf[2] == 0) { - HUD_init_message(HM_MULTI, "%s %s", Players[(int)buf[1]].callsign, TXT_HAS_ESCAPED); + HUD_init_message(HM_MULTI, "%s %s", static_cast(Players[(int)buf[1]].callsign), TXT_HAS_ESCAPED); if (Game_mode & GM_NETWORK) Players[(int)buf[1]].connected = CONNECT_ESCAPE_TUNNEL; if (!multi_goto_secret) @@ -1871,7 +1870,7 @@ static multi_do_escape(const ubyte *buf) } else if (buf[2] == 1) { - HUD_init_message(HM_MULTI, "%s %s", Players[(int)buf[1]].callsign, TXT_HAS_FOUND_SECRET); + HUD_init_message(HM_MULTI, "%s %s", static_cast(Players[(int)buf[1]].callsign), TXT_HAS_FOUND_SECRET); if (Game_mode & GM_NETWORK) Players[(int)buf[1]].connected = CONNECT_FOUND_SECRET; if (!multi_goto_secret) @@ -1945,7 +1944,7 @@ void multi_disconnect_player(int pnum) if (Players[pnum].connected == CONNECT_PLAYING) { digi_play_sample( SOUND_HUD_MESSAGE, F1_0 ); - HUD_init_message(HM_MULTI, "%s %s", Players[pnum].callsign, TXT_HAS_LEFT_THE_GAME); + HUD_init_message(HM_MULTI, "%s %s", static_cast(Players[pnum].callsign), TXT_HAS_LEFT_THE_GAME); multi_sending_message[pnum] = msgsend_none; @@ -2475,7 +2474,7 @@ multi_send_destroy_controlcen(int objnum, int player) if (player == Player_num) HUD_init_message_literal(HM_MULTI, TXT_YOU_DEST_CONTROL); else if ((player > 0) && (player < N_players)) - HUD_init_message(HM_MULTI, "%s %s", Players[player].callsign, TXT_HAS_DEST_CONTROL); + HUD_init_message(HM_MULTI, "%s %s", static_cast(Players[player].callsign), TXT_HAS_DEST_CONTROL); else HUD_init_message_literal(HM_MULTI, TXT_CONTROL_DESTROYED); @@ -3641,9 +3640,7 @@ void change_playernum_to( int new_Player_num ) // memcpy( Players[new_Player_num].callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 ); if (Player_num > -1) { - char buf[CALLSIGN_LEN+1]; - memcpy( buf, Players[Player_num].callsign, CALLSIGN_LEN+1 ); - strcpy(Players[new_Player_num].callsign,buf); + Players[new_Player_num].callsign = Players[Player_num].callsign; } Player_num = new_Player_num; @@ -3935,7 +3932,7 @@ void multi_check_for_killgoal_winner () } else - HUD_init_message(HM_MULTI, "%s has the best score with %d kills!",Players[bestnum].callsign,best); + HUD_init_message(HM_MULTI, "%s has the best score with %d kills!",static_cast(Players[bestnum].callsign),best); HUD_init_message_literal(HM_MULTI, "The control center has been destroyed!"); @@ -4115,7 +4112,7 @@ void multi_do_capture_bonus(const unsigned pnum, const ubyte *buf) if (pnum==Player_num) HUD_init_message_literal(HM_MULTI, "You have Scored!"); else - HUD_init_message(HM_MULTI, "%s has Scored!",Players[(int)pnum].callsign); + HUD_init_message(HM_MULTI, "%s has Scored!", static_cast(Players[pnum].callsign)); if (pnum==Player_num) digi_play_sample (SOUND_HUD_YOU_GOT_GOAL,F1_0*2); @@ -4142,7 +4139,7 @@ void multi_do_capture_bonus(const unsigned pnum, const ubyte *buf) Players[Player_num].shields=i2f(200); } else - HUD_init_message(HM_MULTI, "%s has reached the kill goal!",Players[(int)pnum].callsign); + HUD_init_message(HM_MULTI, "%s has reached the kill goal!",static_cast(Players[pnum].callsign)); HUD_init_message_literal(HM_MULTI, "The control center has been destroyed!"); net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN)); @@ -4172,7 +4169,7 @@ void multi_do_orb_bonus(const unsigned pnum, const ubyte *buf) if (pnum==Player_num) HUD_init_message(HM_MULTI, "You have scored %d points!",bonus); else - HUD_init_message(HM_MULTI, "%s has scored with %d orbs!",Players[(int)pnum].callsign,buf[2]); + HUD_init_message(HM_MULTI, "%s has scored with %d orbs!",static_cast(Players[pnum].callsign), buf[2]); if (pnum==Player_num) digi_start_sound_queued (SOUND_HUD_YOU_GOT_GOAL,F1_0*2); @@ -4191,7 +4188,7 @@ void multi_do_orb_bonus(const unsigned pnum, const ubyte *buf) if (pnum==Player_num) HUD_init_message(HM_MULTI, "You have the record with %d points!",bonus); else - HUD_init_message(HM_MULTI, "%s has the record with %d points!",Players[(int)pnum].callsign,bonus); + HUD_init_message(HM_MULTI, "%s has the record with %d points!",static_cast(Players[pnum].callsign),bonus); digi_play_sample (SOUND_BUDDY_MET_GOAL,F1_0*2); PhallicMan=pnum; PhallicLimit=bonus; @@ -4219,7 +4216,7 @@ void multi_do_orb_bonus(const unsigned pnum, const ubyte *buf) Players[Player_num].shields=i2f(200); } else - HUD_init_message(HM_MULTI, "%s has reached the kill goal!",Players[(int)pnum].callsign); + HUD_init_message(HM_MULTI, "%s has reached the kill goal!",static_cast(Players[pnum].callsign)); HUD_init_message_literal(HM_MULTI, "The control center has been destroyed!"); net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN)); @@ -4258,7 +4255,7 @@ static void multi_do_got_flag (const unsigned pnum, const ubyte *buf) else digi_start_sound_queued (SOUND_HUD_BLUE_GOT_FLAG,F1_0*2); Players[(int)pnum].flags|=PLAYER_FLAGS_FLAG; - HUD_init_message(HM_MULTI, "%s picked up a flag!",Players[(int)pnum].callsign); + HUD_init_message(HM_MULTI, "%s picked up a flag!",static_cast(Players[pnum].callsign)); } static void multi_do_got_orb (const unsigned pnum, const ubyte *buf) { @@ -4275,7 +4272,7 @@ static void multi_do_got_orb (const unsigned pnum, const ubyte *buf) digi_play_sample (SOUND_OPPONENT_GOT_ORB,F1_0*2); Players[(int)pnum].flags|=PLAYER_FLAGS_FLAG; - HUD_init_message(HM_MULTI, "%s picked up an orb!",Players[(int)pnum].callsign); + HUD_init_message(HM_MULTI, "%s picked up an orb!",static_cast(Players[pnum].callsign)); } @@ -4603,7 +4600,7 @@ static void multi_do_ranking (const unsigned pnum, const ubyte *buf) Netgame.players[(int)pnum].rank=rank; if (!PlayerCfg.NoRankings) - HUD_init_message(HM_MULTI, "%s has been %s to %s!",Players[(int)pnum].callsign,rankstr,RankStrings[(int)rank]); + HUD_init_message(HM_MULTI, "%s has been %s to %s!",static_cast(Players[pnum].callsign),rankstr,RankStrings[(int)rank]); } #endif @@ -4666,7 +4663,7 @@ void multi_new_bounty_target( int pnum ) /* Send a message */ HUD_init_message( HM_MULTI, "%c%c%s is the new target!", CC_COLOR, BM_XRGB( player_rgb[Bounty_target].r, player_rgb[Bounty_target].g, player_rgb[Bounty_target].b ), - Players[Bounty_target].callsign ); + static_cast(Players[Bounty_target].callsign)); #if defined(DXX_BUILD_DESCENT_I) digi_play_sample( SOUND_CONTROL_CENTER_WARNING_SIREN, F1_0 * 3 ); @@ -4748,7 +4745,7 @@ void multi_initiate_save_game() { for (j = i + 1; j < N_players; j++) { - if (i != j && !d_stricmp(Players[i].callsign, Players[j].callsign)) + if (i != j && Players[i].callsign == Players[j].callsign) { HUD_init_message_literal(HM_MULTI, "Can't save! Multiple players with same callsign!"); return; @@ -4769,7 +4766,7 @@ void multi_initiate_save_game() for (i = 0; i < N_players; i++ ) { fix call2i; - memcpy(&call2i, Players[i].callsign, sizeof(fix)); + memcpy(&call2i, static_cast(Players[i].callsign), sizeof(fix)); game_id ^= call2i; } if ( game_id == 0 ) @@ -4802,7 +4799,7 @@ void multi_initiate_restore_game() { for (j = i + 1; j < N_players; j++) { - if (i != j && !d_stricmp(Players[i].callsign, Players[j].callsign)) + if (i != j && Players[i].callsign == Players[j].callsign) { HUD_init_message_literal(HM_MULTI, "Can't load! Multiple players with same callsign!"); return; @@ -4828,7 +4825,7 @@ void multi_save_game(ubyte slot, uint id, char *desc) if ((Endlevel_sequence) || (Control_center_destroyed)) return; - snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%s.mg%d"), Players[Player_num].callsign, slot); + snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%s.mg%d"), static_cast(Players[Player_num].callsign), slot); HUD_init_message(HM_MULTI, "Saving game #%d, '%s'", slot, desc); stop_time(); state_game_id = id; @@ -4844,7 +4841,7 @@ void multi_restore_game(ubyte slot, uint id) if ((Endlevel_sequence) || (Control_center_destroyed)) return; - snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%s.mg%d"), Players[Player_num].callsign, slot); + snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%s.mg%d"), static_cast(Players[Player_num].callsign), slot); for (i = 0; i < N_players; i++) multi_strip_robots(i); diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index dd8a26d49..84cab040b 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -58,8 +58,11 @@ #include "vers_id.h" #include "u_mem.h" +#include "dxxsconf.h" #include "compiler-array.h" +#include "compiler-range_for.h" #include "compiler-lengthof.h" +#include "partial_range.h" // Prototypes static void net_udp_init(); @@ -1027,7 +1030,7 @@ static void net_udp_receive_sequence_packet(ubyte *data, UDP_sequence_packet *se int len = 0; seq->type = data[0]; len++; - memcpy(seq->player.callsign, &(data[len]), CALLSIGN_LEN+1); len += CALLSIGN_LEN+1; + memcpy(seq->player.callsign.buffer(), &(data[len]), CALLSIGN_LEN+1); len += CALLSIGN_LEN+1; seq->player.connected = data[len]; len++; memcpy (&(seq->player.rank),&(data[len]),1); len++; @@ -1060,7 +1063,7 @@ void net_udp_init() UDP_MData = {}; net_udp_noloss_init_mdata_queue(); UDP_Seq.type = UPID_REQUEST; - memcpy(UDP_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1); + UDP_Seq.player.callsign = Players[Player_num].callsign; UDP_Seq.player.rank=GetMyNetRanking(); @@ -1197,7 +1200,7 @@ static net_udp_can_join_netgame(netgame_info *game) // Search to see if we were already in this closed netgame in progress for (i = 0; i < num_players; i++) { - if ( (!d_stricmp(Players[Player_num].callsign, game->players[i].callsign)) && game->players[i].protocol.udp.isyou ) + if ( (Players[Player_num].callsign == game->players[i].callsign) && game->players[i].protocol.udp.isyou ) break; } @@ -1245,8 +1248,8 @@ static net_udp_new_player(UDP_sequence_packet *their) newdemo_record_multi_connect(pnum, new_player, their->player.callsign); } - memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1); - memcpy(Netgame.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1); + Players[pnum].callsign = their->player.callsign; + Netgame.players[pnum].callsign = their->player.callsign; memcpy(&Netgame.players[pnum].protocol.udp.addr, &their->player.protocol.udp.addr, sizeof(struct _sockaddr)); ClipRank (&their->player.rank); @@ -1271,9 +1274,9 @@ static net_udp_new_player(UDP_sequence_packet *their) ClipRank (&their->player.rank); if (PlayerCfg.NoRankings) - HUD_init_message(HM_MULTI, "'%s' %s\n",their->player.callsign, TXT_JOINING); + HUD_init_message(HM_MULTI, "'%s' %s\n", static_cast(their->player.callsign), TXT_JOINING); else - HUD_init_message(HM_MULTI, "%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING); + HUD_init_message(HM_MULTI, "%s'%s' %s\n",RankStrings[their->player.rank],static_cast(their->player.callsign), TXT_JOINING); multi_make_ghost_player(pnum); @@ -1327,7 +1330,7 @@ static void net_udp_welcome_player(UDP_sequence_packet *their) for (i = 0; i < N_players; i++) { - if ((!d_stricmp(Players[i].callsign, their->player.callsign )) && !memcmp((struct _sockaddr *)&their->player.protocol.udp.addr, (struct _sockaddr *)&Netgame.players[i].protocol.udp.addr, sizeof(struct _sockaddr))) + if ((Players[i].callsign == their->player.callsign) && !memcmp((struct _sockaddr *)&their->player.protocol.udp.addr, (struct _sockaddr *)&Netgame.players[i].protocol.udp.addr, sizeof(struct _sockaddr))) { player_num = i; break; @@ -1414,9 +1417,9 @@ static void net_udp_welcome_player(UDP_sequence_packet *their) digi_play_sample(SOUND_HUD_MESSAGE, F1_0); if (PlayerCfg.NoRankings) - HUD_init_message(HM_MULTI, "'%s' %s", Players[player_num].callsign, TXT_REJOIN); + HUD_init_message(HM_MULTI, "'%s' %s", static_cast(Players[player_num].callsign), TXT_REJOIN); else - HUD_init_message(HM_MULTI, "%s'%s' %s", RankStrings[Netgame.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN); + HUD_init_message(HM_MULTI, "%s'%s' %s", RankStrings[Netgame.players[player_num].rank],static_cast(Players[player_num].callsign), TXT_REJOIN); multi_send_score(); @@ -1936,7 +1939,7 @@ static void net_udp_add_player(UDP_sequence_packet *p) } ClipRank (&p->player.rank); - memcpy( Netgame.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 ); + Netgame.players[N_players].callsign = p->player.callsign; memcpy( (struct _sockaddr *)&Netgame.players[N_players].protocol.udp.addr, (struct _sockaddr *)&p->player.protocol.udp.addr, sizeof(struct _sockaddr) ); Netgame.players[N_players].rank=p->player.rank; Netgame.players[N_players].connected = CONNECT_PLAYING; @@ -1970,7 +1973,7 @@ static void net_udp_remove_player(UDP_sequence_packet *p) for (i=pn; i(&data[len]), CALLSIGN_LEN); + len += CALLSIGN_LEN+1; + i.connected = data[len]; len++; + i.rank = data[len]; len++; + i.protocol.udp.isyou = data[len]; len++; } memcpy(&Netgame.game_name, &(data[len]), NETGAME_NAME_LEN+1); len += (NETGAME_NAME_LEN+1); memcpy(&Netgame.mission_title, &(data[len]), MISSION_NAME_LEN+1); len += (MISSION_NAME_LEN+1); @@ -2863,9 +2867,9 @@ static int net_udp_start_poll( newmenu *menu, d_event *event, start_poll_data *s for (i=0; i(Netgame.players[i].callsign)); else - sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[Netgame.players[i].rank],Netgame.players[i].callsign ); + snprintf( menus[i].text, 45, "%d. %s%-20s", i+1, RankStrings[Netgame.players[i].rank],static_cast(Netgame.players[i].callsign)); } if (spd->playercount < Netgame.numplayers ) // A new player @@ -3221,7 +3225,7 @@ int net_udp_setup_game() for (i=0;i(Players[Player_num].callsign), TXT_S_GAME ); if (GameArg.MplUdpMyPort != 0) snprintf (UDP_MyPort, sizeof(UDP_MyPort), "%d", GameArg.MplUdpMyPort); else @@ -3374,7 +3378,6 @@ static net_udp_set_game_mode(int gamemode) void net_udp_read_sync_packet( ubyte * data, int data_len, struct _sockaddr sender_addr ) { int i, j; - char temp_callsign[CALLSIGN_LEN+1]; if (data) { @@ -3397,7 +3400,7 @@ void net_udp_read_sync_packet( ubyte * data, int data_len, struct _sockaddr send // Discover my player number - memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1); + callsign_t temp_callsign = Players[Player_num].callsign; Player_num = -1; @@ -3408,7 +3411,7 @@ void net_udp_read_sync_packet( ubyte * data, int data_len, struct _sockaddr send } for (i=0; i(Players[Player_num].callsign)); else - sprintf( text[0], "%d. %s%-20s", 1, RankStrings[Netgame.players[Player_num].rank],Players[Player_num].callsign ); + snprintf( text[0], sizeof(text[0]), "%d. %s%-20s", 1, RankStrings[Netgame.players[Player_num].rank],static_cast(Players[Player_num].callsign)); sprintf( title, "%s %d %s", TXT_TEAM_SELECT, Netgame.max_numplayers, TXT_TEAM_PRESS_ENTER ); @@ -3721,7 +3723,7 @@ abort: { if (i > N_players) { - memcpy(Netgame.players[N_players].callsign, Netgame.players[i].callsign, CALLSIGN_LEN+1); + Netgame.players[N_players].callsign = Netgame.players[i].callsign; Netgame.players[N_players].rank=Netgame.players[i].rank; ClipRank (&Netgame.players[N_players].rank); } @@ -3735,7 +3737,7 @@ abort: } for (i = N_players; i < MAX_PLAYERS; i++) { - memset(Netgame.players[i].callsign, 0, CALLSIGN_LEN+1); + Netgame.players[i].callsign.fill(0); Netgame.players[i].rank=0; } @@ -3816,7 +3818,7 @@ static int net_udp_wait_for_sync(void) if (i < 0) return(-1); - sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, Netgame.players[i].callsign, TXT_NET_TO_ENTER ); + snprintf(text, sizeof(text), "%s\n'%s' %s", TXT_NET_WAITING, static_cast(Netgame.players[i].callsign), TXT_NET_TO_ENTER ); while (choice > -1) { @@ -3828,7 +3830,7 @@ static int net_udp_wait_for_sync(void) { UDP_sequence_packet me{}; me.type = UPID_QUIT_JOINING; - memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 ); + me.player.callsign = Players[Player_num].callsign; net_udp_send_sequence_packet(me, Netgame.players[0].protocol.udp.addr); N_players = 0; Game_mode = GM_GAME_OVER; @@ -4815,9 +4817,9 @@ void net_udp_read_pdata_packet(UDP_frame_info *pd) ClipRank (&Netgame.players[TheirPlayernum].rank); if (PlayerCfg.NoRankings) - HUD_init_message(HM_MULTI, "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN ); + HUD_init_message(HM_MULTI, "'%s' %s", static_cast(Players[TheirPlayernum].callsign), TXT_REJOIN ); else - HUD_init_message(HM_MULTI, "%s'%s' %s", RankStrings[Netgame.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN ); + HUD_init_message(HM_MULTI, "%s'%s' %s", RankStrings[Netgame.players[TheirPlayernum].rank], static_cast(Players[TheirPlayernum].callsign), TXT_REJOIN ); multi_send_score(); @@ -4997,17 +4999,17 @@ void net_udp_do_refuse_stuff (UDP_sequence_packet *their) { if (!PlayerCfg.NoRankings) { - HUD_init_message(HM_MULTI, "%s %s wants to join",RankStrings[their->player.rank],their->player.callsign); + HUD_init_message(HM_MULTI, "%s %s wants to join",RankStrings[their->player.rank],static_cast(their->player.callsign)); } else { - HUD_init_message(HM_MULTI, "%s wants to join",their->player.callsign); + HUD_init_message(HM_MULTI, "%s wants to join",static_cast(their->player.callsign)); } - HUD_init_message(HM_MULTI, "Alt-1 assigns to team %s. Alt-2 to team %s",Netgame.team_name[0],Netgame.team_name[1]); + HUD_init_message(HM_MULTI, "Alt-1 assigns to team %s. Alt-2 to team %s", static_cast(Netgame.team_name[0]), static_cast(Netgame.team_name[1])); } else { - HUD_init_message(HM_MULTI, "%s wants to join (accept: F6)",their->player.callsign); + HUD_init_message(HM_MULTI, "%s wants to join (accept: F6)", static_cast(their->player.callsign)); } strcpy (RefusePlayerName,their->player.callsign); diff --git a/similar/main/newdemo.cpp b/similar/main/newdemo.cpp index f90d07524..221a4eac9 100644 --- a/similar/main/newdemo.cpp +++ b/similar/main/newdemo.cpp @@ -199,7 +199,7 @@ static int swap_endian = 0; // playback variables static unsigned int nd_playback_v_demosize; -static char nd_playback_v_save_callsign[CALLSIGN_LEN+1]; +static callsign_t nd_playback_v_save_callsign; static sbyte nd_playback_v_at_eof; static sbyte nd_playback_v_cntrlcen_destroyed = 0; static sbyte nd_playback_v_bad_read; @@ -923,7 +923,7 @@ void newdemo_record_start_demo() if (Game_mode & GM_MULTI) { nd_write_byte((sbyte)N_players); for (i = 0; i < N_players; i++) { - nd_write_string(Players[i].callsign); + nd_write_string(static_cast(Players[i].callsign)); nd_write_byte(Players[i].connected); if (Game_mode & GM_MULTI_COOP) { @@ -1397,7 +1397,7 @@ void newdemo_record_multi_connect(int pnum, int new_player, const char *new_call nd_write_byte((sbyte)pnum); nd_write_byte((sbyte)new_player); if (!new_player) { - nd_write_string(Players[pnum].callsign); + nd_write_string(static_cast(Players[pnum].callsign)); nd_write_int(Players[pnum].net_killed_total); nd_write_int(Players[pnum].net_kills_total); } @@ -1676,8 +1676,8 @@ static int newdemo_read_demo_start(enum purpose_type purpose) { if (Newdemo_game_mode & GM_TEAM) { nd_read_byte((sbyte *) &(Netgame.team_vector)); - nd_read_string(Netgame.team_name[0]); - nd_read_string(Netgame.team_name[1]); + nd_read_string(Netgame.team_name[0].buffer()); + nd_read_string(Netgame.team_name[1].buffer()); if (purpose == PURPOSE_REWRITE) { nd_write_byte(Netgame.team_vector); @@ -1699,11 +1699,11 @@ static int newdemo_read_demo_start(enum purpose_type purpose) for (i = 0 ; i < N_players; i++) { Players[i].cloak_time = 0; Players[i].invulnerable_time = 0; - nd_read_string(Players[i].callsign); + nd_read_string(Players[i].callsign.buffer()); nd_read_byte(&(Players[i].connected)); if (purpose == PURPOSE_REWRITE) { - nd_write_string(Players[i].callsign); + nd_write_string(static_cast(Players[i].callsign)); nd_write_byte(Players[i].connected); } @@ -2689,16 +2689,16 @@ static int newdemo_read_frame_information(int rewrite) case ND_EVENT_MULTI_CONNECT: { sbyte pnum, new_player; int killed_total, kills_total; - char new_callsign[CALLSIGN_LEN+1], old_callsign[CALLSIGN_LEN+1]; + callsign_t new_callsign, old_callsign; nd_read_byte(&pnum); nd_read_byte(&new_player); if (!new_player) { - nd_read_string(old_callsign); + nd_read_string(old_callsign.buffer()); nd_read_int(&killed_total); nd_read_int(&kills_total); } - nd_read_string(new_callsign); + nd_read_string(new_callsign.buffer()); if (rewrite) { nd_write_byte(pnum); @@ -2708,13 +2708,13 @@ static int newdemo_read_frame_information(int rewrite) nd_write_int(killed_total); nd_write_int(kills_total); } - nd_write_string(new_callsign); + nd_write_string(static_cast(new_callsign)); break; } if ((Newdemo_vcr_state == ND_STATE_REWINDING) || (Newdemo_vcr_state == ND_STATE_ONEFRAMEBACKWARD)) { Players[pnum].connected = CONNECT_DISCONNECTED; if (!new_player) { - memcpy(Players[pnum].callsign, old_callsign, CALLSIGN_LEN+1); + Players[pnum].callsign = old_callsign; Players[pnum].net_killed_total = killed_total; Players[pnum].net_kills_total = kills_total; } else { @@ -2724,7 +2724,7 @@ static int newdemo_read_frame_information(int rewrite) Players[pnum].connected = CONNECT_PLAYING; Players[pnum].net_kills_total = 0; Players[pnum].net_killed_total = 0; - memcpy(Players[pnum].callsign, new_callsign, CALLSIGN_LEN+1); + Players[pnum].callsign = new_callsign; if (new_player) N_players++; } @@ -3239,7 +3239,7 @@ void newdemo_goto_end(int to_rewrite) // why this is commented out // nd_read_byte((sbyte *)&N_players); for (i = 0; i < N_players; i++) { - nd_read_string(Players[i].callsign); + nd_read_string(Players[i].callsign.buffer()); nd_read_byte(&(Players[i].connected)); if (Newdemo_game_mode & GM_MULTI_COOP) { nd_read_int(&(Players[i].score)); @@ -3632,8 +3632,8 @@ static void newdemo_write_end() nd_write_byte((sbyte)N_players); byte_count++; for (i = 0; i < N_players; i++) { - nd_write_string(Players[i].callsign); - byte_count += (strlen(Players[i].callsign) + 2); + nd_write_string(static_cast(Players[i].callsign)); + byte_count += (strlen(static_cast(Players[i].callsign)) + 2); nd_write_byte(Players[i].connected); if (Game_mode & GM_MULTI_COOP) { nd_write_int(Players[i].score); @@ -3811,7 +3811,7 @@ void newdemo_start_playback(const char * filename) nd_playback_v_bad_read = 0; change_playernum_to(0); // force playernum to 0 - strncpy(nd_playback_v_save_callsign, Players[Player_num].callsign, CALLSIGN_LEN); + nd_playback_v_save_callsign = Players[Player_num].callsign; Players[Player_num].lives=0; Viewer = ConsoleObject = &Objects[0]; // play properly as if console player @@ -3849,7 +3849,7 @@ void newdemo_stop_playback() PHYSFS_close(infile); Newdemo_state = ND_STATE_NORMAL; change_playernum_to(0); //this is reality - strncpy(Players[Player_num].callsign, nd_playback_v_save_callsign, CALLSIGN_LEN); + Players[Player_num].callsign = nd_playback_v_save_callsign; Rear_view=0; nd_playback_v_dead = nd_playback_v_rear = 0; #if defined(DXX_BUILD_DESCENT_II) diff --git a/similar/main/playsave.cpp b/similar/main/playsave.cpp index 473f6a22b..90491229a 100644 --- a/similar/main/playsave.cpp +++ b/similar/main/playsave.cpp @@ -513,7 +513,7 @@ static void plyr_read_stats_v(int *k, int *d) *k=0;*d=0;//in case the file doesn't exist. memset(filename, '\0', PATH_MAX); - snprintf(filename,sizeof(filename),PLAYER_EFFECTIVENESS_FILENAME_FORMAT,Players[Player_num].callsign); + snprintf(filename,sizeof(filename),PLAYER_EFFECTIVENESS_FILENAME_FORMAT,static_cast(Players[Player_num].callsign)); f = PHYSFSX_openReadBuffered(filename); if(f) @@ -571,7 +571,7 @@ void plyr_save_stats() PHYSFS_file *f; memset(filename, '\0', PATH_MAX); - snprintf(filename,sizeof(filename),PLAYER_EFFECTIVENESS_FILENAME_FORMAT,Players[Player_num].callsign); + snprintf(filename,sizeof(filename),PLAYER_EFFECTIVENESS_FILENAME_FORMAT,static_cast(Players[Player_num].callsign)); f = PHYSFSX_openWriteBuffered(filename); if(!f) @@ -756,7 +756,7 @@ int read_player_file() Assert(Player_num>=0 && Player_num < MAX_PLAYERS); memset(filename, '\0', PATH_MAX); - snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plr"), Players[Player_num].callsign); + snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plr"), static_cast(Players[Player_num].callsign)); if (!PHYSFSX_exists(filename,0)) return ENOENT; @@ -1136,9 +1136,9 @@ void write_player_file() errno_ret = WriteConfigFile(); - snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plx"), Players[Player_num].callsign); + snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plx"), static_cast(Players[Player_num].callsign)); write_player_dxx(filename); - snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plr"), Players[Player_num].callsign); + snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.plr"), static_cast(Players[Player_num].callsign)); file = PHYSFSX_openWriteBuffered(filename); if (!file) @@ -1314,7 +1314,7 @@ void read_netgame_profile(netgame_info *ng) char filename[PATH_MAX], line[50], *token, *ptr; PHYSFS_file *file; - snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.ngp"), Players[Player_num].callsign); + snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.ngp"), static_cast(Players[Player_num].callsign)); if (!PHYSFSX_exists(filename,0)) return; @@ -1396,7 +1396,7 @@ void write_netgame_profile(netgame_info *ng) char filename[PATH_MAX]; PHYSFS_file *file; - snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.ngp"), Players[Player_num].callsign); + snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.8s.ngp"), static_cast(Players[Player_num].callsign)); file = PHYSFSX_openWriteBuffered(filename); if (!file) diff --git a/similar/main/scores.cpp b/similar/main/scores.cpp index 5806eef57..65de62f9b 100644 --- a/similar/main/scores.cpp +++ b/similar/main/scores.cpp @@ -68,7 +68,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. struct stats_info { - char name[CALLSIGN_LEN+1]; + callsign_t name; int score; sbyte starting_level; sbyte ending_level; @@ -101,16 +101,16 @@ static void scores_read(all_scores *scores) // No error message needed, code will work without a scores file sprintf( scores->cool_saying, "%s", TXT_REGISTER_DESCENT ); - sprintf( scores->stats[0].name, "Parallax" ); - sprintf( scores->stats[1].name, "Matt" ); - sprintf( scores->stats[2].name, "Mike" ); - sprintf( scores->stats[3].name, "Adam" ); - sprintf( scores->stats[4].name, "Mark" ); - sprintf( scores->stats[5].name, "Jasen" ); - sprintf( scores->stats[6].name, "Samir" ); - sprintf( scores->stats[7].name, "Doug" ); - sprintf( scores->stats[8].name, "Dan" ); - sprintf( scores->stats[9].name, "Jason" ); + scores->stats[0].name = "Parallax"; + scores->stats[1].name = "Matt"; + scores->stats[2].name = "Mike"; + scores->stats[3].name = "Adam"; + scores->stats[4].name = "Mark"; + scores->stats[5].name = "Jasen"; + scores->stats[6].name = "Samir"; + scores->stats[7].name = "Doug"; + scores->stats[8].name = "Dan"; + scores->stats[9].name = "Jason"; for (i=0; i<10; i++) scores->stats[i].score = (10-i)*1000; @@ -181,7 +181,7 @@ static void int_to_string( int number, char *dest ) static void scores_fill_struct(stats_info * stats) { - strcpy( stats->name, Players[Player_num].callsign ); + stats->name = Players[Player_num].callsign; stats->score = Players[Player_num].score; stats->ending_level = Players[Player_num].level; if (Players[Player_num].num_robots_total > 0 ) @@ -434,7 +434,7 @@ static int scores_handler(window *wind, d_event *event, scores_menu *menu) gr_set_fontcolor( BM_XRGB(28,28,28), -1 ); - gr_printf( 0x8000, FSPACY(31), "%c%s%c - %s", 34, menu->scores.cool_saying, 34, menu->scores.stats[0].name ); + gr_printf( 0x8000, FSPACY(31), "%c%s%c - %s", 34, menu->scores.cool_saying, 34, static_cast(menu->scores.stats[0].name)); for (i=0; icallsign, pl->callsign, CALLSIGN_LEN+1); + pl_rw->callsign = pl->callsign; memset(pl_rw->net_address, 0, 6); pl_rw->connected = pl->connected; pl_rw->objnum = pl->objnum; @@ -516,7 +516,7 @@ static void state_player_to_player_rw(const player *pl, player_rw *pl_rw) static void state_player_rw_to_player(const player_rw *pl_rw, player *pl) { int i=0; - memcpy(pl->callsign, pl_rw->callsign, CALLSIGN_LEN+1); + pl->callsign = pl_rw->callsign; pl->connected = pl_rw->connected; pl->objnum = pl_rw->objnum; pl->flags = pl_rw->flags; @@ -646,7 +646,7 @@ static int state_get_savegame_filename(char * fname, char * dsc, const char * ca nm_set_item_text(& m[0], "\n\n\n\n"); for (i=0;i(Players[Player_num].callsign), (Game_mode & GM_MULTI_COOP)?'m':'s', i ); valid = 0; fp = PHYSFSX_openReadBuffered(filename[i]); if ( fp ) { @@ -751,7 +751,7 @@ int state_save_old_game(int slotnum, const char * sg_name, player_rw * sg_player GLint gl_draw_buffer; #endif - snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%s.sg%d"), sg_player->callsign, slotnum ); + snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%s.sg%d"), static_cast(sg_player->callsign), slotnum ); fp = PHYSFSX_openWriteBuffered(filename); if ( !fp ) return 0; @@ -1423,7 +1423,6 @@ int state_restore_all_sub(const char *filename, int secret_restore) char mission[16]; char desc[DESC_LENGTH+1]; char id[5]; - char org_callsign[CALLSIGN_LEN+16]; fix tmptime32 = 0; short TempTmapNum[MAX_SEGMENTS][MAX_SIDES_PER_SEGMENT]; short TempTmapNum2[MAX_SEGMENTS][MAX_SIDES_PER_SEGMENT]; @@ -1466,10 +1465,10 @@ int state_restore_all_sub(const char *filename, int secret_restore) // Read Coop state_game_id. Oh the redundancy... we have this one later on but Coop games want to read this before loading a state so for easy access we have this here if (Game_mode & GM_MULTI_COOP) { - char saved_callsign[CALLSIGN_LEN+1]; + callsign_t saved_callsign; state_game_id = PHYSFSX_readSXE32(fp, swap); PHYSFS_read(fp, &saved_callsign, sizeof(char)*CALLSIGN_LEN+1, 1); - if (strcmp(saved_callsign, Players[Player_num].callsign)) // check the callsign of the palyer who saved this state. It MUST match. If we transferred this savegame from pilot A to pilot B, others won't be able to restore us. So bail out here if this is the case. + if (saved_callsign != Players[Player_num].callsign) // check the callsign of the palyer who saved this state. It MUST match. If we transferred this savegame from pilot A to pilot B, others won't be able to restore us. So bail out here if this is the case. { PHYSFS_close(fp); return 0; @@ -1507,12 +1506,13 @@ int state_restore_all_sub(const char *filename, int secret_restore) GameTime64 = (fix64)tmptime32; // Start new game.... + callsign_t org_callsign; if (!(Game_mode & GM_MULTI_COOP)) { Game_mode = GM_NORMAL; change_playernum_to(0); N_players = 1; - strcpy( org_callsign, Players[0].callsign ); + org_callsign = Players[0].callsign; if (!secret_restore) { InitPlayerObject(); //make sure player's object set up init_player_stats_game(0); //clear all stats @@ -1520,7 +1520,7 @@ int state_restore_all_sub(const char *filename, int secret_restore) } else // in coop we want to stay the player we are already. { - strcpy( org_callsign, Players[Player_num].callsign ); + org_callsign = Players[Player_num].callsign; if (!secret_restore) init_player_stats_game(Player_num); } @@ -1561,7 +1561,7 @@ int state_restore_all_sub(const char *filename, int secret_restore) state_read_player(fp, Players[Player_num], swap); } } - strcpy( Players[Player_num].callsign, org_callsign ); + Players[Player_num].callsign = org_callsign; if (Game_mode & GM_MULTI_COOP) Players[Player_num].objnum = coop_org_objnum; @@ -1876,7 +1876,7 @@ int state_restore_all_sub(const char *filename, int secret_restore) for (j = 0; j < MAX_PLAYERS; j++) { // map stored players to current players depending on their unique (which we made sure) callsign - if (Players[i].connected == CONNECT_PLAYING && restore_players[j].connected == CONNECT_PLAYING && !strcmp(Players[i].callsign, restore_players[j].callsign)) + if (Players[i].connected == CONNECT_PLAYING && restore_players[j].connected == CONNECT_PLAYING && Players[i].callsign == restore_players[j].callsign) { object *obj; int sav_objnum = Players[i].objnum; @@ -1982,7 +1982,7 @@ int state_get_game_id(const char *filename) // Read Coop state_game_id to validate the savegame we are about to load matches the others state_game_id = PHYSFSX_readSXE32(fp, swap); PHYSFS_read(fp, &saved_callsign, sizeof(char)*CALLSIGN_LEN+1, 1); - if (strcmp(saved_callsign, Players[Player_num].callsign)) // check the callsign of the palyer who saved this state. It MUST match. If we transferred this savegame from pilot A to pilot B, others won't be able to restore us. So bail out here if this is the case. + if (saved_callsign != Players[Player_num].callsign) // check the callsign of the palyer who saved this state. It MUST match. If we transferred this savegame from pilot A to pilot B, others won't be able to restore us. So bail out here if this is the case. return 0; return state_game_id;