Пример #1
0
        public override async ValueTask HandleMessageAsync(IMessageReader reader, MessageType messageType)
        {
            var flag = reader.Tag;

            Logger.Verbose("Server got {0}.", flag);

            switch (flag)
            {
            case MessageFlags.HostGame:
            {
                using var packet = MessageWriter.Get(MessageType.Reliable);
                Message13RedirectS2C.Serialize(packet, false, _nodeProvider.Get());
                await Connection.SendAsync(packet);

                break;
            }

            case MessageFlags.JoinGame:
            {
                Message01JoinGameC2S.Deserialize(
                    reader,
                    out var gameCode,
                    out _);

                using var packet = MessageWriter.Get(MessageType.Reliable);
                var endpoint = await _nodeLocator.FindAsync(GameCodeParser.IntToGameName(gameCode));

                if (endpoint == null)
                {
                    Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.GameMissing);
                }
                else
                {
                    Message13RedirectS2C.Serialize(packet, false, endpoint);
                }

                await Connection.SendAsync(packet);

                break;
            }

            case MessageFlags.GetGameListV2:
            {
                // TODO: Implement.
                using var packet = MessageWriter.Get(MessageType.Reliable);
                Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.Custom, DisconnectMessages.NotImplemented);
                await Connection.SendAsync(packet);

                break;
            }

            default:
            {
                Logger.Warning("Received unsupported message flag on the redirector ({0}).", flag);
                break;
            }
            }
        }
Пример #2
0
 public static async ValueTask <bool> ExistsAsync(this INodeLocator nodeLocator, string gameCode)
 {
     return(await nodeLocator.FindAsync(gameCode) != null);
 }