Ejemplo n.º 1
0
        private static void OnCommand()
        {
            List <string> command = Util.FetchString(Console.ReadLine(), " ");

            switch (command[0])
            {
            case "/send":     // send all msg || send id msg || send username msg
                if (command.Count < 3)
                {
                    Console.WriteLine("Invalid Syntax!");
                    break;
                }
                SendMessage(command);
                break;

            case "/create":     // create username password
                if (command.Count < 4)
                {
                    Console.WriteLine("Invalid Syntax!");
                    break;
                }
                if (command[1] == "account")
                {
                    Account.CreateAccount(command[2], command[3]);
                }
                if (command[1] == "character" && command.Count == 5)
                {
                    Console.WriteLine(Character.CreateCharacter(command[2], command[3], command[4]));
                }
                else
                {
                    Console.WriteLine("Invalid Syntax! Usage: /create character <username> <charName> <charClass>");
                }
                break;

            case "/delete":
                if (command[1] == "character" && command.Count == 4)
                {
                    Console.WriteLine(Character.DeleteCharacter(command[2], Convert.ToInt32(command[3])));
                }
                else
                {
                    Console.WriteLine("Invalid Syntax! Usage: /delete character <username> <charindex>");
                }
                break;

            case "/clear":
                Console.Clear();
                break;

            default:
                Console.WriteLine("Unknown Command: " + command[0]);
                break;
            }
            OnCommand();
        }
Ejemplo n.º 2
0
        private static void ParsePlayerMessage(Player player, string message)
        {
            Console.WriteLine("Player " + player.ID + ": " + message);
            if (player.Username == null)
            {
                List <string> request = Util.FetchString(message, ":");
                if (request.Count < 3)
                {
                    KickPlayer(player, "Invalid Request!");
                    return;
                }
                request[1] = Util.MakeStringCooler(request[1]); // adMiN -> Admin
                switch (request[0])
                {
                case "Login":
                    if (Account.GetAccount(request[1], request[2]) == "Success!")
                    {
                        if (Player.IsPlayerAlreadyInGame(request[1]))     // If Player Is Already In The Game Then Dont Let New Player Join The Game.
                        {
                            KickPlayer(player, "Disconnected! You are already in the Game!");
                            break;
                        }
                        Console.WriteLine(request[1] + " Has Logged In! [Player " + player.ID + "]");
                        SendMessage(player, "*Welcome");
                        player.Username = request[1];
                        player.Password = request[2];
                    }
                    else
                    {
                        KickPlayer(player, "Account Not Found Or Wrong Password");
                    }
                    break;

                case "Register":
                    if (Account.CreateAccount(request[1], request[2]))
                    {
                        SendMessage(player, "Account Created!");
                    }
                    else
                    {
                        KickPlayer(player, "Account Exists!");
                    }
                    break;
                }
                return;
            }

            if (message.Substring(0, 1) == "/")
            {
                List <string> request = Util.FetchString(message.Substring(1, message.Length - 1), " ");
                switch (request[0])
                {
                case "hi":
                    SendMessage(player, "Hey!");
                    break;

                case "commands":
                    SendMessage(player, "/Hi and /Commands are Current At The Moment.");
                    break;

                default:
                    SendMessage(player, "Command Not Found!");
                    break;
                }
                Console.WriteLine("Player " + player.ID + " Tried to Execute This Command: /" + request.ToString());
            }
            else if (message.Substring(0, 1) == "*")
            {
                List <string> request = Util.FetchString(message.Substring(1, message.Length - 1), " ");
                switch (request[0])
                {
                case "Create":
                    if (request.Count != 5)
                    {
                        return;
                    }
                    if (request[1] == "Character")
                    {
                        SendMessage(player, "*CCreateResult:" + Character.CreateCharacter(request[2], request[3], request[4]));
                    }
                    break;

                case "Delete":
                    if (request.Count != 4)
                    {
                        return;
                    }
                    if (request[1] == "Character")
                    {
                        Character.DeleteCharacter(request[2], Convert.ToInt16(request[3]));
                    }
                    break;

                case "CharacterList":
                    if (request.Count != 3)
                    {
                        return;
                    }
                    if (Account.GetAccount(request[1], request[2]) == "Success!")
                    {
                        SendMessage(player, "*CList:" + Character.RetrieveShortenedCharacterList(request[1]));
                    }
                    break;

                case "EnterWorld":
                    if (request.Count != 3)
                    {
                        return;
                    }
                    SendMessage(player, "*CharacterData:" + Character.LoadCharacterAsString(request[1], Convert.ToInt16(request[2])));
                    break;
                }
            }
            else
            {
                Console.WriteLine(player.Username + ": " + message);
            }
        }