-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update deps
- Loading branch information
Showing
10 changed files
with
128 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#if CLIENT || GAME | ||
|
||
namespace ExtractIntoVoid.Client; | ||
|
||
public class ChatWebSocket | ||
{ | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#if CLIENT || GAME | ||
using EIV_JsonLib.Lobby; | ||
using System.Buffers; | ||
using System.Collections.Generic; | ||
using System.Net.WebSockets; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading; | ||
|
||
namespace ExtractIntoVoid.Client; | ||
|
||
public class UserWebSocket | ||
{ | ||
ClientWebSocket webSocket = new(); | ||
private static UserWebSocket instance; | ||
public static UserWebSocket Instance | ||
{ | ||
get | ||
{ | ||
if (instance == null) | ||
instance = new(); | ||
return instance; | ||
} | ||
} | ||
|
||
public Queue<ClientSocketMessage> MessageQueue = new(); | ||
|
||
public void Connect(string ip_port, string guid, string ticket) | ||
{ | ||
webSocket.Options.SetRequestHeader("authorization", ticket); | ||
webSocket.ConnectAsync(new($"ws://{ip_port}/Socket/Client/{guid}"), CancellationToken.None); | ||
} | ||
|
||
public void Send(ClientSocketMessage clientSocketMessage) | ||
{ | ||
if (webSocket.State != WebSocketState.Open) | ||
return; | ||
webSocket.SendAsync(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(clientSocketMessage)), WebSocketMessageType.Binary, false, CancellationToken.None); | ||
} | ||
|
||
public ClientSocketMessage SendAndReceive(ClientSocketMessage clientSocketMessage) | ||
{ | ||
Send(clientSocketMessage); | ||
byte[] bytes = ArrayPool<byte>.Shared.Rent(2048); | ||
var res = webSocket.ReceiveAsync(bytes, CancellationToken.None).Result; | ||
if (res.MessageType == WebSocketMessageType.Close) | ||
return null; | ||
ClientSocketMessage resp = JsonSerializer.Deserialize<ClientSocketMessage>(Encoding.UTF8.GetString(bytes, 0, res.Count)); | ||
ArrayPool<byte>.Shared.Return(bytes); | ||
return resp; | ||
} | ||
|
||
|
||
public void Receive() | ||
{ | ||
byte[] bytes = ArrayPool<byte>.Shared.Rent(2048); | ||
var res = webSocket.ReceiveAsync(bytes, CancellationToken.None).Result; | ||
if (res.MessageType == WebSocketMessageType.Close) | ||
return; | ||
MessageQueue.Enqueue(JsonSerializer.Deserialize<ClientSocketMessage>(Encoding.UTF8.GetString(bytes, 0, res.Count))); | ||
ArrayPool<byte>.Shared.Return(bytes); | ||
} | ||
|
||
public void Quit() | ||
{ | ||
MessageQueue.Clear(); | ||
webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None); | ||
webSocket.Dispose(); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
update-deps | ||
2024-12-16T16:25:44 | ||
8746db9 | ||
2024-12-25T22:36:42 | ||
cf994be |