Пример #1
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);
            }
        }
Пример #2
0
        static void ParsePlayerMessage(Player player, string message)
        {
            if (player.Username == null)
            {
                List <string> request = Util.FetchRequest(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 Mr. " + request[1] + "! You Are Now Logged In!");
                        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]))
                    {
                        KickPlayer(player, "Account Created!");
                    }
                    else
                    {
                        KickPlayer(player, "Account Exists!");
                    }
                    break;
                }
                return;
            }

            if (message.Substring(0, 1) == "/")
            {
                List <string> request = Util.FetchRequest(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());
                return;
            }

            Console.WriteLine(player.Username + ": " + message);
        }