Пример #1
0
        public static void Serialize(IMessageWriter writer, int skeldGameCount, int miraHqGameCount, int polusGameCount, IEnumerable <IGame> games)
        {
            writer.StartMessage(MessageFlags.GetGameListV2);

            // Count
            writer.StartMessage(1);
            writer.Write(skeldGameCount);  // The Skeld
            writer.Write(miraHqGameCount); // Mira HQ
            writer.Write(polusGameCount);  // Polus
            writer.EndMessage();

            // Listing
            writer.StartMessage(0);

            foreach (var game in games)
            {
                writer.StartMessage(0);
                writer.Write(game.PublicIp.Address);
                writer.Write((ushort)game.PublicIp.Port);
                writer.Write(game.Code);
                writer.Write(game.DisplayName ?? game.Host?.Client.Name ?? string.Empty);
                writer.Write((byte)game.PlayerCount);
                writer.WritePacked(1); // TODO: What does Age do?
                writer.Write((byte)game.Options.Map);
                writer.Write((byte)game.Options.NumImpostors);
                writer.Write((byte)game.Options.MaxPlayers);
                writer.EndMessage();
            }

            writer.EndMessage();
            writer.EndMessage();
        }
Пример #2
0
        internal ValueTask FinishRpcAsync(IMessageWriter writer, int?targetClientId = null)
        {
            writer.EndMessage();
            writer.EndMessage();

            return(targetClientId.HasValue
                ? SendToAsync(writer, targetClientId.Value)
                : SendToAllAsync(writer));
        }
Пример #3
0
 public static void Serialize(IMessageWriter writer, int id, string message)
 {
     writer.StartMessage(AnnouncementsMessageFlags.SetUpdate);
     writer.WritePacked(id);
     writer.Write(message);
     writer.EndMessage();
 }
Пример #4
0
        public static void Serialize(IMessageWriter writer, bool hasReason, DisconnectReason?reason, string?message)
        {
            writer.Write(hasReason);

            if (hasReason)
            {
                if (reason == null)
                {
                    throw new ArgumentNullException(nameof(reason));
                }

                writer.StartMessage(0);
                writer.Write((byte)reason);

                if (reason == DisconnectReason.Custom)
                {
                    if (message == null)
                    {
                        throw new ArgumentNullException(nameof(message));
                    }

                    writer.Write(message);
                }

                writer.EndMessage();
            }
        }
Пример #5
0
 public static void Serialize(IMessageWriter writer, string serverName, string serverVersion, int pluginCount)
 {
     writer.StartMessage(byte.MaxValue);
     writer.Write((byte)ReactorMessageFlags.Handshake);
     writer.Write(serverName);
     writer.Write(serverVersion);
     writer.WritePacked(pluginCount);
     writer.EndMessage();
 }
        public static void Serialize(IMessageWriter writer, bool clear, int gameCode, int playerId)
        {
            if (clear)
            {
                writer.Clear(MessageType.Reliable);
            }

            writer.StartMessage(MessageFlags.WaitForHost);
            writer.Write(gameCode);
            writer.Write(playerId);
            writer.EndMessage();
        }
Пример #7
0
        public static void Serialize(IMessageWriter writer, bool clear, IPEndPoint ipEndPoint)
        {
            if (clear)
            {
                writer.Clear(MessageType.Reliable);
            }

            writer.StartMessage(MessageFlags.Redirect);
            writer.Write(ipEndPoint.Address);
            writer.Write((ushort)ipEndPoint.Port);
            writer.EndMessage();
        }
        public static void Serialize(IMessageWriter writer, bool clear, int gameCode, int playerId, bool isBan)
        {
            if (clear)
            {
                writer.Clear(MessageType.Reliable);
            }

            writer.StartMessage(MessageFlags.KickPlayer);
            writer.Write(gameCode);
            writer.WritePacked(playerId);
            writer.Write(isBan);
            writer.EndMessage();
        }
Пример #9
0
        public static void Serialize(IMessageWriter writer, GameOptionsData gameOptionsData)
        {
            writer.StartMessage(MessageFlags.HostGame);

            using (var memory = new MemoryStream())
                using (var writerBin = new BinaryWriter(memory))
                {
                    gameOptionsData.Serialize(writerBin, GameOptionsData.LatestVersion);
                    writer.WriteBytesAndSize(memory.ToArray());
                }

            writer.EndMessage();
        }
Пример #10
0
        public static void Serialize(IMessageWriter writer, bool clear, int gameCode, bool isPublic)
        {
            if (clear)
            {
                writer.Clear(MessageType.Reliable);
            }

            writer.StartMessage(MessageFlags.AlterGame);
            writer.Write(gameCode);
            writer.Write((byte)AlterGameTags.ChangePrivacy);
            writer.Write(isPublic);
            writer.EndMessage();
        }
        public static void Serialize(IMessageWriter writer, bool clear, int gameCode, int playerId, int hostId, DisconnectReason reason)
        {
            // Only a subset of DisconnectReason shows an unique message.
            // ExitGame, Banned and Kicked.
            if (clear)
            {
                writer.Clear(MessageType.Reliable);
            }

            writer.StartMessage(MessageFlags.RemovePlayer);
            writer.Write(gameCode);
            writer.Write(playerId);
            writer.Write(hostId);
            writer.Write((byte)reason);
            writer.EndMessage();
        }
Пример #12
0
        public static void Serialize(IMessageWriter writer, bool clear, int gameCode, int playerId, int hostId, int[] otherPlayerIds)
        {
            if (clear)
            {
                writer.Clear(MessageType.Reliable);
            }

            writer.StartMessage(MessageFlags.JoinedGame);
            writer.Write(gameCode);
            writer.Write(playerId);
            writer.Write(hostId);
            writer.WritePacked(otherPlayerIds.Length);

            foreach (var id in otherPlayerIds)
            {
                writer.WritePacked(id);
            }

            writer.EndMessage();
        }
Пример #13
0
        public static void SerializeError(IMessageWriter writer, bool clear, DisconnectReason reason, string?message = null)
        {
            if (clear)
            {
                writer.Clear(MessageType.Reliable);
            }

            writer.StartMessage(MessageFlags.JoinGame);
            writer.Write((int)reason);

            if (reason == DisconnectReason.Custom)
            {
                if (message == null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                writer.Write(message);
            }

            writer.EndMessage();
        }
Пример #14
0
 public static void Serialize(IMessageWriter writer, int gameCode)
 {
     writer.StartMessage(MessageFlags.HostGame);
     writer.Write(gameCode);
     writer.EndMessage();
 }
Пример #15
0
 public static void Serialize(IMessageWriter writer, string serverBrand)
 {
     writer.StartMessage(byte.MaxValue);
     writer.Write(serverBrand);
     writer.EndMessage();
 }
Пример #16
0
 public static void Serialize(IMessageWriter writer, GameOptionsData gameOptionsData)
 {
     writer.StartMessage(MessageFlags.HostGame);
     gameOptionsData.Serialize(writer);
     writer.EndMessage();
 }
Пример #17
0
 public static void Serialize(IMessageWriter writer, FreeWeekendState state)
 {
     writer.StartMessage(AnnouncementsMessageFlags.SetFreeWeekend);
     writer.Write((byte)state);
     writer.EndMessage();
 }
Пример #18
0
 public static void Serialize(IMessageWriter writer)
 {
     writer.StartMessage(AnnouncementsMessageFlags.UseCache);
     writer.EndMessage();
 }