diff --git a/server/Entrypoint.cs b/server/Entrypoint.cs index 978cd56..389c788 100644 --- a/server/Entrypoint.cs +++ b/server/Entrypoint.cs @@ -13,7 +13,7 @@ namespace CircleScape { server.Start(); while(true) { - // physics and game logic processing loop + // logic processing loop } } } diff --git a/server/Kneesocks/Connection.cs b/server/Kneesocks/Connection.cs index 1b78da5..365b651 100644 --- a/server/Kneesocks/Connection.cs +++ b/server/Kneesocks/Connection.cs @@ -23,6 +23,8 @@ namespace Kneesocks { private TcpClient Socket; private NetworkStream Stream; + private string RawBuffer = ""; + private List FrameBuffer = new List(); public bool Disconnected { get; private set; } = false; public string DisconnectReason { get; private set; } = null; @@ -55,6 +57,14 @@ namespace Kneesocks { Headers = conn.Headers; } + public byte[] Parse() { + if(!Handshaked) { + + } else { + + } + } + public void Disconnect(string reason = null) { Disconnect(Frame.kClosingReason.Normal, reason); } diff --git a/server/Kneesocks/Pool.cs b/server/Kneesocks/Pool.cs index 5ce2472..71cce38 100644 --- a/server/Kneesocks/Pool.cs +++ b/server/Kneesocks/Pool.cs @@ -27,41 +27,49 @@ namespace Kneesocks { public int Tolerance { get; set; } = 0; private int _fullThreadCount; - private bool updateFullThreadCount = true; + private volatile bool updateFullThreadCount = true; private List Threads = new List(); - private UInt64 InternalCounter = 0; + private long InternalCounter = 0; private Dictionary Connections = new Dictionary(); public Pool() { for(var i = 0; i < InitialCount; ++i) - CreateThread(); + CreateThread(runWithNoClients: true); } private void IndexConnection(UInt64 id, Connection connection) { lock(Connections) { if(id == 0) - id = InternalCounter++; - + id = (ulong)Interlocked.Increment(ref InternalCounter); + connection.Id = id; Connections.Add(id, connection); } } + public void InvalidateConnection(UInt64 id) { + lock(Connections) { + Connections.Remove(id); + } + } + public bool AddConnection(Connection connection, UInt64 id = 0) { lock(Threads) { foreach(var thread in Threads) { if(thread.Stack.Count < FullThreadSize) { thread.Stack.AddClient(connection); + IndexConnection(id, connection); return true; } } if(MaxCount == 0 || Threads.Count < MaxCount) { CreateThread(connection); + IndexConnection(id, connection); return true; } } @@ -69,12 +77,6 @@ namespace Kneesocks { return false; } - public void InvalidateConnection(Connection connection) { - lock(Connections) { - - } - } - public void InvalidateThread(Stack stackRef) { lock(Threads) { var ctx = Threads.FirstOrDefault(x => Object.ReferenceEquals(x.Stack, stackRef)); diff --git a/server/Kneesocks/Stack.cs b/server/Kneesocks/Stack.cs index d8e9407..d9d7d65 100644 --- a/server/Kneesocks/Stack.cs +++ b/server/Kneesocks/Stack.cs @@ -53,7 +53,11 @@ namespace Kneesocks { while(Running && (Count > 0 || RunWithNoClients)) { for(var i = Count - 1; i >= 0 && Running; ++i) { var client = Clients[i]; - client + if(client.Handshaked) { + + } else { + + } } }