summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7bafa6e)
raw | patch | inline | side by side (parent: 7bafa6e)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sat, 12 Oct 2019 02:29:16 +0000 (05:29 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sat, 12 Oct 2019 15:54:12 +0000 (18:54 +0300) |
src/game/g_net.pas | patch | blob | history | |
src/game/g_netmsg.pas | patch | blob | history |
diff --git a/src/game/g_net.pas b/src/game/g_net.pas
index 7dcffd78c8c27caf1eb32bc59cd80e2db2057eea..8f8488f904fad54e4e014f62db6a1afd15de329c 100644 (file)
--- a/src/game/g_net.pas
+++ b/src/game/g_net.pas
e_KeyPressed(JOY3_JUMP)
end;
-{
-function g_Net_Wait_Event(msgId: Word): TMemoryStream;
- var
- ev: ENetEvent;
- rMsgId: Byte;
- Ptr: Pointer;
- stream: TMemoryStream;
- status: cint;
-begin
- FillChar(ev, SizeOf(ev), 0);
- stream := nil;
- repeat
- status := enet_host_service(NetHost, @ev, Trunc(g_Net_DownloadTimeout * 1000));
- if status > 0 then
- begin
- case ev.kind of
- ENET_EVENT_TYPE_RECEIVE:
- begin
- Ptr := ev.packet^.data;
- rMsgId := Byte(Ptr^);
- if rMsgId = msgId then
- begin
- stream := TMemoryStream.Create;
- stream.SetSize(ev.packet^.dataLength);
- stream.WriteBuffer(Ptr^, ev.packet^.dataLength);
- stream.Seek(0, soFromBeginning);
- status := 1 (* received *)
- end
- else
- begin
- (* looks that game state always received, so ignore it *)
- e_LogWritefln('g_Net_Wait_Event(%s): skip message %s', [msgId, rMsgId]);
- status := 2 (* continue *)
- end
- end;
- ENET_EVENT_TYPE_DISCONNECT:
- begin
- if (ev.data <= NET_DISC_MAX) then
- g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' + _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + ev.data)], True);
- status := -2 (* error: disconnected *)
- end;
- else
- g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' unknown ENet event ' + IntToStr(Ord(ev.kind)), True);
- status := -3 (* error: unknown event *)
- end;
- enet_packet_destroy(ev.packet)
- end
- else
- begin
- g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' timeout reached', True);
- status := 0 (* error: timeout *)
- end;
- ProcessLoading(true);
- until (status <> 2) or g_Net_UserRequestExit();
- Result := stream
-end;
-}
-
function getNewTimeoutEnd (): Int64;
begin
diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas
index bd32f68095a8d15b13a788babc2188afc70dee20..ddef35df216b9f645023eef3ab3d511aee45fe38 100644 (file)
--- a/src/game/g_netmsg.pas
+++ b/src/game/g_netmsg.pas
function IsValidFileName(const S: String): Boolean;
function IsValidFilePath(const S: String): Boolean;
+
implementation
uses
//kDirPrev: TDirection = D_LEFT;
//HostGameTime: Word = 0;
+
+function IsValidFileName(const S: String): Boolean;
+const
+ Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
+var
+ I: Integer;
+begin
+ Result := S <> '';
+ for I := 1 to Length(S) do
+ Result := Result and (not(S[I] in Forbidden));
+end;
+
+function IsValidFilePath(const S: String): Boolean;
+var
+ I: Integer;
+begin
+ Result := False;
+ if not IsValidFileName(S) then exit;
+ if FileExists(S) then exit;
+ I := LastDelimiter('\/', S);
+ if (I > 0) then
+ if (not DirectoryExists(Copy(S, 1, I-1))) then
+ exit;
+ Result := True;
+end;
+
+
// HOST MESSAGES //
g_Net_Client_Send(True, NET_CHAN_SERVICE);
end;
-// i have no idea why all this stuff is in here
-
-function ReadFile(const FileName: TFileName): AByte;
-var
- FileStream : TStream;
- fname: string;
-begin
- e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), TMsgType.Notify);
- fname := findDiskWad(FileName);
- if length(fname) = 0 then
- begin
- e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), TMsgType.Fatal);
- SetLength(Result, 0);
- exit;
- end;
- e_WriteLog(Format('NETWORK: found file "%s"', [fname]), TMsgType.Notify);
- Result := nil;
- FileStream := openDiskFileRO(fname);
- try
- if FileStream.Size > 0 then
- begin
- SetLength(Result, FileStream.Size);
- FileStream.Read(Result[0], FileStream.Size);
- end;
- finally
- FileStream.Free;
- end;
-end;
-
-{
-function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
-var
- i: Integer;
-begin
- Result.MsgId := NET_MSG_MAP_RESPONSE;
- Result.FileData := ReadFile(FileName);
- Result.FileSize := Length(Result.FileData);
-
- SetLength(Result.ExternalResources, ResList.Count);
- for i:=0 to ResList.Count-1 do
- begin
- Result.ExternalResources[i].Name := ResList.Strings[i];
- Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
- end;
-end;
-
-procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
-var
- ResultStream: TMemoryStream;
-begin
- ResultStream := TMemoryStream.Create;
-
- ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
- ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
- ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
-
- SetLength(bytes, ResultStream.Size);
- ResultStream.Seek(0, soFromBeginning);
- ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
-
- ResultStream.Free;
-end;
-
-function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
-begin
- msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
- msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
- SetLength(Result.FileData, Result.FileSize);
- msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
-end;
-
-procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
-var
- ResultStream: TMemoryStream;
- resCount: Integer;
-begin
- resCount := Length(MapDataMsg.ExternalResources);
-
- ResultStream := TMemoryStream.Create;
-
- ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
- ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
- ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
-
- ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
- ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
-
- SetLength(bytes, ResultStream.Size);
- ResultStream.Seek(0, soFromBeginning);
- ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
-
- ResultStream.Free;
-end;
-
-function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
-var
- resCount: Integer;
-begin
- msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
- msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
-
- SetLength(Result.FileData, Result.FileSize);
- msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
-
- msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
- SetLength(Result.ExternalResources, resCount);
-
- msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
-end;
-}
-
-function IsValidFileName(const S: String): Boolean;
-const
- Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
-var
- I: Integer;
-begin
- Result := S <> '';
- for I := 1 to Length(S) do
- Result := Result and (not(S[I] in Forbidden));
-end;
-
-function IsValidFilePath(const S: String): Boolean;
-var
- I: Integer;
-begin
- Result := False;
- if not IsValidFileName(S) then exit;
- if FileExists(S) then exit;
- I := LastDelimiter('\/', S);
- if (I > 0) then
- if (not DirectoryExists(Copy(S, 1, I-1))) then
- exit;
- Result := True;
-end;
-
-{
-procedure MC_SEND_MapRequest();
-begin
- NetOut.Write(Byte(NET_MSG_MAP_REQUEST));
- g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
-end;
-
-procedure MC_SEND_ResRequest(const resName: AnsiString);
-begin
- NetOut.Write(Byte(NET_MSG_RES_REQUEST));
- NetOut.Write(resName);
- g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
-end;
-
-procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
-var
- peer: pENetPeer;
- payload: AByte;
- mapDataMsg: TMapDataMsg;
-begin
- e_WriteLog('NET: Received map request from ' +
- DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
-
- mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
- peer := NetClients[C^.ID].Peer;
-
- MapDataMsgToBytes(payload, mapDataMsg);
- g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
-
- payload := nil;
- mapDataMsg.FileData := nil;
- mapDataMsg.ExternalResources := nil;
-end;
-
-procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
-var
- payload: AByte;
- peer: pENetPeer;
- FileName: String;
- resDataMsg: TResDataMsg;
-begin
- FileName := ExtractFileName(M.ReadString());
- e_WriteLog('NET: Received res request: ' + FileName +
- ' from ' + DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
-
- if not IsValidFilePath(FileName) then
- begin
- e_WriteLog('Invalid filename: ' + FileName, TMsgType.Warning);
- exit;
- end;
-
- peer := NetClients[C^.ID].Peer;
-
- if gExternalResources.IndexOf(FileName) > -1 then
- begin
- resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
- resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
- resDataMsg.FileSize := Length(resDataMsg.FileData);
-
- ResDataMsgToBytes(payload, resDataMsg);
- g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
- end;
-end;
-}
-
end.