Пример #1
0
        public static async Task Main()
        {
            // ReSharper disable once CollectionNeverQueried.Local
            var clients = new List <MultiplayerClient>();

            for (int i = 1; i < 6; i++)
            {
                clients.Add(getConnectedClient(i));
            }

            while (true)
            {
                Console.WriteLine();

                foreach (var c in clients)
                {
                    Console.WriteLine($"Client {c.UserID} room: {c.Room} state: {c.State} beatmap: {c.BeatmapAvailability} mods: {string.Join(',', c.UserMods.Select(m => m.Acronym))}");
                }

                Console.WriteLine("Usage: <client_id> <command> [params]");
                Console.WriteLine("Valid commands [ JoinRoom LeaveRoom TransferHost ChangeSettings ChangeState ChangeBeatmapAvailability ChangeMods StartMatch ]");

                Console.Write(">");

                string?input = Console.ReadLine();

                try
                {
                    var pieces = input?.Split(' ');

                    if (pieces == null || pieces.Length < 2)
                    {
                        continue;
                    }

                    var args = pieces.Skip(2).ToArray();

                    MultiplayerClient targetClient = clients.First(c => c.UserID == int.Parse(pieces[0]));

                    switch (pieces[1].ToLower())
                    {
                    case "joinroom":
                        long roomId = long.Parse(args[0]);

                        if (args.Length > 1)
                        {
                            await targetClient.JoinRoomWithPassword(roomId, args[1]);
                        }
                        else
                        {
                            await targetClient.JoinRoom(roomId);
                        }
                        break;

                    case "leaveroom":
                        await targetClient.LeaveRoom();

                        break;

                    case "transferhost":
                        await targetClient.TransferHost(int.Parse(args[0]));

                        break;

                    case "changesettings":
                        await targetClient.ChangeSettings(new MultiplayerRoomSettings { BeatmapID = RNG.Next(0, 65536) });

                        break;

                    case "changestate":
                        await targetClient.ChangeState(Enum.Parse <MultiplayerUserState>(args[0], true));

                        break;

                    case "changebeatmapavailability":
                        switch (Enum.Parse <DownloadState>(args[0], true))
                        {
                        case DownloadState.NotDownloaded:
                            await targetClient.ChangeBeatmapAvailability(BeatmapAvailability.NotDownloaded());

                            break;

                        case DownloadState.Downloading:
                            await targetClient.ChangeBeatmapAvailability(BeatmapAvailability.Downloading(float.Parse(args[1])));

                            break;

                        case DownloadState.Importing:
                            await targetClient.ChangeBeatmapAvailability(BeatmapAvailability.Importing());

                            break;

                        case DownloadState.LocallyAvailable:
                            await targetClient.ChangeBeatmapAvailability(BeatmapAvailability.LocallyAvailable());

                            break;
                        }

                        break;

                    case "changemods":
                        var mods = new List <APIMod>();

                        for (int i = 0; i < args.Length; i++)
                        {
                            mods.Add(new APIMod {
                                Acronym = args[i]
                            });
                        }

                        await targetClient.ChangeUserMods(mods);

                        break;

                    case "startmatch":
                        await targetClient.StartMatch();

                        break;

                    default:
                        Console.WriteLine("Unknown command");
                        continue;
                    }
                }
                catch (HubException e)
                {
                    Console.WriteLine($"Server returned error: {e.Message}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error performing action: {e}");
                }

                Thread.Sleep(50);
                Console.WriteLine("Success!");
            }

            // ReSharper disable once FunctionNeverReturns
        }
Пример #2
0
        public static async Task Main()
        {
            // ReSharper disable once CollectionNeverQueried.Local
            var clients = new List <MultiplayerClient>();

            for (int i = 1; i < 6; i++)
            {
                clients.Add(getConnectedClient(i));
            }

            while (true)
            {
                Console.WriteLine();

                foreach (var c in clients)
                {
                    Console.WriteLine($"Client {c.UserID}  state: {c.State} room: {c.Room}");
                }

                Console.WriteLine("Usage: <client_id> <command> [params]");
                Console.WriteLine("Valid commands [ JoinRoom LeaveRoom TransferHost ChangeSettings ChangeState StartMatch ]");

                Console.Write(">");

                string input = Console.ReadLine();

                try
                {
                    var pieces = input.Split(' ');

                    if (pieces.Length < 2)
                    {
                        continue;
                    }

                    var args = pieces.Skip(2).ToArray();

                    MultiplayerClient targetClient = clients.First(c => c.UserID == int.Parse(pieces[0]));

                    switch (pieces[1].ToLower())
                    {
                    case "joinroom":
                        await targetClient.JoinRoom(long.Parse(args[0]));

                        break;

                    case "leaveroom":
                        await targetClient.LeaveRoom();

                        break;

                    case "transferhost":
                        await targetClient.TransferHost(int.Parse(args[0]));

                        break;

                    case "changesettings":
                        await targetClient.ChangeSettings(new MultiplayerRoomSettings { BeatmapID = RNG.Next(0, 65536) });

                        break;

                    case "changestate":
                        await targetClient.ChangeState(Enum.Parse <MultiplayerUserState>(args[0], true));

                        break;

                    case "startmatch":
                        await targetClient.StartMatch();

                        break;

                    default:
                        Console.WriteLine("Unknown command");
                        continue;
                    }
                }
                catch (HubException e)
                {
                    Console.WriteLine($"Server returned error: {e.Message}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error performing action: {e}");
                }

                Thread.Sleep(50);
                Console.WriteLine("Success!");
            }

            // ReSharper disable once FunctionNeverReturns
        }