Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
 private static void ScheduleSend(TcpClient client, ListServerHeader code)
 {
     SendQueue[client].Enqueue(code);
 }