private static void UpdateRoomHandler(ListServerHeader header, NetworkStream networkStream) { byte[] guidBytes = new byte[16]; networkStream.Read(guidBytes); Guid guid = guidBytes.ToGuid(); switch (header) { case ListServerHeader.UpdateName: byte[] size = new byte[4]; networkStream.Read(size); byte[] nameBuffer = new byte[size.ToI32()]; networkStream.Read(nameBuffer); if (RoomInfosByGuid.ContainsKey(guid)) { RoomInfo roomInfo = RoomInfosByGuid[guid]; roomInfo.Name = nameBuffer.ToName(); RoomInfosByGuid[guid] = roomInfo; } break; case ListServerHeader.UpdateCurrentPlayer: byte[] current = new byte[4]; networkStream.Read(current); if (RoomInfosByGuid.ContainsKey(guid)) { RoomInfo roomInfo = RoomInfosByGuid[guid]; roomInfo.CurrentPlayers = current.ToI32(); RoomInfosByGuid[guid] = roomInfo; } break; case ListServerHeader.UpdateMaxPlayer: byte[] max = new byte[4]; networkStream.Read(max); if (RoomInfosByGuid.ContainsKey(guid)) { RoomInfo roomInfo = RoomInfosByGuid[guid]; roomInfo.MaxPlayers = max.ToI32(); RoomInfosByGuid[guid] = roomInfo; } break; case ListServerHeader.UpdatePassword: byte[] flagBuffer = new byte[1]; networkStream.Read(flagBuffer); if (RoomInfosByGuid.ContainsKey(guid)) { RoomInfo roomInfo = RoomInfosByGuid[guid]; roomInfo.HasPassword = flagBuffer.ToBool(); RoomInfosByGuid[guid] = roomInfo; } break; default: break; } }
private static unsafe void HandleListServerHeader(TcpClient client, byte[] headerBuffer) { fixed(byte *pBytes = headerBuffer) { ListServerHeader header = *(ListServerHeader *)pBytes; if (Handlers.TryGetValue(header, out Action <TcpClient> handler)) { handler(client); AliveTick(client); } } }
private static void ScheduleSend(TcpClient client, ListServerHeader code) { SendQueue[client].Enqueue(code); }