diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ca33f1f7945eab8d6342ce3f958c599644ebd34b..df6ab2bc6b8918e2d632aa91573b81e7adb1f4a3 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -184,6 +184,26 @@ void RegisterNetXCmd(netxcmd_t id, void (*cmd_f)(UINT8 **p, INT32 playernum)) listnetxcmd[id] = cmd_f; } +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); +} + +// splitscreen player +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); +} + +UINT8 GetFreeXCmdSize(void) +{ + return -1; +} + // Frees all textcmd memory for the specified tic static void D_FreeTextcmd(void) { @@ -249,53 +269,6 @@ static UINT8* D_GetTextcmd(tic_t tic, INT32 playernum) return textcmdplayer->cmd; } -static void ExtraDataTicker(void) -{ - INT32 i; - - for (i = 0; i < MAXPLAYERS; i++) - if (playeringame[i] || i == 0) - { - UINT8 *bufferstart = D_GetExistingTextcmd(gametic, i); - - if (bufferstart) - { - UINT8 *curpos = bufferstart; - UINT8 *bufferend = &curpos[curpos[0]+1]; - - curpos++; - while (curpos < bufferend) - { - if (*curpos < MAXNETXCMD && listnetxcmd[*curpos]) - { - const UINT8 id = *curpos; - curpos++; - DEBFILE(va("executing x_cmd %u ply %u ", id, i)); - (listnetxcmd[id])(&curpos, i); - DEBFILE("done\n"); - } - else - { - if (server) - { - XBOXSTATIC UINT8 buf[3]; - - buf[0] = (UINT8)i; - buf[1] = KICK_MSG_XD_FAIL; - SendNetXCmd(XD_KICK, &buf, 2); - DEBFILE(va("player %d kicked [gametic=%u] reason as follows:\n", i, gametic)); - } - CONS_Alert(CONS_WARNING, M_GetText("Got unknown net command [%s]=%d (max %d)\n"), sizeu1(curpos - bufferstart), *curpos, bufferstart[0]); - D_FreeTextcmd(); - return; - } - } - } - } - - D_FreeTextcmd(); -} - static void D_Clearticcmd(void) { INT32 i; @@ -1084,29 +1057,13 @@ static void Command_connect(void) CONS_Printf(M_GetText("You cannot connect while in a game. End this game first.\n")); return; } - // NET TODO - /*else if (I_NetOpenSocket) + else { - MSCloseUDPSocket(); // Tidy up before wiping the slate. - I_NetOpenSocket(); - netgame = true; - multiplayer = true; - - if (!stricmp(COM_Argv(1), "any")) - servernode = BROADCASTADDR; - else if (I_NetMakeNodewPort && COM_Argc() >= 3) - servernode = I_NetMakeNodewPort(COM_Argv(1), COM_Argv(2)); - else if (I_NetMakeNodewPort) - servernode = I_NetMakeNode(COM_Argv(1)); + if (COM_Argc() >= 3) + D_NetConnect(COM_Argv(1), COM_Argv(2)); else - { - CONS_Alert(CONS_ERROR, M_GetText("There is no server identification with this network driver\n")); - D_CloseConnection(); - return; - } - }*/ - else - CONS_Alert(CONS_ERROR, M_GetText("There is no network driver\n")); + D_NetConnect(COM_Argv(1), NULL); + } } splitscreen = false; @@ -1905,9 +1862,7 @@ boolean SV_SpawnServer(void) SV_ResetServer(); SV_GenContext(); if (netgame) - { - // NET TODO: Open network socket, register to masterserver, etc. - } + D_NetOpen(); // non dedicated server just connect to itself if (!dedicated) @@ -2019,7 +1974,6 @@ void TryRunTics(tic_t realtics) DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic)); G_Ticker((gametic % NEWTICRATERATIO) == 0); - ExtraDataTicker(); gametic++; } } diff --git a/src/d_enet.c b/src/d_enet.c index 8e1fc79e9a0201eb3d0ffa554c4c102bcc1e6630..5db2b8ffc88eb9f4ef0ef0f991fbe98a2c741512 100644 --- a/src/d_enet.c +++ b/src/d_enet.c @@ -38,7 +38,7 @@ void Net_AckTicker(void) UINT8 i; PeerData_t *pdata; - while (enet_host_service(ClientHost, &e, 0) > 0) + while (ClientHost && enet_host_service(ClientHost, &e, 0) > 0) switch (e.type) { case ENET_EVENT_TYPE_CONNECT: @@ -60,7 +60,8 @@ void Net_AckTicker(void) default: break; } - while (enet_host_service(ServerHost, &e, 0) > 0) + + while (ServerHost && enet_host_service(ServerHost, &e, 0) > 0) switch (e.type) { case ENET_EVENT_TYPE_CONNECT: @@ -111,6 +112,45 @@ void D_SetDoomcom(void) net_playercount = 0; } +void D_NetOpen(void) +{ + ENetAddress address = { ENET_HOST_ANY, 5029 }; + ServerHost = enet_host_create(&address, MAXNETNODES, NETCHANNELS, 0, 0); + if (!ServerHost) + I_Error("ENet failed to open server host. (Check if the port is in use?)"); + servernode = 0; +} + +void D_NetConnect(const char *hostname, const char *port) +{ + ENetAddress address; + ENetEvent e; + + ClientHost = enet_host_create(NULL, 1, NETCHANNELS, 0, 0); + if (!ClientHost) + I_Error("ENet failed to initialize client host."); + + netgame = multiplayer = true; + servernode = 1; + + enet_address_set_host(&address, hostname); + address.port = 5029; + if (port != NULL) + address.port = atoi(port) || address.port; + + nodetopeer[servernode] = enet_host_connect(ClientHost, &address, NETCHANNELS, 0); + if (!nodetopeer[servernode]) + I_Error("Failed to allocate ENet peer for connecting ???"); + + if (enet_host_service(ClientHost, &e, 5000) > 0 + && e.type == ENET_EVENT_TYPE_CONNECT) + { + CONS_Printf("Connection successful!"); + return; + } + M_StartMessage(M_GetText("Failed to connect to server.\n\nPress ESC\n"), NULL, MM_NOTHING); +} + // Initialize network. // Returns true if the server is booting up right into a level according to startup args and whatnot. // netgame is set to true before this is called if -server was passed. @@ -121,19 +161,9 @@ boolean D_CheckNetGame(void) if (netgame) { if (server) - { - ENetAddress address = { ENET_HOST_ANY, 5029 }; - ServerHost = enet_host_create(&address, MAXNETNODES, NETCHANNELS, 0, 0); - if (!ServerHost) - I_Error("ENet failed to open server host. (Check if the port is in use?)"); - } - if (!dedicated) - { - ClientHost = enet_host_create(NULL, 1, NETCHANNELS, 0, 0); - if (!ClientHost) - I_Error("ENet failed to initialize client host."); - } - } else + D_NetOpen(); + } + else server = true; multiplayer = netgame; D_ClientServerInit(); @@ -215,17 +245,3 @@ void Net_SendAcks(INT32 node) void Net_WaitAllAckReceived(UINT32 timeout) { } - -void SendNetXCmd(netxcmd_t id, const void *param, size_t nparam) -{ -} - -// splitscreen player -void SendNetXCmd2(netxcmd_t id, const void *param, size_t nparam) -{ -} - -UINT8 GetFreeXCmdSize(void) -{ - return -1; -}