From bb38e9c12ab24f1599fe037486eb600deeef2b74 Mon Sep 17 00:00:00 2001 From: Yukita Mayako Date: Sun, 13 Mar 2016 15:12:27 -0400 Subject: [PATCH] Server should force clients back if they clip into something, instead of crushing them. --- src/d_enet.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/d_enet.c b/src/d_enet.c index dc59c183a..07662b043 100644 --- a/src/d_enet.c +++ b/src/d_enet.c @@ -30,6 +30,7 @@ static tic_t lastMove; static ticcmd_t lastCmd; static UINT16 *removelist, removecount; + enum { CHANNEL_GENERAL = 0, CHANNEL_CHAT, @@ -56,7 +57,8 @@ enum { SERVER_REMOVE_LIST, SERVER_MOVE, SERVER_PLAYER_DAMAGE, - SERVER_PLAYER_RINGS + SERVER_PLAYER_RINGS, + SERVER_FORCE_MOVE }; static ENetHost *ServerHost = NULL, @@ -89,6 +91,7 @@ void Net_ServerMessage(const char *fmt, ...); static void ServerSendMapInfo(UINT8 node); static void Net_MovePlayers(void); static void Net_SendRemoveList(UINT8 node); +static void Net_ForceMove(player_t *player); void Net_GetNetStat(UINT8 node, UINT32 *ping, UINT32 *packetLoss) { @@ -184,6 +187,7 @@ static void ServerHandlePacket(UINT8 node, DataWrap data) { player_t *player; GhostData ghost; + fixed_t oldz; ghost.cmd.forwardmove = DW_ReadSINT8(data); ghost.cmd.sidemove = DW_ReadSINT8(data); @@ -206,9 +210,14 @@ static void ServerHandlePacket(UINT8 node, DataWrap data) player->cmd.angleturn = ghost.cmd.angleturn; player->cmd.aiming = ghost.cmd.aiming; player->cmd.buttons = ghost.cmd.buttons; - P_MapStart(); - P_TeleportMove(player->mo, ghost.x, ghost.y, ghost.z); - P_MapEnd(); + oldz = player->mo->z; + player->mo->z = ghost.z; + if (!P_TryMove(player->mo, ghost.x, ghost.y, true)) + { + player->mo->z = oldz; + Net_ForceMove(player); + } + P_SetTarget(&tmthing, NULL); break; } @@ -408,6 +417,16 @@ static void ClientHandlePacket(UINT8 node, DataWrap data) players[consoleplayer].mo->health = players[consoleplayer].health; break; + case SERVER_FORCE_MOVE: + { + const fixed_t x = DW_ReadFixed(data), + y = DW_ReadFixed(data), + z = DW_ReadFixed(data); + P_TeleportMove(players[consoleplayer].mo, x, y, z); + P_SetTarget(&tmthing, NULL); + break; + } + default: CONS_Printf("NETWORK: Unknown message type recieved from node %u!\n", node); break; @@ -1019,3 +1038,19 @@ static void Net_SendRemoveList(UINT8 node) enet_peer_send(nodetopeer[node], CHANNEL_GENERAL, packet); } +static void Net_ForceMove(player_t *player) +{ + ENetPacket *packet; + UINT8 *buf = net_buffer; + + if (!netgame || !server) + return; + + WRITEUINT8(buf, SERVER_FORCE_MOVE); + WRITEFIXED(buf, player->mo->x); + WRITEFIXED(buf, player->mo->y); + WRITEFIXED(buf, player->mo->z); + + packet = enet_packet_create(net_buffer, buf-net_buffer, ENET_PACKET_FLAG_RELIABLE); + enet_peer_send(nodetopeer[playernode[player-players]], CHANNEL_GENERAL, packet); +}