Beispiel #1
0
        private static void StartInput()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input == null || (input = input.Trim()).Length == 0)
                {
                    continue;
                }

                string[] inputParts = input.Split();

                if (inputParts[0].StartsWith("/"))
                {
                    string cmd = inputParts[0].Substring(1).ToLower();

                    switch (cmd)
                    {
                    case "stop":
                        Logger.Log(LogLevel.Info, "Stopping Server...");
                        for (int i = Player.players.Count - 1; i >= 0; i--)
                        {
                            Player.players[i].Kick("Server Shutting Down!");
                        }
                        Exit();
                        return;

                    case "id":
                        new Thread(new ThreadStart(InventoryDebug)).Start();
                        break;

                    default:
                        Command command = Command.all.Find(cmd);
                        if (command == null)
                        {
                            Logger.Log(LogLevel.Info, "Unrecognized command: " + cmd);
                            break;
                        }

                        if (command.ConsoleUseable)
                        {
                            string[] args = new string[inputParts.Length - 1];

                            Array.Copy(inputParts, 1, args, 0, inputParts.Length - 1);

                            try { command.Use(Server.consolePlayer, args); }
                            catch (Exception e) { Logger.LogError(e); }
                            break;
                        }
                        else
                        {
                            Logger.Log(LogLevel.Info, cmd + " command not useable in the console.");
                            break;
                        }
                    }
                }
                else if (inputParts[0].StartsWith("@"))
                {
                    string name    = inputParts[0].Substring(1);
                    string message = "";
                    Player p       = Player.FindPlayer(name);
                    Logger.Log(name + " : ");

                    if (p != null)
                    {
                        if (inputParts.Length <= 1)
                        {
                            Logger.Log(LogLevel.Warning, "Please enter a message to send");
                        }
                        else if (input.Length > 1)
                        {
                            for (int i = 1; i < inputParts.Length; i++)
                            {
                                message += inputParts[i];
                            }
                            p.SendMessage(Color.PrivateMsg + "[Server >> Me] " + Color.ServerDefaultColor + message);
                        }
                    }
                    else
                    {
                        Logger.Log(LogLevel.Warning, "Please enter a valid username");
                    }
                }
                else
                {
                    Player.GlobalMessage(Color.Announce + "[" + Server.consolePlayer.username + "]: " + Color.Blue + input);
                }
            }
        }
Beispiel #2
0
        private void HandleLogin(byte[] message)
        {
            int   version = util.EndianBitConverter.Big.ToInt32(message, 0);
            short length  = util.EndianBitConverter.Big.ToInt16(message, 4);

            if (length > 32)
            {
                Kick("Username too long"); return;
            }
            username = Encoding.BigEndianUnicode.GetString(message, 6, (length * 2));
            Logger.Log(ip + " Logged in as " + username);

            if (Server.VerifyNames)
            {
                bool verified = false;
                try
                {
                    using (WebClient web = new WebClient())
                    {
                        string response = web.DownloadString("http://session.minecraft.net/game/checkserver.jsp?user="******"&serverId=" + randomHash);
                        verified = (response.Trim() == "YES");
                    }
                }
                catch { }
                if (!verified)
                {
                    Kick("Failed to verify username!"); return;
                }
            }

            /*if (version > Server.protocolversion)  //left commented during development
             * {
             *  Kick("Outdated server!");
             *  return;
             * }
             * if (version < Server.protocolversion)
             * {
             *  Kick("Outdated client!");
             *  return;
             * }*/

            if (!IPInPrivateRange(ip))
            {
                if (Player.players.Count >= Server.MaxPlayers)
                {
                    if (Server.useviplist && Server.VIPList.Contains(username.ToLower()))
                    {
                        for (int i = players.Count - 1; i >= 0; i--) // kick the last joined non-vip
                        {
                            if (!Server.VIPList.Contains(players[i].username.ToLower()))
                            {
                                players[i].Kick("You have been kicked for a VIP.");
                                break;
                            }
                        }
                    }
                    else if (Server.useviplist && !Server.VIPList.Contains(username.ToLower()))
                    {
                        Kick(Server.VIPListMessage);
                    }
                    else if (!Server.useviplist)
                    {
                        Kick("Server is full!");
                    }
                }

                if (Server.BanList.Contains(username.ToLower()))
                {
                    Kick(Server.BanMessage);
                }

                if (Server.usewhitelist && !Server.WhiteList.Contains(username.ToLower()))
                {
                    Kick(Server.WhiteListMessage);
                }
            }

            //TODO: load Player attributes like group, and other settings
            LoadAttributes();

            LoggedIn = true;
            SendLoginPass();

            Player.GlobalMessage(Color.Announce + username + " has joined the game!");

            UpdateShi(this);

            int tries = 0;

            while (tries < 100 && Chunk.GetChunk((int)pos.x >> 4, (int)pos.z >> 4, level) == null)
            {
                tries++;
                System.Threading.Thread.Sleep(50);
            }

            if (Chunk.GetChunk((int)pos.x >> 4, (int)pos.z >> 4, level) == null)
            {
                Kick("Chunk missing: " + ((int)pos.x >> 4) + "," + ((int)pos.z >> 4));
            }

            /*if (PlayerAuth != null)
             *      PlayerAuth(this);
             * if (OnAuth != null)
             * OnAuth(this);*/
            OnPlayerAuthEvent.Call(this);
        }