X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_nethandler.pas;h=4dc52a395c6152a05cd3c8cbc2581831b1ead811;hb=e2b934c614ee1cc235e632a368576804f8c4f2b4;hp=dadef20a3acf022e4716002a1c960bb2892eb757;hpb=69ed21bb4a9cd4c59ba1acfd5971c7be5f854ee2;p=d2df-sdl.git diff --git a/src/game/g_nethandler.pas b/src/game/g_nethandler.pas index dadef20..4dc52a3 100644 --- a/src/game/g_nethandler.pas +++ b/src/game/g_nethandler.pas @@ -2,8 +2,7 @@ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * the Free Software Foundation, version 3 of the License ONLY. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -39,55 +38,82 @@ procedure g_Net_Client_HandlePacket(P: pENetPacket; Handler: TNetClientMsgHandle var MNext: Integer; MSize: LongWord; - MHandled: Boolean; + MHandled: Boolean = false; NetMsg: TMsg; + Err: Boolean; begin if not NetMsg.Init(P^.data, P^.dataLength, True) then Exit; + Err := False; MNext := 0; - while NetMsg.BytesLeft() > 0 do + while (NetMsg.BytesLeft() > 0) and (not Err) do begin - MSize := NetMsg.ReadLongWord(); - MNext := NetMsg.ReadCount + MSize; - MHandled := Handler(NetMsg); // TODO: maybe do something with this bool - NetMsg.Seek(MNext); + try + MSize := NetMsg.ReadLongWord(); + MNext := NetMsg.ReadCount + MSize; + MHandled := Handler(NetMsg); // TODO: maybe do something with this bool + NetMsg.Seek(MNext); + except + Err := True; + end; end; + MHandled := not MHandled; //k8: stfu, fpc! + enet_packet_destroy(P); + //if Err then begin MC_MalformedPacket(S); Exit; end; end; procedure g_Net_Host_HandlePacket(S: pTNetClient; P: pENetPacket; Handler: TNetHostMsgHandler); var MNext: Integer; MSize: LongWord; - MHandled: Boolean; + MHandled: Boolean = false; NetMsg: TMsg; + Err: Boolean; begin if not NetMsg.Init(P^.data, P^.dataLength, True) then Exit; + Err := False; MNext := 0; - while NetMsg.BytesLeft() > 0 do + while (NetMsg.BytesLeft() > 0) and (not Err) do begin - MSize := NetMsg.ReadLongWord(); - MNext := NetMsg.ReadCount + MSize; - MHandled := Handler(S, NetMsg); // TODO: maybe do something with this bool - NetMsg.Seek(MNext); + try + MSize := NetMsg.ReadLongWord(); + MNext := NetMsg.ReadCount + MSize; + MHandled := Handler(S, NetMsg); // TODO: maybe do something with this bool + NetMsg.Seek(MNext); + except + Err := True; + end; end; + MHandled := not MHandled; //k8: stfu, fpc! + enet_packet_destroy(P); + if Err then begin MH_MalformedPacket(S); Exit; end; end; function g_Net_ClientMsgHandler(NetMsg: TMsg): Boolean; var MID: Byte; + Err: Boolean; begin Result := True; - MID := NetMsg.ReadByte(); + Err := False; + try + MID := NetMsg.ReadByte(); + except + MID := 0; + Err := True; + end; + + //if Err then begin MC_MalformedPacket(S); Exit; end; case MID of NET_MSG_CHAT: MC_RECV_Chat(NetMsg); @@ -98,6 +124,7 @@ begin NET_MSG_GEVENT: MC_RECV_GameEvent(NetMsg); NET_MSG_FLAG: MC_RECV_FlagEvent(NetMsg); NET_MSG_GSET: MC_RECV_GameSettings(NetMsg); + NET_MSG_FLAGPOS:MC_RECV_FlagPos(NetMsg); NET_MSG_PLR: MC_RECV_PlayerCreate(NetMsg); NET_MSG_PLRPOS: MC_RECV_PlayerPos(NetMsg); @@ -120,6 +147,7 @@ begin NET_MSG_ISPAWN: MC_RECV_ItemSpawn(NetMsg); NET_MSG_IDEL: MC_RECV_ItemDestroy(NetMsg); + NET_MSG_IPOS: MC_RECV_ItemPos(NetMsg); NET_MSG_PSTATE: MC_RECV_PanelState(NetMsg); NET_MSG_PTEX: MC_RECV_PanelTexture(NetMsg); @@ -141,9 +169,18 @@ end; function g_Net_ClientLightMsgHandler(NetMsg: TMsg): Boolean; var MID: Byte; + Err: Boolean; begin Result := True; - MID := NetMsg.ReadByte(); + Err := False; + try + MID := NetMsg.ReadByte(); + except + MID := 0; + Err := True; + end; + + //if Err then begin MC_MalformedPacket(S); Exit; end; case MID of NET_MSG_GEVENT: MC_RECV_GameEvent(NetMsg); @@ -159,10 +196,18 @@ end; function g_Net_HostMsgHandler(S: pTNetClient; NetMsg: TMsg): Boolean; var MID: Byte; + Err: Boolean; begin Result := True; - MID := NetMsg.ReadByte(); - g_Console_Add('MID = ' + IntTOStr(MID)); + Err := False; + try + MID := NetMsg.ReadByte(); + except + MID := 0; + Err := True; + end; + + if Err then begin MH_MalformedPacket(S); Exit; end; case MID of NET_MSG_INFO: MH_RECV_Info(S, NetMsg); @@ -176,8 +221,8 @@ begin NET_MSG_RCON_AUTH: MH_RECV_RCONPassword(S, NetMsg); NET_MSG_RCON_CMD: MH_RECV_RCONCommand(S, NetMsg); - NET_MSG_MAP_REQUEST: MH_RECV_MapRequest(S, NetMsg); - NET_MSG_RES_REQUEST: MH_RECV_ResRequest(S, NetMsg); + //NET_MSG_MAP_REQUEST: MH_RECV_MapRequest(S, NetMsg); + //NET_MSG_RES_REQUEST: MH_RECV_ResRequest(S, NetMsg); NET_MSG_VOTE_EVENT: MH_RECV_Vote(S, NetMsg); end;