Changeset 499
- Timestamp:
- Jul 23, 2024, 6:49:56 PM (5 months ago)
- Location:
- TFP-WebServer
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/CommandExtensions/ModInfo.xml
r487 r499 5 5 <Description value="Additional commands for server operation" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="1.1.0. 0" />7 <Version value="1.1.0.1" /> 8 8 <Website value="" /> 9 9 </xml> -
TFP-WebServer/CommandExtensions/src/ChatHelpers.cs
r485 r499 10 10 } 11 11 12 _receiver.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, _message, 13 $"{senderName} (PM)", null)); 12 _receiver.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, 13 $"{senderName} (PM): {_message}", null, 14 EMessageSender.None)); 14 15 string receiverName = _receiver.playerName; 15 16 receiverName = receiverName != null ? $"\"{receiverName}\"" : "unknownName"; -
TFP-WebServer/CommandExtensions/src/Commands/Give.cs
r487 r499 51 51 } 52 52 53 int quality = Constants.cItemMaxQuality;53 ushort quality = Constants.cItemMaxQuality; 54 54 55 55 if (_params.Count == 4) { 56 if (! int.TryParse (_params [3], out quality) || quality <= 0) {56 if (!ushort.TryParse (_params [3], out quality) || quality > Constants.cItemMaxQuality) { 57 57 SdtdConsole.Instance.Output ("Quality is not an integer or not greater than zero."); 58 58 return; -
TFP-WebServer/WebServer/ModInfo.xml
r490 r499 5 5 <Description value="Integrated Webserver for the Web Dashboard and server APIs" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="1.1.0. 2" />7 <Version value="1.1.0.3" /> 8 8 <Website value="" /> 9 9 </xml> -
TFP-WebServer/WebServer/src/SSE/AbsEvent.cs
r487 r499 36 36 37 37 openClients.Add (_client); 38 39 logConnectionState ("Connection opened", _client); 38 40 } 39 41 … … 64 66 bytesToSend = Encoding.UTF8.GetBytes (output, 0, output.Length, buf, 0); 65 67 } catch (ArgumentException e) { 66 logError ("Exception while encoding data for output, most likely exceeding buffer size:", false);68 Log.Error ($"[Web] [SSE] '{Name}': Exception while encoding data for output, most likely exceeding buffer size:"); 67 69 Log.Exception (e); 68 70 return; … … 79 81 private void sendBufToListeners (byte[] _bytes, int _bytesToSend) { 80 82 for (int i = openClients.Count - 1; i >= 0; i--) { 81 ESseClientWriteResult writeResult = openClients [i].Write (_bytes, _bytesToSend); 82 if (writeResult == ESseClientWriteResult.Ok) { 83 continue; 84 } 85 86 currentlyOpen--; 87 totalClosed++; 88 89 if (writeResult == ESseClientWriteResult.Error) { 90 logError ("Can not write to endpoint, closing", true); 91 } 83 openClients [i].Write (_bytes, _bytesToSend); 92 84 } 93 }94 95 protected void logError (string _message, bool _printConnections) {96 Log.Error (_printConnections97 ? $"[Web] [SSE] '{Name}': {_message} (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed})"98 : $"[Web] [SSE] '{Name}': {_message}");99 85 } 100 86 101 87 public virtual int DefaultPermissionLevel () => 0; 102 88 89 private void logConnectionState (string _message, SseClient _client) { 90 Log.Out ($"[Web] [SSE] '{Name}': {_message} from {_client.RemoteEndpoint} (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed})"); 91 } 92 103 93 public void ClientClosed (SseClient _client) { 104 openClients.Remove (_client); 94 if (openClients.Remove (_client)) { 95 currentlyOpen--; 96 totalClosed++; 97 98 logConnectionState ("Closed connection", _client); 99 } 105 100 } 106 101 } -
TFP-WebServer/WebServer/src/SSE/SseClient.cs
r487 r499 1 1 using System; 2 2 using System.IO; 3 using System.Net; 3 4 using System.Net.Sockets; 4 5 using System.Text; 5 using SpaceWizards.HttpListener;6 6 using Webserver.UrlHandlers; 7 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse; 7 8 8 9 namespace Webserver.SSE { … … 17 18 private static readonly byte[] keepAliveData = Encoding.UTF8.GetBytes (": KeepAlive\n\n"); 18 19 20 public readonly IPEndPoint RemoteEndpoint; 19 21 private readonly SseHandler parent; 20 22 private readonly HttpListenerResponse response; 21 23 private DateTime lastMessageSent = DateTime.Now; 22 24 23 public SseClient (SseHandler _parent, HttpListenerResponse _response) {25 public SseClient (SseHandler _parent, RequestContext _context) { 24 26 parent = _parent; 25 response = _response; 27 response = _context.Response; 28 RemoteEndpoint = _context.Request.RemoteEndPoint; 26 29 27 30 // Keep the request open 28 _response.SendChunked = true;31 response.SendChunked = true; 29 32 30 _response.AddHeader ("Content-Type", "text/event-stream");31 _response.OutputStream.Flush ();33 response.AddHeader ("Content-Type", "text/event-stream"); 34 response.OutputStream.Flush (); 32 35 } 33 36 -
TFP-WebServer/WebServer/src/UrlHandlers/SseHandler.cs
r487 r499 68 68 SseClient client; 69 69 try { 70 client = new SseClient(this, _context .Response);70 client = new SseClient(this, _context); 71 71 } catch (Exception e) { 72 72 Log.Error ($"[Web] [SSE] In {nameof (SseHandler)}.HandleRequest(): Could not create client:"); -
TFP-WebServer/bin/Mods/TFP_CommandExtensions/ModInfo.xml
r487 r499 5 5 <Description value="Additional commands for server operation" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="1.1.0. 0" />7 <Version value="1.1.0.1" /> 8 8 <Website value="" /> 9 9 </xml> -
TFP-WebServer/bin/Mods/TFP_WebServer/ModInfo.xml
r490 r499 5 5 <Description value="Integrated Webserver for the Web Dashboard and server APIs" /> 6 6 <Author value="The Fun Pimps LLC" /> 7 <Version value="1.1.0. 2" />7 <Version value="1.1.0.3" /> 8 8 <Website value="" /> 9 9 </xml>
Note:
See TracChangeset
for help on using the changeset viewer.