コード例 #1
0
        public override async Task ProcessAsync(IMessageBroadcaster broadcaster, ICommand cmd)
        {
            if (!await this.game.ProcessAsync(Settings.UNITY_SERVER_PORT))
            {
                broadcaster.Broadcast(Localization.GAME_NOT_STARTED);
                return;
            }

            // --- PLayers only ---
            //!arena leave
            //!arena, !arena join

            // --- Broadcaster Only ---
            //!arena start,begin
            //!arena cancel,cancel
            //!arena kick <player>
            //!arena add <player>

            var command = cmd.Arguments?.Trim().ToLower();
            var player  = playerProvider.Get(cmd.Sender);

            if (string.IsNullOrEmpty(command) || command.Equals("join"))
            {
                await game.JoinArenaAsync(player);
            }
            else if (command.Equals("leave"))
            {
                await game.LeaveArenaAsync(player);
            }
            else if (command.Equals("start") || command.Equals("begin"))
            {
                if (!cmd.Sender.IsBroadcaster && !cmd.Sender.IsModerator)
                {
                    broadcaster.Send(cmd.Sender.Username, "You do not have permission to force start the arena.");
                    //broadcaster.Broadcast("You do not have permission to force start the arena.");
                    return;
                }

                await game.StartArenaAsync(player);
            }
            else if (command.Equals("cancel") || command.Equals("end"))
            {
                if (!cmd.Sender.IsBroadcaster && !cmd.Sender.IsModerator)
                {
                    //broadcaster.Broadcast(
                    broadcaster.Send(cmd.Sender.Username,
                                     "You do not have permission to cancel the arena.");
                    return;
                }

                await game.CancelArenaAsync(player);
            }
            else
            {
                var targetPlayerName = command.Split(' ').LastOrDefault();
                if (command.StartsWith("kick "))
                {
                    if (!cmd.Sender.IsBroadcaster && !cmd.Sender.IsModerator)
                    {
                        //broadcaster.Broadcast(
                        broadcaster.Send(cmd.Sender.Username,
                                         "You do not have permission to kick a player from the arena.");
                        return;
                    }

                    var targetPlayer = playerProvider.Get(cmd.Sender);
                    await game.KickPlayerFromArenaAsync(player, targetPlayer);
                }
                else if (command.StartsWith("add "))
                {
                    if (!cmd.Sender.IsBroadcaster && !cmd.Sender.IsModerator)
                    {
                        //broadcaster.Broadcast(
                        broadcaster.Send(cmd.Sender.Username,
                                         "You do not have permission to add a player to the arena.");
                        return;
                    }

                    var targetPlayer = playerProvider.Get(cmd.Sender);
                    await game.AddPlayerToArenaAsync(player, targetPlayer);
                }
            }
        }