diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bc9b599f04da6d49a158e42294f79b496a8eaad6..b2ae09dd85fdd2ab539f288358327e53c8d73fbd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,6 @@ set(SRB2_CORE_SOURCES m_queue.c m_random.c md5.c - mserv.c s_sound.c screen.c sounds.c @@ -95,7 +94,6 @@ set(SRB2_CORE_HEADERS m_random.h m_swap.h md5.h - mserv.h p5prof.h s_sound.h screen.h diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 65e955d02719e028d5aaea08c367178e6433215a..8873b6ea98d98f037212b626818b9309d29d9527 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -33,7 +33,6 @@ #include "m_misc.h" #include "am_map.h" #include "m_random.h" -#include "mserv.h" #include "y_inter.h" #include "r_local.h" #include "m_argv.h" @@ -71,8 +70,6 @@ char motd[254], server_context[8]; // Message of the Day, Unique Context (even w static tic_t nettics[MAXNETNODES]; // what tic the client have received static tic_t supposedtics[MAXNETNODES]; // nettics prevision for smaller packet static UINT8 nodewaiting[MAXNETNODES]; -static tic_t firstticstosend; // min of the nettics -static tic_t tictoclear = 0; // optimize d_clearticcmd // client specific static ticcmd_t localcmds; @@ -106,7 +103,6 @@ typedef struct textcmdtic_s } textcmdtic_t; ticcmd_t netcmds[MAXPLAYERS]; -static textcmdtic_t *textcmds[TEXTCMD_HASH_SIZE] = {NULL}; static consvar_t cv_showjoinaddress = {"showjoinaddress", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -189,6 +185,7 @@ void SendNetXCmd(netxcmd_t id, const void *param, size_t nparam) //D_NetSendXCmd(id, param, nparam, consoleplayer); UINT8 **p = (UINT8 **)¶m; (listnetxcmd[id])(p, consoleplayer); + (void)nparam; } // splitscreen player @@ -197,6 +194,7 @@ void SendNetXCmd2(netxcmd_t id, const void *param, size_t nparam) //D_NetSendXCmd(id, param, nparam, secondarydisplayplayer); UINT8 **p = (UINT8 **)¶m; (listnetxcmd[id])(p, secondarydisplayplayer); + (void)nparam; } UINT8 GetFreeXCmdSize(void) @@ -210,65 +208,6 @@ static void D_FreeTextcmd(void) // NET TODO } -// Gets the buffer for the specified ticcmd, or NULL if there isn't one -static UINT8* D_GetExistingTextcmd(tic_t tic, INT32 playernum) -{ - textcmdtic_t *textcmdtic = textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; - while (textcmdtic && textcmdtic->tic != tic) textcmdtic = textcmdtic->next; - - // Do we have an entry for the tic? If so, look for player. - if (textcmdtic) - { - textcmdplayer_t *textcmdplayer = textcmdtic->playercmds[playernum & (TEXTCMD_HASH_SIZE - 1)]; - while (textcmdplayer && textcmdplayer->playernum != playernum) textcmdplayer = textcmdplayer->next; - - if (textcmdplayer) return textcmdplayer->cmd; - } - - return NULL; -} - -// Gets the buffer for the specified ticcmd, creating one if necessary -static UINT8* D_GetTextcmd(tic_t tic, INT32 playernum) -{ - textcmdtic_t *textcmdtic = textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; - textcmdtic_t **tctprev = &textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; - textcmdplayer_t *textcmdplayer, **tcpprev; - - // Look for the tic. - while (textcmdtic && textcmdtic->tic != tic) - { - tctprev = &textcmdtic->next; - textcmdtic = textcmdtic->next; - } - - // If we don't have an entry for the tic, make it. - if (!textcmdtic) - { - textcmdtic = *tctprev = Z_Calloc(sizeof (textcmdtic_t), PU_STATIC, NULL); - textcmdtic->tic = tic; - } - - tcpprev = &textcmdtic->playercmds[playernum & (TEXTCMD_HASH_SIZE - 1)]; - textcmdplayer = *tcpprev; - - // Look for the player. - while (textcmdplayer && textcmdplayer->playernum != playernum) - { - tcpprev = &textcmdplayer->next; - textcmdplayer = textcmdplayer->next; - } - - // If we don't have an entry for the player, make it. - if (!textcmdplayer) - { - textcmdplayer = *tcpprev = Z_Calloc(sizeof (textcmdplayer_t), PU_STATIC, NULL); - textcmdplayer->playernum = playernum; - } - - return textcmdplayer->cmd; -} - static void D_Clearticcmd(void) { INT32 i; @@ -337,59 +276,18 @@ void ReadLmpExtraData(UINT8 **demo_pointer, INT32 playernum) // end extra data function for lmps // ----------------------------------------------------------------- -#ifndef NONET -#define JOININGAME -#endif - typedef enum { cl_searching, cl_downloadfiles, cl_askjoin, cl_waitjoinresponse, -#ifdef JOININGAME - cl_downloadsavegame, -#endif cl_connected, cl_aborted } cl_mode_t; static cl_mode_t cl_mode = cl_searching; -// Player name send/load - -static void CV_SavePlayerNames(UINT8 **p) -{ - INT32 i = 0; - // Players in game only. - for (; i < MAXPLAYERS; ++i) - { - if (!playeringame[i]) - { - WRITEUINT8(*p, 0); - continue; - } - WRITESTRING(*p, player_names[i]); - } -} - -static void CV_LoadPlayerNames(UINT8 **p) -{ - INT32 i = 0; - char tmp_name[MAXPLAYERNAME+1]; - tmp_name[MAXPLAYERNAME] = 0; - - for (; i < MAXPLAYERS; ++i) - { - READSTRING(*p, tmp_name); - if (tmp_name[0] == 0) - continue; - if (tmp_name[MAXPLAYERNAME]) // overflow detected - I_Error("Received bad server config packet when trying to join"); - memcpy(player_names[i], tmp_name, MAXPLAYERNAME+1); - } -} - #ifdef CLIENT_LOADINGSCREEN // // CL_DrawConnectionStatus @@ -419,17 +317,6 @@ static inline void CL_DrawConnectionStatus(void) switch (cl_mode) { -#ifdef JOININGAME - case cl_downloadsavegame: - cltext = M_GetText("Downloading game state..."); - Net_GetNetStat(); - V_DrawString(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, - va(" %4uK",fileneeded[lastfilenum].currentsize>>10)); - // NET TODO - //V_DrawRightAlignedString(BASEVIDWIDTH/2+128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, - // va("%3.1fK/s ", ((double)getbps)/1024)); - break; -#endif case cl_askjoin: case cl_waitjoinresponse: cltext = M_GetText("Requesting to join..."); @@ -488,231 +375,6 @@ static boolean CL_SendJoin(void) return true; } -static void SV_SendServerInfo(INT32 node, tic_t servertime) -{ - // NET TODO -} - -static void SV_SendPlayerInfo(INT32 node) -{ - // NET TODO -} - -static boolean SV_SendServerConfig(INT32 node) -{ - // NET TODO - return true; -} - -#ifdef JOININGAME -#define SAVEGAMESIZE (768*1024) - -static void SV_SendSaveGame(INT32 node) -{ - size_t length, compressedlen; - UINT8 *savebuffer; - UINT8 *compressedsave; - UINT8 *buffertosend; - - // first save it in a malloced buffer - savebuffer = (UINT8 *)malloc(SAVEGAMESIZE); - if (!savebuffer) - { - CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); - return; - } - - // Leave room for the uncompressed length. - save_p = savebuffer + sizeof(UINT32); - - P_SaveNetGame(); - - length = save_p - savebuffer; - if (length > SAVEGAMESIZE) - { - free(savebuffer); - save_p = NULL; - I_Error("Savegame buffer overrun"); - } - - // Allocate space for compressed save: one byte fewer than for the - // uncompressed data to ensure that the compression is worthwhile. - compressedsave = malloc(length - 1); - if (!compressedsave) - { - CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); - return; - } - - // Attempt to compress it. - if((compressedlen = lzf_compress(savebuffer + sizeof(UINT32), length - sizeof(UINT32), compressedsave + sizeof(UINT32), length - sizeof(UINT32) - 1))) - { - // Compressing succeeded; send compressed data - - free(savebuffer); - - // State that we're compressed. - buffertosend = compressedsave; - WRITEUINT32(compressedsave, length - sizeof(UINT32)); - length = compressedlen + sizeof(UINT32); - } - else - { - // Compression failed to make it smaller; send original - - free(compressedsave); - - // State that we're not compressed - buffertosend = savebuffer; - WRITEUINT32(savebuffer, 0); - } - - SendRam(node, buffertosend, length, SF_RAM, 0); - save_p = NULL; -} - -#define TMPSAVENAME "$$$.sav" - - -static void CL_LoadReceivedSavegame(void) -{ - UINT8 *savebuffer = NULL; - size_t length, decompressedlen; - XBOXSTATIC char tmpsave[256]; - - sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); - - length = FIL_ReadFile(tmpsave, &savebuffer); - - CONS_Printf(M_GetText("Loading savegame length %s\n"), sizeu1(length)); - if (!length) - { - I_Error("Can't read savegame sent"); - return; - } - - save_p = savebuffer; - - // Decompress saved game if necessary. - decompressedlen = READUINT32(save_p); - if(decompressedlen > 0) - { - UINT8 *decompressedbuffer = Z_Malloc(decompressedlen, PU_STATIC, NULL); - lzf_decompress(save_p, length - sizeof(UINT32), decompressedbuffer, decompressedlen); - Z_Free(savebuffer); - save_p = savebuffer = decompressedbuffer; - } - - paused = false; - demoplayback = false; - titledemo = false; - automapactive = false; - - // load a base level - playerdeadview = false; - - if (P_LoadNetGame()) - { - const INT32 actnum = mapheaderinfo[gamemap-1]->actnum; - CONS_Printf(M_GetText("Map is now \"%s"), G_BuildMapName(gamemap)); - if (strcmp(mapheaderinfo[gamemap-1]->lvlttl, "")) - { - CONS_Printf(": %s", mapheaderinfo[gamemap-1]->lvlttl); - if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE)) - CONS_Printf(M_GetText("ZONE")); - if (actnum > 0) - CONS_Printf(" %2d", actnum); - } - CONS_Printf("\"\n"); - } - else - { - CONS_Alert(CONS_ERROR, M_GetText("Can't load the level!\n")); - Z_Free(savebuffer); - save_p = NULL; - if (unlink(tmpsave) == -1) - CONS_Alert(CONS_ERROR, M_GetText("Can't delete %s\n"), tmpsave); - return; - } - - // done - Z_Free(savebuffer); - save_p = NULL; - if (unlink(tmpsave) == -1) - CONS_Alert(CONS_ERROR, M_GetText("Can't delete %s\n"), tmpsave); - CON_ToggleOff(); -} -#endif - -#ifndef NONET -static void SendAskInfo(INT32 node, boolean viams) -{ - //if (server) - {// I'm the server, skip this. - // I'm the server, skip this. - cl_mode = cl_askjoin; - return; - } - // NET TODO -} - -serverelem_t serverlist[MAXSERVERLIST]; -UINT32 serverlistcount = 0; - -static void SL_ClearServerList(INT32 connectedserver) -{ - UINT32 i; - - for (i = 0; i < serverlistcount; i++) - if (connectedserver != serverlist[i].node) - { - Net_CloseConnection(serverlist[i].node); - serverlist[i].node = 0; - } - serverlistcount = 0; -} - -static UINT32 SL_SearchServer(INT32 node) -{ - // NET TODO - return UINT32_MAX; -} - -static void SL_InsertServer(serverinfo_pak* info, SINT8 node) -{ - UINT32 i; - - // search if not already on it - i = SL_SearchServer(node); - if (i == UINT32_MAX) - { - // not found add it - if (serverlistcount >= MAXSERVERLIST) - return; // list full - - if (info->version != VERSION) - return; // Not same version. - - if (info->subversion != SUBVERSION) - return; // Close, but no cigar. - - i = serverlistcount++; - } - - serverlist[i].info = *info; - serverlist[i].node = node; - - // resort server list - M_SortServerList(); -} - -void CL_UpdateServerList(boolean internetsearch, INT32 room) -{ - // NET TODO -} - -#endif // ifndef NONET - void CL_ConnectionSuccessful(void) { if (cl_mode == cl_waitjoinresponse) @@ -720,16 +382,11 @@ void CL_ConnectionSuccessful(void) } // use adaptive send using net_bandwidth and stat.sendbytes -static void CL_ConnectToServer(boolean viams) +static void CL_ConnectToServer(void) { INT32 pnumnodes, nodewaited = net_nodecount, i; boolean waitmore; tic_t oldtic; -#ifdef JOININGAME - XBOXSTATIC char tmpsave[256]; - - sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); -#endif cl_mode = cl_askjoin; @@ -737,12 +394,6 @@ static void CL_ConnectToServer(boolean viams) lastfilenum = 0; #endif -#ifdef JOININGAME - // don't get a corrupt savegame error because tmpsave already exists - if (FIL_FileExists(tmpsave) && unlink(tmpsave) == -1) - I_Error("Can't delete %s\n", tmpsave); -#endif - if (netgame) { if (servernode < 0 || servernode >= MAXNETNODES) @@ -788,17 +439,6 @@ static void CL_ConnectToServer(boolean viams) if (CL_SendJoin()) // Send join request, server instantly connects. cl_mode = server ? cl_connected : cl_waitjoinresponse; break; -#ifdef JOININGAME - case cl_downloadsavegame: - if (fileneeded[0].status == FS_FOUND) - { - // Gamestate is now handled within CL_LoadReceivedSavegame() - CL_LoadReceivedSavegame(); - cl_mode = cl_connected; - } // don't break case continue to cl_connected - else - break; -#endif case cl_waitjoinresponse: case cl_connected: default: @@ -867,51 +507,8 @@ static void CL_ConnectToServer(boolean viams) } #ifndef NONET -typedef struct banreason_s -{ - char *reason; - struct banreason_s *prev; //-1 - struct banreason_s *next; //+1 -} banreason_t; - -static banreason_t *reasontail = NULL; //last entry, use prev -static banreason_t *reasonhead = NULL; //1st entry, use next - -static void Command_ShowBan(void) //Print out ban list -{ - // NET TODO -} - -void D_SaveBan(void) -{ - // NET TODO -} - -static void Ban_Add(const char *reason) -{ - // NET TODO -} - -static void Command_ClearBans(void) -{ - // NET TODO -} - -static void Ban_Load_File(boolean warning) -{ - // NET TODO -} - -static void Command_ReloadBan(void) //recheck ban.txt -{ - Ban_Load_File(true); -} - static void Command_connect(void) { - // Assume we connect directly. - boolean viams = false; - if (COM_Argc() < 2) { CONS_Printf(M_GetText( @@ -932,39 +529,21 @@ static void Command_connect(void) server = false; - if (!stricmp(COM_Argv(1), "self")) + if (netgame) { - servernode = 0; - server = true; - /// \bug should be but... - //SV_SpawnServer(); + CONS_Printf(M_GetText("You cannot connect while in a game. End this game first.\n")); + return; } else { - // used in menu to connect to a server in the list - if (netgame && !stricmp(COM_Argv(1), "node")) - { - servernode = (SINT8)atoi(COM_Argv(2)); - - // Use MS to traverse NAT firewalls. - viams = true; - } - else if (netgame) - { - CONS_Printf(M_GetText("You cannot connect while in a game. End this game first.\n")); - return; - } + boolean success = false; + if (COM_Argc() >= 3) + success = D_NetConnect(COM_Argv(1), COM_Argv(2)); else - { - boolean success = false; - if (COM_Argc() >= 3) - success = D_NetConnect(COM_Argv(1), COM_Argv(2)); - else - success = D_NetConnect(COM_Argv(1), NULL); - if (!success) { - M_StartMessage(M_GetText("Failed to connect to server.\n\nPress ESC\n"), NULL, MM_NOTHING); - return; - } + success = D_NetConnect(COM_Argv(1), NULL); + if (!success) { + M_StartMessage(M_GetText("Failed to connect to server.\n\nPress ESC\n"), NULL, MM_NOTHING); + return; } } @@ -972,7 +551,7 @@ static void Command_connect(void) SplitScreen_OnChange(); botingame = false; botskin = 0; - CL_ConnectToServer(viams); + CL_ConnectToServer(); } #endif @@ -1161,7 +740,6 @@ static void Command_Nodes(void) { INT32 i; size_t maxlen = 0; - const char *address; for (i = 0; i < MAXPLAYERS; i++) { @@ -1202,46 +780,18 @@ static void Command_Ban(void) XBOXSTATIC UINT8 buf[3 + MAX_REASONLENGTH]; UINT8 *p = buf; const SINT8 pn = nametonum(COM_Argv(1)); - const INT32 node = playernode[(INT32)pn]; + //const INT32 node = playernode[(INT32)pn]; if (pn == -1 || pn == 0) return; else WRITEUINT8(p, pn); // NET TODO - //if (I_Ban && !I_Ban(node)) { //CONS_Alert(CONS_WARNING, M_GetText("Too many bans! Geez, that's a lot of people you're excluding...\n")); WRITEUINT8(p, KICK_MSG_GO_AWAY); SendNetXCmd(XD_KICK, &buf, 2); } - /*else - { - Ban_Add(COM_Argv(2)); - - if (COM_Argc() == 2) - { - WRITEUINT8(p, KICK_MSG_BANNED); - SendNetXCmd(XD_KICK, &buf, 2); - } - else - { - size_t i, j = COM_Argc(); - char message[MAX_REASONLENGTH]; - - //Steal from the motd code so you don't have to put the reason in quotes. - strlcpy(message, COM_Argv(2), sizeof message); - for (i = 3; i < j; i++) - { - strlcat(message, " ", sizeof message); - strlcat(message, COM_Argv(i), sizeof message); - } - - WRITEUINT8(p, KICK_MSG_CUSTOM_BAN); - WRITESTRINGN(p, message, MAX_REASONLENGTH); - SendNetXCmd(XD_KICK, &buf, p - buf); - } - }*/ } else CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); @@ -1450,9 +1000,6 @@ void D_ClientServerInit(void) COM_AddCommand("getplayernum", Command_GetPlayerNum); COM_AddCommand("kick", Command_Kick); COM_AddCommand("ban", Command_Ban); - COM_AddCommand("clearbans", Command_ClearBans); - COM_AddCommand("showbanlist", Command_ShowBan); - COM_AddCommand("reloadbans", Command_ReloadBan); COM_AddCommand("connect", Command_connect); COM_AddCommand("nodes", Command_Nodes); #endif @@ -1463,7 +1010,6 @@ void D_ClientServerInit(void) CV_RegisterVar(&cv_allownewplayer); CV_RegisterVar(&cv_joinnextround); CV_RegisterVar(&cv_showjoinaddress); - Ban_Load_File(false); #endif gametic = 0; @@ -1766,7 +1312,7 @@ boolean SV_SpawnServer(void) // non dedicated server just connect to itself if (!dedicated) - CL_ConnectToServer(false); + CL_ConnectToServer(); } return SV_AddWaitingPlayers(); @@ -1774,8 +1320,6 @@ boolean SV_SpawnServer(void) void SV_StopServer(void) { - tic_t i; - if (gamestate == GS_INTERMISSION) Y_EndIntermission(); gamestate = wipegamestate = GS_NULL; @@ -1836,14 +1380,16 @@ static void Local_Maketic(INT32 realtics) void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle) { + (void)playernum; (void)x; (void)y; - // TODO: Send everyone a player spawn message?? + (void)angle; + // NET TODO: Send everyone a player spawn message?? } void TryRunTics(tic_t realtics) { - int i; + tic_t i; // the machine has lagged but it is not so bad if (realtics > TICRATE/7) @@ -1875,7 +1421,7 @@ void TryRunTics(tic_t realtics) if (advancedemo) D_StartTitle(); else - // TODO: re-impliment cv_playbackspeed for demos + // NET TODO: re-impliment cv_playbackspeed for demos for (i = 0; i < realtics; i++) { DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic)); @@ -1890,7 +1436,6 @@ void NetUpdate(void) static tic_t gametime = 0; static tic_t resptime = 0; tic_t nowtime; - INT32 i; INT32 realtics; nowtime = I_GetTime(); @@ -1913,8 +1458,6 @@ void NetUpdate(void) // client send the command after a receive of the server // the server send before because in single player is beter - MasterClient_Ticker(); // acking the master server - Net_AckTicker(); nowtime /= NEWTICRATERATIO; if (nowtime > resptime) diff --git a/src/d_clisrv.h b/src/d_clisrv.h index b48253fb2092445428bc8c69853f62200c2ecfd0..4fde8654c7f096b90570d43f17d4151b4afda8f0 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -207,14 +207,6 @@ typedef struct #endif #define MAXSERVERLIST 64 // depends only on the display -typedef struct -{ - SINT8 node; - serverinfo_pak info; -} serverelem_t; - -extern serverelem_t serverlist[MAXSERVERLIST]; -extern UINT32 serverlistcount; extern INT32 mapchangepending; extern consvar_t cv_playbackspeed; @@ -270,7 +262,6 @@ void SV_ResetServer(void); void CL_AddSplitscreenPlayer(void); void CL_RemoveSplitscreenPlayer(void); void CL_Reset(void); -void D_SaveBan(void); // in the middle of frikking nowhere void CL_ClearPlayer(INT32 playernum); void CL_RemovePlayer(INT32 playernum); void CL_UpdateServerList(boolean internetsearch, INT32 room); diff --git a/src/d_datawrap.c b/src/d_datawrap.c index 838af499e77228ed7c96449234a5a950141e12a2..ff80f726b26bf4c091b05906933f2e197114d934 100644 --- a/src/d_datawrap.c +++ b/src/d_datawrap.c @@ -47,7 +47,7 @@ char *DW_ReadStringn(DataWrap dw, size_t n) { char *string = ZZ_Alloc(n+1); char *p = string; - int i; + size_t i; for (i = 0; i < n; i++, p++) { CheckEOF(dw,1); diff --git a/src/d_enet.c b/src/d_enet.c index 4b405c8bc661b0fd50da870b128a148236297639..e76781998eee34bf21e75a77789fef70bdfd07aa 100644 --- a/src/d_enet.c +++ b/src/d_enet.c @@ -9,6 +9,7 @@ #include "d_datawrap.h" #include "g_game.h" #include "p_local.h" +#include "d_main.h" UINT8 net_nodecount, net_playercount; UINT8 playernode[MAXPLAYERS]; @@ -594,15 +595,14 @@ static void ServerSendMapInfo(UINT8 node) void Net_ServerMessage(const char *fmt, ...) { va_list argptr; - ENetPacket *packet; UINT8 data[1+MAX_SERVER_MESSAGE]; UINT8 *buf = data; WRITEUINT8(buf, SERVER_MESSAGE); va_start(argptr, fmt); - vsnprintf(buf, MAX_SERVER_MESSAGE, fmt, argptr); + vsnprintf((char *)buf, MAX_SERVER_MESSAGE, fmt, argptr); va_end(argptr); - buf += strlen(buf)+1; + buf += strlen((char *)buf)+1; CONS_Printf("%s\n", data+1); enet_host_broadcast(ServerHost, 0, enet_packet_create(data, buf-data, ENET_PACKET_FLAG_RELIABLE)); @@ -617,8 +617,8 @@ void Net_SendChat(char *line) if (server) { WRITEUINT8(buf, SERVER_MESSAGE); - sprintf(buf, "\3<~%s> %s", cv_playername.string, line); - buf += strlen(buf)+1; + sprintf((char *)buf, "\3<~%s> %s", cv_playername.string, line); + buf += strlen((char *)buf)+1; CONS_Printf("%s\n", data+1); } else diff --git a/src/d_enet.h b/src/d_enet.h index cfe698177d8dc54d3d359e09c76d3b37f3dce91c..306ddb64fef58f05748a8e1d66dd9c292ca12f72 100644 --- a/src/d_enet.h +++ b/src/d_enet.h @@ -8,6 +8,9 @@ extern SINT8 nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if a extern UINT8 playerpernode[MAXNETNODES]; // used specialy for scplitscreen extern boolean nodeingame[MAXNETNODES]; // set false as nodes leave game +void D_NetOpen(void); +boolean D_NetConnect(const char *hostname, const char *port); + boolean Net_GetNetStat(void); void Net_AckTicker(void); boolean D_CheckNetGame(void); @@ -17,3 +20,4 @@ void Net_CloseConnection(INT32 node); void Net_SendJoin(void); void Net_SendCharacter(void); void Net_SpawnPlayer(UINT8 pnum, UINT8 node); +void Net_SendChat(char *line); diff --git a/src/d_main.c b/src/d_main.c index dc981ca32a7d7a8f22bdbfa1b0cbea043c88bd1d..474ef4424e23913fae181d468c850bde3e8358cb 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -67,11 +67,11 @@ int snprintf(char *str, size_t n, const char *fmt, ...); #include "m_cheat.h" #include "y_inter.h" #include "p_local.h" // chasecam -#include "mserv.h" // ms_RoomId #include "m_misc.h" // screenshot functionality #include "dehacked.h" // Dehacked list test #include "m_cond.h" // condition initialization #include "fastcmp.h" +#include "d_enet.h" #ifdef CMAKECONFIG #include "config.h" @@ -477,23 +477,8 @@ static void D_Display(void) // if (!wipe) { - if (cv_netstat.value) - { - char s[50]; - Net_GetNetStat(); - - s[sizeof s - 1] = '\0'; - + //if (cv_netstat.value) // NET TODO - //snprintf(s, sizeof s - 1, "get %d b/s", getbps); - //V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-40, V_YELLOWMAP, s); - //snprintf(s, sizeof s - 1, "send %d b/s", sendbps); - //V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-30, V_YELLOWMAP, s); - //snprintf(s, sizeof s - 1, "GameMiss %.2f%%", gamelostpercent); - //V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-20, V_YELLOWMAP, s); - //snprintf(s, sizeof s - 1, "SysMiss %.2f%%", lostpercent); - //V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-10, V_YELLOWMAP, s); - } I_FinishUpdate(); // page flip or blit buffer return; @@ -1220,17 +1205,6 @@ void D_SRB2Main(void) CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); - if (M_CheckParm("-room")) - { - if (!M_IsNextParm()) - I_Error("usage: -room <room_id>\nCheck the Master Server's webpage for room ID numbers.\n"); - ms_RoomId = atoi(M_GetNextParm()); - -#ifdef UPDATE_ALERT - GetMODVersion_Console(); -#endif - } - // init all NETWORK CONS_Printf("D_CheckNetGame(): Checking network game status.\n"); if (D_CheckNetGame()) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 1e37799593b923b05394b3baf89ab37b425967af..e352fdfa078879dd6ba372355753b76c7e2fc227 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -37,7 +37,6 @@ #include "d_main.h" #include "m_random.h" #include "f_finale.h" -#include "mserv.h" #include "md5.h" #include "z_zone.h" #include "lua_script.h" @@ -443,9 +442,6 @@ void D_RegisterServerCommands(void) #endif #endif - // for master server connection - AddMServCommands(); - // p_mobj.c CV_RegisterVar(&cv_itemrespawntime); CV_RegisterVar(&cv_itemrespawn); diff --git a/src/d_netfil.c b/src/d_netfil.c index 6c7be7314052da82f077902ec59ab36388d4c3e6..9bea902e6212c928908e0803905558146f512a05 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -61,8 +61,6 @@ #include <errno.h> -static void SendFile(INT32 node, const char *filename, UINT8 fileid); - // sender structure typedef struct filetx_s { @@ -339,74 +337,6 @@ void CL_LoadServerFiles(void) // little optimization to test if there is a file in the queue static INT32 filetosend = 0; -static void SendFile(INT32 node, const char *filename, UINT8 fileid) -{ - filetx_t **q; - filetx_t *p; - INT32 i; - char wadfilename[MAX_WADPATH]; - - q = &transfer[node].txlist; - while (*q) - q = &((*q)->next); - p = *q = (filetx_t *)malloc(sizeof (filetx_t)); - if (p) - memset(p, 0, sizeof (filetx_t)); - else - I_Error("SendFile: No more ram\n"); - p->filename = (char *)malloc(MAX_WADPATH); - if (!p->filename) - I_Error("SendFile: No more ram\n"); - - // a minimum of security, can get only file in srb2 direcory - strlcpy(p->filename, filename, MAX_WADPATH); - nameonly(p->filename); - - // check first in wads loaded the majority of case - for (i = 0; wadfiles[i]; i++) - { - strlcpy(wadfilename, wadfiles[i]->filename, MAX_WADPATH); - nameonly(wadfilename); - if (!stricmp(wadfilename, p->filename)) - { - // copy filename with full path - strlcpy(p->filename, wadfiles[i]->filename, MAX_WADPATH); - break; - } - } - - if (!wadfiles[i]) - { - DEBFILE(va("%s not found in wadfiles\n", filename)); - // this formerly checked if (!findfile(p->filename, NULL, true)) - - // not found - // don't inform client (probably hacker) - DEBFILE(va("Client %d request %s: not found\n", node, filename)); - free(p->filename); - free(p); - *q = NULL; - return; - } - - if (wadfiles[i]->filesize > (UINT32)cv_maxsend.value * 1024) - { - // too big - // don't inform client (client sucks, man) - DEBFILE(va("Client %d request %s: file too big, not sending\n", node, filename)); - free(p->filename); - free(p); - *q = NULL; - return; - } - - DEBFILE(va("Sending file %s (id=%d) to %d\n", filename, fileid, node)); - p->ram = SF_FILE; - p->fileid = fileid; - p->next = NULL; // end of list - filetosend++; -} - void SendRam(INT32 node, void *data, size_t size, freemethod_t freemethod, UINT8 fileid) { filetx_t **q; diff --git a/src/g_game.c b/src/g_game.c index 48388421aeb37486a7927157c1b2a0aa0b9aa332..e763c1e90835fdd450ca31ad6590db72db28ab86 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -45,6 +45,7 @@ #include "b_bot.h" #include "m_cond.h" // condition sets #include "md5.h" // demo checksums +#include "d_enet.h" gameaction_t gameaction; gamestate_t gamestate = GS_NULL; @@ -1839,7 +1840,6 @@ boolean G_Responder(event_t *ev) void G_Ticker(boolean run) { UINT32 i; - INT32 buf; P_MapStart(); // do player reborns if needed diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 32cee9abef5727b189cba3dcd84d0ac711135d4d..1c07ae225847c29616fa54cb6223c16510142b00 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -42,6 +42,8 @@ #include "p_local.h" // camera, camera2 #include "p_tick.h" +#include "d_enet.h" + #ifdef HWRENDER #include "hardware/hw_main.h" #endif diff --git a/src/m_menu.c b/src/m_menu.c index 1633d80f85c4f7205619ab61d216a920604bc409..f0a66c61afff44121f34ea441220c2b77a1cd807 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -46,13 +46,14 @@ #include "hardware/hw_main.h" #endif -#include "mserv.h" #include "m_misc.h" #include "m_anigif.h" #include "byteptr.h" #include "st_stuff.h" #include "i_sound.h" +#include "d_enet.h" + // Condition Sets #include "m_cond.h" @@ -196,9 +197,6 @@ levellist_mode_t levellistmode = LLM_CREATESERVER; UINT8 maplistoption = 0; static char joystickInfo[8][25]; -#ifndef NONET -static UINT32 serverlistpage; -#endif static saveinfo_t savegameinfo[MAXSAVEGAMES]; // Extra info about the save games. @@ -226,11 +224,6 @@ static boolean shiftdown = false; static void M_StopMessage(INT32 choice); -#ifndef NONET -static void M_HandleServerPage(INT32 choice); -static void M_RoomMenu(INT32 choice); -#endif - // Prototyping is fun, innit? // ========================================================================== // NEEDED FUNCTION PROTOTYPES GO HERE @@ -291,16 +284,10 @@ static menu_t SP_NightsAttackDef, SP_NightsReplayDef, SP_NightsGuestReplayDef, S // Multiplayer #ifndef NONET static void M_StartServerMenu(INT32 choice); -static void M_ConnectMenu(INT32 choice); static void M_ConnectIPMenu(INT32 choice); #endif static void M_StartSplitServerMenu(INT32 choice); static void M_StartServer(INT32 choice); -#ifndef NONET -static void M_Refresh(INT32 choice); -static void M_Connect(INT32 choice); -static void M_ChooseRoom(INT32 choice); -#endif static void M_SetupMultiPlayer(INT32 choice); static void M_SetupMultiPlayer2(INT32 choice); static void M_NetgameChoosePlayer(INT32 choice); @@ -363,9 +350,7 @@ static void M_OGL_DrawFogMenu(void); static void M_OGL_DrawColorMenu(void); #endif #ifndef NONET -static void M_DrawConnectMenu(void); static void M_DrawConnectIPMenu(void); -static void M_DrawRoomMenu(void); #endif static void M_DrawJoystick(void); static void M_DrawSetupMultiPlayerMenu(void); @@ -428,17 +413,6 @@ CV_PossibleValue_t gametype_cons_t[] = }; consvar_t cv_newgametype = {"newgametype", "Co-op", CV_HIDEN|CV_CALL, gametype_cons_t, Newgametype_OnChange, 0, NULL, NULL, 0, 0, NULL}; -static CV_PossibleValue_t serversort_cons_t[] = { - {0,"Ping"}, - {1,"Modified State"}, - {2,"Most Players"}, - {3,"Least Players"}, - {4,"Max Players"}, - {5,"Gametype"}, - {0,NULL} -}; -consvar_t cv_serversort = {"serversort", "Ping", CV_HIDEN | CV_CALL, serversort_cons_t, M_SortServerList, 0, NULL, NULL, 0, 0, NULL}; - // autorecord demos for time attack static consvar_t cv_autorecord = {"autorecord", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -906,7 +880,6 @@ static menuitem_t MP_MainMenu[] = { #ifndef NONET {IT_CALL | IT_STRING, NULL, "HOST GAME", M_StartServerMenu, 10}, - {IT_CALL | IT_STRING, NULL, "JOIN GAME (Search)", M_ConnectMenu, 30}, {IT_CALL | IT_STRING, NULL, "JOIN GAME (Specify IP)", M_ConnectIPMenu, 40}, #endif {IT_CALL | IT_STRING, NULL, "TWO PLAYER GAME", M_StartSplitServerMenu, 60}, @@ -915,13 +888,10 @@ static menuitem_t MP_MainMenu[] = {IT_CALL | IT_STRING, NULL, "SETUP PLAYER 2", M_SetupMultiPlayer2, 90}, }; +#ifndef NONET static menuitem_t MP_ServerMenu[] = { {IT_STRING|IT_CVAR, NULL, "Game Type", &cv_newgametype, 10}, -#ifndef NONET - {IT_STRING|IT_CALL, NULL, "Room...", M_RoomMenu, 20}, - {IT_STRING|IT_CVAR|IT_CV_STRING, NULL, "Server Name", &cv_servername, 30}, -#endif {IT_STRING|IT_CVAR, NULL, "Level", &cv_nextmap, 80}, @@ -931,66 +901,10 @@ static menuitem_t MP_ServerMenu[] = enum { mp_server_gametype = 0, -#ifndef NONET - mp_server_room, - mp_server_name, -#endif mp_server_level, mp_server_start }; -#ifndef NONET -static menuitem_t MP_ConnectMenu[] = -{ - {IT_STRING | IT_CALL, NULL, "Room...", M_RoomMenu, 4}, - {IT_STRING | IT_CVAR, NULL, "Sort By", &cv_serversort, 12}, - {IT_STRING | IT_KEYHANDLER, NULL, "Page", M_HandleServerPage, 20}, - {IT_STRING | IT_CALL, NULL, "Refresh", M_Refresh, 28}, - - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 48-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 60-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 72-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 84-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 96-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 108-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 120-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 132-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 144-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 156-4}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 168-4}, -}; - -enum -{ - mp_connect_room, - mp_connect_sort, - mp_connect_page, - mp_connect_refresh, - FIRSTSERVERLINE -}; - -static menuitem_t MP_RoomMenu[] = -{ - {IT_STRING | IT_CALL, NULL, "<Offline Mode>", M_ChooseRoom, 9}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 18}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 27}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 36}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 45}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 54}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 63}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 72}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 81}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 90}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 99}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 108}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 117}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 126}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 135}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 144}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 153}, - {IT_DISABLED, NULL, "", M_ChooseRoom, 162}, -}; - static menuitem_t MP_ConnectIPMenu[] = { {IT_KEYHANDLER | IT_STRING, NULL, " IP Address:", M_HandleConnectIP, 0}, @@ -1358,10 +1272,6 @@ static menuitem_t OP_EraseDataMenu[] = static menuitem_t OP_GameOptionsMenu[] = { -#ifndef NONET - {IT_STRING | IT_CVAR | IT_CV_STRING, - NULL, "Master server", &cv_masterserver, 10}, -#endif {IT_STRING | IT_CVAR, NULL, "Show HUD", &cv_showhud, 40}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "HUD Visibility", &cv_translucenthud, 50}, @@ -1384,11 +1294,6 @@ static menuitem_t OP_ServerOptionsMenu[] = {IT_STRING | IT_SUBMENU, NULL, "Gametype options...", &OP_GametypeOptionsDef, 20}, {IT_STRING | IT_SUBMENU, NULL, "Random Monitor Toggles...", &OP_MonitorToggleDef, 30}, -#ifndef NONET - {IT_STRING | IT_CVAR | IT_CV_STRING, - NULL, "Server name", &cv_servername, 50}, -#endif - {IT_STRING | IT_CVAR, NULL, "Intermission Timer", &cv_inttime, 80}, {IT_STRING | IT_CVAR, NULL, "Advance to next map", &cv_advancemap, 90}, @@ -1681,17 +1586,6 @@ menu_t SP_PlayerDef = menu_t MP_MainDef = DEFAULTMENUSTYLE("M_MULTI", MP_MainMenu, &MainDef, 60, 40); menu_t MP_ServerDef = MAPICONMENUSTYLE("M_MULTI", MP_ServerMenu, &MP_MainDef); #ifndef NONET -menu_t MP_ConnectDef = -{ - "M_MULTI", - sizeof (MP_ConnectMenu)/sizeof (menuitem_t), - &MP_MainDef, - MP_ConnectMenu, - M_DrawConnectMenu, - 27,24, - 0, - M_CancelConnect -}; menu_t MP_ConnectIPDef = { "M_MULTI", @@ -1703,17 +1597,6 @@ menu_t MP_ConnectIPDef = 0, M_CancelConnect }; -menu_t MP_RoomDef = -{ - "M_MULTI", - sizeof (MP_RoomMenu)/sizeof (menuitem_t), - &MP_ConnectDef, - MP_RoomMenu, - M_DrawRoomMenu, - 27, 32, - 0, - NULL -}; #endif menu_t MP_SplitServerDef = MAPICONMENUSTYLE("M_MULTI", MP_SplitServerMenu, &MP_MainDef); menu_t MP_PlayerSetupDef = @@ -2474,15 +2357,6 @@ boolean M_Responder(event_t *ev) currentMenu->lastOn = itemOn; if (currentMenu->prevMenu) { - //If we entered the game search menu, but didn't enter a game, - //make sure the game doesn't still think we're in a netgame. - if (!Playing() && netgame && multiplayer) - { - MSCloseUDPSocket(); // Clean up so we can re-open the connection later. - netgame = false; - multiplayer = false; - } - if (currentMenu == &SP_TimeAttackDef || currentMenu == &SP_NightsAttackDef) { // D_StartTitle does its own wipe, since GS_TIMEATTACK is now a complete gamestate. @@ -2809,10 +2683,6 @@ void M_Init(void) OP_VideoOptionsMenu[1].status = IT_DISABLED; #endif -#ifndef NONET - CV_RegisterVar(&cv_serversort); -#endif - //todo put this somewhere better... CV_RegisterVar(&cv_allcaps); } @@ -6059,335 +5929,13 @@ static void M_EndGame(INT32 choice) #define S_LINEY(n) currentMenu->y + SERVERHEADERHEIGHT + (n * SERVERLINEHEIGHT) #ifndef NONET -static UINT32 localservercount; - -static void M_HandleServerPage(INT32 choice) -{ - boolean exitmenu = false; // exit to previous menu - - switch (choice) - { - case KEY_DOWNARROW: - M_NextOpt(); - S_StartSound(NULL, sfx_menu1); - break; - case KEY_UPARROW: - M_PrevOpt(); - S_StartSound(NULL, sfx_menu1); - break; - case KEY_BACKSPACE: - case KEY_ESCAPE: - exitmenu = true; - break; - - case KEY_ENTER: - case KEY_RIGHTARROW: - S_StartSound(NULL, sfx_menu1); - if ((serverlistpage + 1) * SERVERS_PER_PAGE < serverlistcount) - serverlistpage++; - break; - case KEY_LEFTARROW: - S_StartSound(NULL, sfx_menu1); - if (serverlistpage > 0) - serverlistpage--; - break; - - default: - break; - } - if (exitmenu) - { - if (currentMenu->prevMenu) - M_SetupNextMenu(currentMenu->prevMenu); - else - M_ClearMenus(true); - } -} - -static void M_Connect(INT32 choice) -{ - // do not call menuexitfunc - M_ClearMenus(false); - - COM_BufAddText(va("connect node %d\n", serverlist[choice-FIRSTSERVERLINE + serverlistpage * SERVERS_PER_PAGE].node)); -} - -static void M_Refresh(INT32 choice) -{ - (void)choice; - - // Display a little "please wait" message. - M_DrawTextBox(52, BASEVIDHEIGHT/2-10, 25, 3); - V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, 0, "Searching for servers..."); - V_DrawCenteredString(BASEVIDWIDTH/2, (BASEVIDHEIGHT/2)+12, 0, "Please wait."); - I_OsPolling(); - I_UpdateNoBlit(); - if (rendermode == render_soft) - I_FinishUpdate(); // page flip or blit buffer - - // note: this is the one case where 0 is a valid room number - // because it corresponds to "All" - CL_UpdateServerList(!(ms_RoomId < 0), ms_RoomId); - - // first page of servers - serverlistpage = 0; -} - -static INT32 menuRoomIndex = 0; - -static void M_DrawRoomMenu(void) -{ - const char *rmotd; - - // use generic drawer for cursor, items and title - M_DrawGenericMenu(); - - V_DrawString(currentMenu->x - 16, currentMenu->y, V_YELLOWMAP, M_GetText("Select a room")); - - M_DrawTextBox(144, 24, 20, 20); - - if (itemOn == 0) - rmotd = M_GetText("Don't connect to the Master Server."); - else - rmotd = room_list[itemOn-1].motd; - - rmotd = V_WordWrap(0, 20*8, 0, rmotd); - V_DrawString(144+8, 32, V_ALLOWLOWERCASE|V_RETURN8, rmotd); -} - -static void M_DrawConnectMenu(void) -{ - UINT16 i, j; - const char *gt = "Unknown"; - INT32 numPages = (serverlistcount+(SERVERS_PER_PAGE-1))/SERVERS_PER_PAGE; - - for (i = FIRSTSERVERLINE; i < min(localservercount, SERVERS_PER_PAGE)+FIRSTSERVERLINE; i++) - MP_ConnectMenu[i].status = IT_STRING | IT_SPACE; - - if (!numPages) - numPages = 1; - - // Room name - if (ms_RoomId < 0) - V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ConnectMenu[mp_connect_room].alphaKey, - V_YELLOWMAP, (itemOn == mp_connect_room) ? "<Select to change>" : "<Offline Mode>"); - else - V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ConnectMenu[mp_connect_room].alphaKey, - V_YELLOWMAP, room_list[menuRoomIndex].name); - - // Page num - V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ConnectMenu[mp_connect_page].alphaKey, - V_YELLOWMAP, va("%u of %d", serverlistpage+1, numPages)); - - // Horizontal line! - V_DrawFill(1, currentMenu->y+40, 318, 1, 0); - - if (serverlistcount <= 0) - V_DrawString(currentMenu->x,currentMenu->y+SERVERHEADERHEIGHT, 0, "No servers found"); - else - for (i = 0; i < min(serverlistcount - serverlistpage * SERVERS_PER_PAGE, SERVERS_PER_PAGE); i++) - { - INT32 slindex = i + serverlistpage * SERVERS_PER_PAGE; - UINT32 globalflags = ((serverlist[slindex].info.numberofplayer >= serverlist[slindex].info.maxplayer) ? V_TRANSLUCENT : 0) - |((itemOn == FIRSTSERVERLINE+i) ? V_YELLOWMAP : 0)|V_ALLOWLOWERCASE; - - V_DrawString(currentMenu->x, S_LINEY(i), globalflags, serverlist[slindex].info.servername); - - // Don't use color flags intentionally, the global yellow color will auto override the text color code - if (serverlist[slindex].info.modifiedgame) - V_DrawSmallString(currentMenu->x+202, S_LINEY(i)+8, globalflags, "\x85" "Mod"); - if (serverlist[slindex].info.cheatsenabled) - V_DrawSmallString(currentMenu->x+222, S_LINEY(i)+8, globalflags, "\x83" "Cheats"); - - V_DrawSmallString(currentMenu->x, S_LINEY(i)+8, globalflags, - va("Ping: %u", (UINT32)LONG(serverlist[slindex].info.time))); - - gt = "Unknown"; - for (j = 0; gametype_cons_t[j].strvalue; j++) - { - if (gametype_cons_t[j].value == serverlist[slindex].info.gametype) - gt = gametype_cons_t[j].strvalue; - } - - V_DrawSmallString(currentMenu->x+46,S_LINEY(i)+8, globalflags, - va("Players: %02d/%02d", serverlist[slindex].info.numberofplayer, serverlist[slindex].info.maxplayer)); - - V_DrawSmallString(currentMenu->x+112, S_LINEY(i)+8, globalflags, va("Gametype: %s", gt)); - - MP_ConnectMenu[i+FIRSTSERVERLINE].status = IT_STRING | IT_CALL; - } - - localservercount = serverlistcount; - - M_DrawGenericMenu(); -} - static boolean M_CancelConnect(void) { D_CloseConnection(); return true; } - -// Ascending order, not descending. -// The casts are safe as long as the caller doesn't do anything stupid. -#define SERVER_LIST_ENTRY_COMPARATOR(key) \ -static int ServerListEntryComparator_##key(const void *entry1, const void *entry2) \ -{ \ - const serverelem_t *sa = (const serverelem_t*)entry1, *sb = (const serverelem_t*)entry2; \ - if (sa->info.key != sb->info.key) \ - return sa->info.key - sb->info.key; \ - return strcmp(sa->info.servername, sb->info.servername); \ -} - -// This does descending instead of ascending. -#define SERVER_LIST_ENTRY_COMPARATOR_REVERSE(key) \ -static int ServerListEntryComparator_##key##_reverse(const void *entry1, const void *entry2) \ -{ \ - const serverelem_t *sa = (const serverelem_t*)entry1, *sb = (const serverelem_t*)entry2; \ - if (sb->info.key != sa->info.key) \ - return sb->info.key - sa->info.key; \ - return strcmp(sb->info.servername, sa->info.servername); \ -} - -SERVER_LIST_ENTRY_COMPARATOR(time) -SERVER_LIST_ENTRY_COMPARATOR(numberofplayer) -SERVER_LIST_ENTRY_COMPARATOR_REVERSE(numberofplayer) -SERVER_LIST_ENTRY_COMPARATOR_REVERSE(maxplayer) -SERVER_LIST_ENTRY_COMPARATOR(gametype) - -// Special one for modified state. -static int ServerListEntryComparator_modified(const void *entry1, const void *entry2) -{ - const serverelem_t *sa = (const serverelem_t*)entry1, *sb = (const serverelem_t*)entry2; - - // Modified acts as 2 points, cheats act as one point. - int modstate_a = (sa->info.cheatsenabled ? 1 : 0) | (sa->info.modifiedgame ? 2 : 0); - int modstate_b = (sb->info.cheatsenabled ? 1 : 0) | (sb->info.modifiedgame ? 2 : 0); - - if (modstate_a != modstate_b) - return modstate_a - modstate_b; - - // Default to strcmp. - return strcmp(sa->info.servername, sb->info.servername); -} #endif -void M_SortServerList(void) -{ -#ifndef NONET - switch(cv_serversort.value) - { - case 0: // Ping. - qsort(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_time); - break; - case 1: // Modified state. - qsort(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_modified); - break; - case 2: // Most players. - qsort(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_numberofplayer_reverse); - break; - case 3: // Least players. - qsort(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_numberofplayer); - break; - case 4: // Max players. - qsort(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_maxplayer_reverse); - break; - case 5: // Gametype. - qsort(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_gametype); - break; - } -#endif -} - -#ifndef NONET -#ifdef UPDATE_ALERT -static int M_CheckMODVersion(void) -{ - char updatestring[500]; - const char *updatecheck = GetMODVersion(); - if(updatecheck) - { - sprintf(updatestring, UPDATE_ALERT_STRING, VERSIONSTRING, updatecheck); - M_StartMessage(updatestring, NULL, MM_NOTHING); - return false; - } else - return true; -} -#endif - -static void M_ConnectMenu(INT32 choice) -{ - (void)choice; - // modified game check: no longer handled - // we don't request a restart unless the filelist differs - - // first page of servers - serverlistpage = 0; - M_SetupNextMenu(&MP_ConnectDef); - itemOn = 0; - M_Refresh(0); -} - -static UINT32 roomIds[NUM_LIST_ROOMS]; - -static void M_RoomMenu(INT32 choice) -{ - INT32 i; - - (void)choice; - - // Display a little "please wait" message. - M_DrawTextBox(52, BASEVIDHEIGHT/2-10, 25, 3); - V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, 0, "Fetching room info..."); - V_DrawCenteredString(BASEVIDWIDTH/2, (BASEVIDHEIGHT/2)+12, 0, "Please wait."); - I_OsPolling(); - I_UpdateNoBlit(); - if (rendermode == render_soft) - I_FinishUpdate(); // page flip or blit buffer - - if (GetRoomsList(currentMenu == &MP_ServerDef) < 0) - return; - -#ifdef UPDATE_ALERT - if (!M_CheckMODVersion()) - return; -#endif - - for (i = 1; i < NUM_LIST_ROOMS+1; ++i) - MP_RoomMenu[i].status = IT_DISABLED; - memset(roomIds, 0, sizeof(roomIds)); - - for (i = 0; room_list[i].header.buffer[0]; i++) - { - if(*room_list[i].name != '\0') - { - MP_RoomMenu[i+1].text = room_list[i].name; - roomIds[i] = room_list[i].id; - MP_RoomMenu[i+1].status = IT_STRING|IT_CALL; - } - } - - MP_RoomDef.prevMenu = currentMenu; - M_SetupNextMenu(&MP_RoomDef); -} - -static void M_ChooseRoom(INT32 choice) -{ - if (choice == 0) - ms_RoomId = -1; - else - { - ms_RoomId = roomIds[choice-1]; - menuRoomIndex = choice - 1; - } - - serverlistpage = 0; - M_SetupNextMenu(currentMenu->prevMenu); - if (currentMenu == &MP_ConnectDef) - M_Refresh(0); -} -#endif //NONET - //=========================================================================== // Start Server Menu //=========================================================================== @@ -6456,19 +6004,6 @@ static void M_DrawServerMenu(void) M_DrawGenericMenu(); -#ifndef NONET - // Room name - if (currentMenu == &MP_ServerDef) - { - if (ms_RoomId < 0) - V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ServerMenu[mp_server_room].alphaKey, - V_YELLOWMAP, (itemOn == mp_server_room) ? "<Select to change>" : "<Offline Mode>"); - else - V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ServerMenu[mp_server_room].alphaKey, - V_YELLOWMAP, room_list[menuRoomIndex].name); - } -#endif - // A 160x100 image of the level as entry MAPxxP lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(cv_nextmap.value))); @@ -6507,7 +6042,6 @@ static void M_StartServerMenu(INT32 choice) (void)choice; levellistmode = LLM_CREATESERVER; M_PrepareLevelSelect(); - ms_RoomId = -1; M_SetupNextMenu(&MP_ServerDef); } diff --git a/src/m_menu.h b/src/m_menu.h index d42ee8aa96762df4e01735ee9f7226e922c34ee5..5abd867404e36d731e856e219e00e53abbaec1b0 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -45,9 +45,6 @@ void M_StartControlPanel(void); // Called upon end of a mode attack run void M_EndModeAttackRun(void); -// Called on new server add, or other reasons -void M_SortServerList(void); - // Draws a box with a texture inside as background for messages void M_DrawTextBox(INT32 x, INT32 y, INT32 width, INT32 boxlines); @@ -212,7 +209,7 @@ typedef struct extern description_t description[32]; extern description_t MP_Description[32]; -extern consvar_t cv_newgametype, cv_nextmap, cv_chooseskin, cv_serversort; +extern consvar_t cv_newgametype, cv_nextmap, cv_chooseskin; extern CV_PossibleValue_t gametype_cons_t[]; extern INT16 startmap; @@ -302,4 +299,7 @@ void Screenshot_option_Onchange(void); NULL\ } +// Netgame stuff +void M_SetupNetgameChoosePlayer(void); + #endif //__X_MENU__ diff --git a/src/mserv.c b/src/mserv.c deleted file mode 100644 index ae7da09b0cdec109af076304f88e66e3444ccc82..0000000000000000000000000000000000000000 --- a/src/mserv.c +++ /dev/null @@ -1,906 +0,0 @@ -// SONIC ROBO BLAST 2 -//----------------------------------------------------------------------------- -// Copyright (C) 1998-2000 by DooM Legacy Team. -// Copyright (C) 1999-2014 by Sonic Team Junior. -// -// This program is free software distributed under the -// terms of the GNU General Public License, version 2. -// See the 'LICENSE' file for more details. -//----------------------------------------------------------------------------- -/// \file mserv.c -/// \brief Commands used for communicate with the master server - -#ifdef __GNUC__ -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#endif - -#if !defined (UNDER_CE) -#include <time.h> -#endif - -#if (defined (NOMD5) || defined (NOMSERV)) && !defined (NONET) -#define NONET -#endif - -#ifndef NONET - -#ifndef NO_IPV6 -#define HAVE_IPV6 -#endif - -#if (defined (_WIN32) || defined (_WIN32_WCE)) && !defined (_XBOX) -#define RPC_NO_WINDOWS_H -#ifdef HAVE_IPV6 -#include <ws2tcpip.h> -#else -#include <winsock.h> // socket(),... -#endif //!HAVE_IPV6 -#else -#ifdef __OS2__ -#include <sys/types.h> -#endif // __OS2__ - -#ifdef HAVE_LWIP -#include <lwip/inet.h> -#include <kos/net.h> -#include <lwip/lwip.h> -#define ioctl lwip_ioctl -#else -#include <arpa/inet.h> -#ifdef __APPLE_CC__ -#ifndef _BSD_SOCKLEN_T_ -#define _BSD_SOCKLEN_T_ -#endif -#endif -#include <sys/socket.h> // socket(),... -#include <netinet/in.h> // sockaddr_in -#ifdef _PS3 -#include <net/select.h> -#elif !defined(_arch_dreamcast) -#include <netdb.h> // getaddrinfo(),... -#include <sys/ioctl.h> -#endif -#endif - -#ifdef _arch_dreamcast -#include "sdl/SRB2DC/dchelp.h" -#endif - -#include <sys/time.h> // timeval,... (TIMEOUT) -#include <errno.h> -#endif // _WIN32/_WIN32_WCE - -#ifdef __OS2__ -#include <errno.h> -#endif // __OS2__ -#endif // !NONET - -#include "doomstat.h" -#include "doomdef.h" -#include "command.h" -#include "console.h" -#include "mserv.h" -#include "i_system.h" -#include "byteptr.h" -#include "m_menu.h" -#include "m_argv.h" // Alam is going to kill me <3 -#include "m_misc.h" // GetRevisionString() - -#ifdef _WIN32_WCE -#include "sdl/SRB2CE/cehelp.h" -#endif - -#include "i_addrinfo.h" - -// ================================ DEFINITIONS =============================== - -#define PACKET_SIZE 1024 - - -#define MS_NO_ERROR 0 -#define MS_SOCKET_ERROR -201 -#define MS_CONNECT_ERROR -203 -#define MS_WRITE_ERROR -210 -#define MS_READ_ERROR -211 -#define MS_CLOSE_ERROR -212 -#define MS_GETHOSTBYNAME_ERROR -220 -#define MS_GETHOSTNAME_ERROR -221 -#define MS_TIMEOUT_ERROR -231 - -// see master server code for the values -#define ADD_SERVER_MSG 101 -#define REMOVE_SERVER_MSG 103 -#define ADD_SERVERv2_MSG 104 -#define GET_SERVER_MSG 200 -#define GET_SHORT_SERVER_MSG 205 -#define ASK_SERVER_MSG 206 -#define ANSWER_ASK_SERVER_MSG 207 -#define ASK_SERVER_MSG 206 -#define ANSWER_ASK_SERVER_MSG 207 -#define GET_MOTD_MSG 208 -#define SEND_MOTD_MSG 209 -#define GET_ROOMS_MSG 210 -#define SEND_ROOMS_MSG 211 -#define GET_ROOMS_HOST_MSG 212 -#define GET_VERSION_MSG 213 -#define SEND_VERSION_MSG 214 -#define GET_BANNED_MSG 215 // Someone's been baaaaaad! -#define PING_SERVER_MSG 216 - -#define HEADER_SIZE (sizeof (INT32)*4) - -#define HEADER_MSG_POS 0 -#define IP_MSG_POS 16 -#define PORT_MSG_POS 32 -#define HOSTNAME_MSG_POS 40 - - -#if defined(_MSC_VER) -#pragma pack(1) -#endif - -/** A message to be exchanged with the master server. - */ -typedef struct -{ - INT32 id; ///< Unused? - INT32 type; ///< Type of message. - INT32 room; ///< Because everyone needs a roomie. - UINT32 length; ///< Length of the message. - char buffer[PACKET_SIZE]; ///< Actual contents of the message. -} ATTRPACK msg_t; - -#if defined(_MSC_VER) -#pragma pack() -#endif - -typedef struct Copy_CVarMS_t -{ - char ip[64]; - char port[8]; - char name[64]; -} Copy_CVarMS_s; -static Copy_CVarMS_s registered_server; -static time_t MSLastPing; - -#if defined(_MSC_VER) -#pragma pack(1) -#endif -typedef struct -{ - char ip[16]; // Big enough to hold a full address. - UINT16 port; - UINT8 padding1[2]; - tic_t time; -} ATTRPACK ms_holepunch_packet_t; -#if defined(_MSC_VER) -#pragma pack() -#endif - -// win32 or djgpp -#if defined (_WIN32) || defined (_WIN32_WCE) || defined (__DJGPP__) -#define ioctl ioctlsocket -#define close closesocket -#ifdef WATTCP -#define strerror strerror_s -#endif -#if defined (_WIN32) || defined (_WIN32_WCE) -#undef errno -#define errno h_errno // some very strange things happen when not using h_error -#endif -#ifndef AI_ADDRCONFIG -#define AI_ADDRCONFIG 0x00000400 -#endif -#endif - -#ifndef NONET -static void Command_Listserv_f(void); -#endif -static void MasterServer_OnChange(void); -static void ServerName_OnChange(void); - -#define DEF_PORT "28900" -consvar_t cv_masterserver = {"masterserver", "ms.srb2.org:"DEF_PORT, CV_SAVE, NULL, MasterServer_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_servername = {"servername", "SRB2 server", CV_SAVE, NULL, ServerName_OnChange, 0, NULL, NULL, 0, 0, NULL}; - -INT16 ms_RoomId = -1; - -static enum { MSCS_NONE, MSCS_WAITING, MSCS_REGISTERED, MSCS_FAILED } con_state = MSCS_NONE; - -static INT32 msnode = -1; -UINT16 current_port = 0; - -#if (defined (_WIN32) || defined (_WIN32_WCE) || defined (_WIN32)) && !defined (NONET) -typedef SOCKET SOCKET_TYPE; -#define BADSOCKET INVALID_SOCKET -#define ERRSOCKET (SOCKET_ERROR) -#else -#if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) || defined (_PS3) -typedef int SOCKET_TYPE; -#else -typedef unsigned long SOCKET_TYPE; -#endif -#define BADSOCKET (SOCKET_TYPE)(~0) -#define ERRSOCKET (-1) -#endif - -#if (defined (WATTCP) && !defined (__libsocket_socklen_t)) || defined (_WIN32) -typedef int socklen_t; -#endif - -#ifndef NONET -static SOCKET_TYPE socket_fd = BADSOCKET; // WINSOCK socket -static struct timeval select_timeout; -static fd_set wset; -static size_t recvfull(SOCKET_TYPE s, char *buf, size_t len, int flags); -#endif - -// Room list is an external variable now. -// Avoiding having to get info ten thousand times... -msg_rooms_t room_list[NUM_LIST_ROOMS+1]; // +1 for easy test - -/** Adds variables and commands relating to the master server. - * - * \sa cv_masterserver, cv_servername, - * Command_Listserv_f - */ -void AddMServCommands(void) -{ -#ifndef NONET - CV_RegisterVar(&cv_masterserver); - CV_RegisterVar(&cv_servername); - COM_AddCommand("listserv", Command_Listserv_f); -#endif -} - -/** Closes the connection to the master server. - * - * \todo Fix for Windows? - */ -static void CloseConnection(void) -{ -#ifndef NONET - if (socket_fd != (SOCKET_TYPE)ERRSOCKET && socket_fd != BADSOCKET) - close(socket_fd); - socket_fd = BADSOCKET; -#endif -} - -// -// MS_Write(): -// -static INT32 MS_Write(msg_t *msg) -{ -#ifdef NONET - (void)msg; - return MS_WRITE_ERROR; -#else - size_t len; - - if (msg->length == 0) - msg->length = (INT32)strlen(msg->buffer); - len = msg->length + HEADER_SIZE; - - msg->type = htonl(msg->type); - msg->length = htonl(msg->length); - msg->room = htonl(msg->room); - - if ((size_t)send(socket_fd, (char *)msg, (int)len, 0) != len) - return MS_WRITE_ERROR; - return 0; -#endif -} - -// -// MS_Read(): -// -static INT32 MS_Read(msg_t *msg) -{ -#ifdef NONET - (void)msg; - return MS_READ_ERROR; -#else - if (recvfull(socket_fd, (char *)msg, HEADER_SIZE, 0) != HEADER_SIZE) - return MS_READ_ERROR; - - msg->type = ntohl(msg->type); - msg->length = ntohl(msg->length); - msg->room = ntohl(msg->room); - - if (!msg->length) // fix a bug in Windows 2000 - return 0; - - if (recvfull(socket_fd, (char *)msg->buffer, msg->length, 0) != msg->length) - return MS_READ_ERROR; - return 0; -#endif -} - -#ifndef NONET -/** Gets a list of game servers from the master server. - */ -static INT32 GetServersList(void) -{ - msg_t msg; - INT32 count = 0; - - msg.type = GET_SERVER_MSG; - msg.length = 0; - msg.room = 0; - if (MS_Write(&msg) < 0) - return MS_WRITE_ERROR; - - while (MS_Read(&msg) >= 0) - { - if (!msg.length) - { - if (!count) - CONS_Alert(CONS_NOTICE, M_GetText("No servers currently running.\n")); - return MS_NO_ERROR; - } - count++; - CONS_Printf("%s",msg.buffer); - } - - return MS_READ_ERROR; -} -#endif - -/** Get the MOTD from the master server. - */ -static inline INT32 GetMSMOTD(void) -{ - msg_t msg; - INT32 count = 0; - - msg.type = GET_MOTD_MSG; - msg.length = 0; - if (MS_Write(&msg) < 0) - return MS_WRITE_ERROR; - - while (MS_Read(&msg) >= 0) - { - if (!msg.length) - { - if (!count) - CONS_Alert(CONS_NOTICE, M_GetText("No servers currently running.\n")); - return MS_NO_ERROR; - } - count++; - CONS_Printf("%s",msg.buffer); - } - - return MS_READ_ERROR; -} - -// -// MS_Connect() -// -static INT32 MS_Connect(const char *ip_addr, const char *str_port, INT32 async) -{ - // NET TODO - (void)ip_addr; - (void)str_port; - (void)async; - return MS_CONNECT_ERROR; -} - -#define NUM_LIST_SERVER MAXSERVERLIST -const msg_server_t *GetShortServersList(INT32 room) -{ - static msg_server_t server_list[NUM_LIST_SERVER+1]; // +1 for easy test - msg_t msg; - INT32 i; - - // we must be connected to the master server before writing to it - if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot connect to the Master Server\n")); - M_StartMessage(M_GetText("There was a problem connecting to\nthe Master Server\n"), NULL, MM_NOTHING); - return NULL; - } - - msg.type = GET_SHORT_SERVER_MSG; - msg.length = 0; - msg.room = room; - if (MS_Write(&msg) < 0) - return NULL; - - for (i = 0; i < NUM_LIST_SERVER && MS_Read(&msg) >= 0; i++) - { - if (!msg.length) - { - server_list[i].header.buffer[0] = 0; - CloseConnection(); - return server_list; - } - M_Memcpy(&server_list[i], msg.buffer, sizeof (msg_server_t)); - server_list[i].header.buffer[0] = 1; - } - CloseConnection(); - if (i == NUM_LIST_SERVER) - { - server_list[i].header.buffer[0] = 0; - return server_list; - } - else - return NULL; -} - -INT32 GetRoomsList(boolean hosting) -{ - static msg_ban_t banned_info[1]; - msg_t msg; - INT32 i; - - // we must be connected to the master server before writing to it - if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot connect to the Master Server\n")); - M_StartMessage(M_GetText("There was a problem connecting to\nthe Master Server\n"), NULL, MM_NOTHING); - return -1; - } - - if (hosting) - msg.type = GET_ROOMS_HOST_MSG; - else - msg.type = GET_ROOMS_MSG; - msg.length = 0; - msg.room = 0; - if (MS_Write(&msg) < 0) - { - room_list[0].id = 1; - strcpy(room_list[0].motd,"Master Server Offline."); - strcpy(room_list[0].name,"Offline"); - return -1; - } - - for (i = 0; i < NUM_LIST_ROOMS && MS_Read(&msg) >= 0; i++) - { - if(msg.type == GET_BANNED_MSG) - { - char banmsg[1000]; - M_Memcpy(&banned_info[0], msg.buffer, sizeof (msg_ban_t)); - if (hosting) - sprintf(banmsg, M_GetText("You have been banned from\nhosting netgames.\n\nUnder the following IP Range:\n%s - %s\n\nFor the following reason:\n%s\n\nYour ban will expire on:\n%s"),banned_info[0].ipstart,banned_info[0].ipend,banned_info[0].reason,banned_info[0].endstamp); - else - sprintf(banmsg, M_GetText("You have been banned from\njoining netgames.\n\nUnder the following IP Range:\n%s - %s\n\nFor the following reason:\n%s\n\nYour ban will expire on:\n%s"),banned_info[0].ipstart,banned_info[0].ipend,banned_info[0].reason,banned_info[0].endstamp); - M_StartMessage(banmsg, NULL, MM_NOTHING); - ms_RoomId = -1; - return -2; - } - if (!msg.length) - { - room_list[i].header.buffer[0] = 0; - CloseConnection(); - return 1; - } - M_Memcpy(&room_list[i], msg.buffer, sizeof (msg_rooms_t)); - room_list[i].header.buffer[0] = 1; - } - CloseConnection(); - if (i == NUM_LIST_ROOMS) - { - room_list[i].header.buffer[0] = 0; - return 1; - } - else - { - room_list[0].id = 1; - strcpy(room_list[0].motd,M_GetText("Master Server Offline.")); - strcpy(room_list[0].name,M_GetText("Offline")); - return -1; - } -} - -#ifdef UPDATE_ALERT -const char *GetMODVersion(void) -{ - static msg_t msg; - - // we must be connected to the master server before writing to it - if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot connect to the Master Server\n")); - M_StartMessage(M_GetText("There was a problem connecting to\nthe Master Server\n"), NULL, MM_NOTHING); - return NULL; - } - - msg.type = GET_VERSION_MSG; - msg.length = sizeof MODVERSION; - msg.room = MODID; // Might as well use it for something. - sprintf(msg.buffer,"%d",MODVERSION); - if (MS_Write(&msg) < 0) - return NULL; - - MS_Read(&msg); - CloseConnection(); - - if(strcmp(msg.buffer,"NULL") != 0) - { - return msg.buffer; - } - else - return NULL; -} - -// Console only version of the above (used before game init) -void GetMODVersion_Console(void) -{ - static msg_t msg; - - // we must be connected to the master server before writing to it - if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot connect to the Master Server\n")); - return; - } - - msg.type = GET_VERSION_MSG; - msg.length = sizeof MODVERSION; - msg.room = MODID; // Might as well use it for something. - sprintf(msg.buffer,"%d",MODVERSION); - if (MS_Write(&msg) < 0) - return; - - MS_Read(&msg); - CloseConnection(); - - if(strcmp(msg.buffer,"NULL") != 0) - I_Error(UPDATE_ALERT_STRING_CONSOLE, VERSIONSTRING, msg.buffer); -} -#endif - -#ifndef NONET -/** Gets a list of game servers. Called from console. - */ -static void Command_Listserv_f(void) -{ - if (con_state == MSCS_WAITING) - { - CONS_Alert(CONS_NOTICE, M_GetText("Not yet connected to the Master Server.\n")); - return; - } - - CONS_Printf(M_GetText("Retrieving server list...\n")); - - if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot connect to the Master Server\n")); - return; - } - - if (GetServersList()) - CONS_Alert(CONS_ERROR, M_GetText("Cannot get server list\n")); - - CloseConnection(); -} -#endif - -FUNCMATH static const char *int2str(INT32 n) -{ - INT32 i; - static char res[16]; - - res[15] = '\0'; - res[14] = (char)((char)(n%10)+'0'); - for (i = 13; (n /= 10); i--) - res[i] = (char)((char)(n%10)+'0'); - - return &res[i+1]; -} - -#ifndef NONET -static INT32 ConnectionFailed(void) -{ - con_state = MSCS_FAILED; - CONS_Alert(CONS_ERROR, M_GetText("Connection to Master Server failed\n")); - CloseConnection(); - return MS_CONNECT_ERROR; -} -#endif - -/** Tries to register the local game server on the master server. - */ -static INT32 AddToMasterServer(boolean firstadd) -{ -#ifdef NONET - (void)firstadd; -#else - static INT32 retry = 0; - int i, res; - socklen_t j; - msg_t msg; - msg_server_t *info = (msg_server_t *)msg.buffer; - INT32 room = -1; - fd_set tset; - time_t timestamp = time(NULL); - UINT32 signature, tmp; - const char *insname; - - M_Memcpy(&tset, &wset, sizeof (tset)); - res = select(255, NULL, &tset, NULL, &select_timeout); - if (res != ERRSOCKET && !res) - { - if (retry++ > 30) // an about 30 second timeout - { - retry = 0; - CONS_Alert(CONS_ERROR, M_GetText("Master Server timed out\n")); - MSLastPing = timestamp; - return ConnectionFailed(); - } - return MS_CONNECT_ERROR; - } - retry = 0; - if (res == ERRSOCKET) - { - if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) - { - CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error #%u: %s\n"), errno, strerror(errno)); - MSLastPing = timestamp; - return ConnectionFailed(); - } - } - - // so, the socket is writable, but what does that mean, that the connection is - // ok, or bad... let see that! - j = (socklen_t)sizeof (i); - getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, (char *)&i, &j); - if (i) // it was bad - { - CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error #%u: %s\n"), errno, strerror(errno)); - MSLastPing = timestamp; - return ConnectionFailed(); - } - -#ifdef PARANOIA - if (ms_RoomId <= 0) - I_Error("Attmepted to host in room \"All\"!\n"); -#endif - room = ms_RoomId; - - for(signature = 0, insname = cv_servername.string; *insname; signature += *insname++); - tmp = (UINT32)(signature * (size_t)&MSLastPing); - signature *= tmp; - signature &= 0xAAAAAAAA; - M_Memcpy(&info->header.signature, &signature, sizeof (UINT32)); - - strcpy(info->ip, ""); - strcpy(info->port, int2str(current_port)); - strcpy(info->name, cv_servername.string); - M_Memcpy(&info->room, & room, sizeof (INT32)); -#if VERSION > 0 || SUBVERSION > 0 - sprintf(info->version, "%d.%d.%d", VERSION/100, VERSION%100, SUBVERSION); -#else // Trunk build, send revision info - strcpy(info->version, GetRevisionString()); -#endif - strcpy(registered_server.name, cv_servername.string); - - if(firstadd) - msg.type = ADD_SERVER_MSG; - else - msg.type = PING_SERVER_MSG; - - msg.length = (UINT32)sizeof (msg_server_t); - msg.room = 0; - if (MS_Write(&msg) < 0) - { - MSLastPing = timestamp; - return ConnectionFailed(); - } - - if(con_state != MSCS_REGISTERED) - CONS_Printf(M_GetText("Master Server update successful.\n")); - - MSLastPing = timestamp; - con_state = MSCS_REGISTERED; - CloseConnection(); -#endif - return MS_NO_ERROR; -} - -static INT32 RemoveFromMasterSever(void) -{ - msg_t msg; - msg_server_t *info = (msg_server_t *)msg.buffer; - - strcpy(info->header.buffer, ""); - strcpy(info->ip, ""); - strcpy(info->port, int2str(current_port)); - strcpy(info->name, registered_server.name); - sprintf(info->version, "%d.%d.%d", VERSION/100, VERSION%100, SUBVERSION); - - msg.type = REMOVE_SERVER_MSG; - msg.length = (UINT32)sizeof (msg_server_t); - msg.room = 0; - if (MS_Write(&msg) < 0) - return MS_WRITE_ERROR; - - return MS_NO_ERROR; -} - -const char *GetMasterServerPort(void) -{ - const char *t = cv_masterserver.string; - - while ((*t != ':') && (*t != '\0')) - t++; - - if (*t) - return ++t; - else - return DEF_PORT; -} - -/** Gets the IP address of the master server. Actually, it seems to just - * return the hostname, instead; the lookup is done elsewhere. - * - * \return Hostname of the master server, without port number on the end. - * \todo Rename function? - */ -const char *GetMasterServerIP(void) -{ - static char str_ip[64]; - char *t = str_ip; - - if (strstr(cv_masterserver.string, "srb2.ssntails.org:28910") - || strstr(cv_masterserver.string, "srb2.servegame.org:28910") - || strstr(cv_masterserver.string, "srb2.servegame.org:28900") - ) - { - // replace it with the current default one - CV_Set(&cv_masterserver, cv_masterserver.defaultvalue); - } - - strcpy(t, cv_masterserver.string); - - while ((*t != ':') && (*t != '\0')) - t++; - *t = '\0'; - - return str_ip; -} - -void MSOpenUDPSocket(void) -{ - // NET TODO - msnode = -1; -} - -void MSCloseUDPSocket(void) -{ - // NET TODO - msnode = -1; -} - -void RegisterServer(void) -{ - if (con_state == MSCS_REGISTERED || con_state == MSCS_WAITING) - return; - - CONS_Printf(M_GetText("Registering this server on the Master Server...\n")); - - strcpy(registered_server.ip, GetMasterServerIP()); - strcpy(registered_server.port, GetMasterServerPort()); - - if (MS_Connect(registered_server.ip, registered_server.port, 1)) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot connect to the Master Server\n")); - return; - } - MSOpenUDPSocket(); - - // keep the TCP connection open until AddToMasterServer() is completed; -} - -static inline void SendPingToMasterServer(void) -{ -/* static tic_t next_time = 0; - tic_t cur_time; - char *inbuffer = (char*)netbuffer; - - cur_time = I_GetTime(); - if (!netgame) - UnregisterServer(); - else if (cur_time > next_time) // ping every 2 second if possible - { - next_time = cur_time+2*TICRATE; - - if (con_state == MSCS_WAITING) - AddToMasterServer(); - - if (con_state != MSCS_REGISTERED) - return; - - // cur_time is just a dummy data to send - WRITEUINT32(inbuffer, cur_time); - doomcom->datalength = sizeof (cur_time); - doomcom->remotenode = (INT16)msnode; - I_NetSend(); - } -*/ - -// Here, have a simpler MS Ping... - Cue - if(time(NULL) > (MSLastPing+(60*2)) && con_state != MSCS_NONE) - { - //CONS_Debug(DBG_NETPLAY, "%ld (current time) is greater than %d (Last Ping Time)\n", time(NULL), MSLastPing); - if(MSLastPing < 1) - AddToMasterServer(true); - else - AddToMasterServer(false); - } -} - -void SendAskInfoViaMS(INT32 node, tic_t asktime) -{ - // NET TODO -} - -void UnregisterServer(void) -{ - if (con_state != MSCS_REGISTERED) - { - con_state = MSCS_NONE; - CloseConnection(); - return; - } - - con_state = MSCS_NONE; - - CONS_Printf(M_GetText("Removing this server from the Master Server...\n")); - - if (MS_Connect(registered_server.ip, registered_server.port, 0)) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot connect to the Master Server\n")); - return; - } - - if (RemoveFromMasterSever() < 0) - CONS_Alert(CONS_ERROR, M_GetText("Cannot remove this server from the Master Server\n")); - - CloseConnection(); - MSCloseUDPSocket(); - MSLastPing = 0; -} - -void MasterClient_Ticker(void) -{ - if (server && ms_RoomId > 0) - SendPingToMasterServer(); -} - -static void ServerName_OnChange(void) -{ - UnregisterServer(); - RegisterServer(); -} - -static void MasterServer_OnChange(void) -{ - UnregisterServer(); - RegisterServer(); -} - -#ifndef NONET -// Like recv, but waits until we've got enough data to fill the buffer. -static size_t recvfull(SOCKET_TYPE s, char *buf, size_t len, int flags) -{ - /* Total received. */ - size_t totallen = 0; - - while(totallen < len) - { - ssize_t ret = (ssize_t)recv(s, buf + totallen, (int)(len - totallen), flags); - - /* Error. */ - if(ret == -1) - return (size_t)-1; - - totallen += ret; - } - - return totallen; -} -#endif diff --git a/src/mserv.h b/src/mserv.h deleted file mode 100644 index 32b227eab46781fa0c49b878ada3d1e1a36f5bb1..0000000000000000000000000000000000000000 --- a/src/mserv.h +++ /dev/null @@ -1,96 +0,0 @@ -// SONIC ROBO BLAST 2 -//----------------------------------------------------------------------------- -// Copyright (C) 1998-2000 by DooM Legacy Team. -// Copyright (C) 1999-2014 by Sonic Team Junior. -// -// This program is free software distributed under the -// terms of the GNU General Public License, version 2. -// See the 'LICENSE' file for more details. -//----------------------------------------------------------------------------- -/// \file mserv.h -/// \brief Header file for the master server routines - -#ifndef _MSERV_H_ -#define _MSERV_H_ - -#define MASTERSERVERS21 // MasterServer v2.1 - -// lowered from 32 due to menu changes -#define NUM_LIST_ROOMS 16 - -#if defined(_MSC_VER) -#pragma pack(1) -#endif - -typedef union -{ - char buffer[16]; // information such as password - UINT32 signature; -} ATTRPACK msg_header_t; - -// Keep this structure 8 bytes aligned (current size is 80) -typedef struct -{ - msg_header_t header; - char ip[16]; - char port[8]; - char name[32]; - INT32 room; - char version[8]; // format is: x.yy.z (like 1.30.2 or 1.31) -} ATTRPACK msg_server_t; - -typedef struct -{ - msg_header_t header; - INT32 id; - char name[32]; - char motd[255]; -} ATTRPACK msg_rooms_t; - -typedef struct -{ - msg_header_t header; - char ipstart[16]; - char ipend[16]; - char endstamp[32]; - char reason[255]; - INT32 hostonly; -} ATTRPACK msg_ban_t; - -#if defined(_MSC_VER) -#pragma pack() -#endif - -// ================================ GLOBALS =============================== - -extern consvar_t cv_masterserver, cv_servername; - -// < 0 to not connect (usually -1) (offline mode) -// == 0 to show all rooms, not a valid hosting room -// anything else is whatever room the MS assigns to that number (online mode) -INT16 ms_RoomId; - -const char *GetMasterServerPort(void); -const char *GetMasterServerIP(void); - -void MSOpenUDPSocket(void); -void MSCloseUDPSocket(void); - -void SendAskInfoViaMS(INT32 node, tic_t asktime); - -void RegisterServer(void); -void UnregisterServer(void); - -void MasterClient_Ticker(void); - -const msg_server_t *GetShortServersList(INT32 room); -INT32 GetRoomsList(boolean hosting); -#ifdef UPDATE_ALERT -const char *GetMODVersion(void); -void GetMODVersion_Console(void); -#endif -extern msg_rooms_t room_list[NUM_LIST_ROOMS+1]; - -void AddMServCommands(void); - -#endif diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index e1e8656990efb927879fdf571e63675d17f3a6e3..3304d50c3239ff01f9a543fcd20670283a506e1d 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2271,9 +2271,6 @@ void I_Quit(void) quiting = SDL_FALSE; I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. -#ifndef NONET - D_SaveBan(); // save the ban list -#endif G_SaveGameData(); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. @@ -2402,9 +2399,6 @@ void I_Error(const char *error, ...) I_ShutdownConsole(); M_SaveConfig(NULL); // save game config, cvars.. -#ifndef NONET - D_SaveBan(); // save the ban list -#endif G_SaveGameData(); // Tails 12-08-2002 // Shutdown. Here might be other errors. diff --git a/src/win32/win_sys.c b/src/win32/win_sys.c index efb0be463128feb1005f98a4d275c8e18b8b8d58..f9a9087b29b87083d672e345715e884a159906f7 100644 --- a/src/win32/win_sys.c +++ b/src/win32/win_sys.c @@ -657,9 +657,6 @@ void I_Error(const char *error, ...) if (!errorcount) { M_SaveConfig(NULL); // save game config, cvars.. -#ifndef NONET - D_SaveBan(); // save the ban list -#endif G_SaveGameData(); } @@ -757,9 +754,6 @@ void I_Quit(void) G_StopMetalRecording(); M_SaveConfig(NULL); // save game config, cvars.. -#ifndef NONET - D_SaveBan(); // save the ban list -#endif G_SaveGameData(); // maybe it needs that the ticcount continues,