Example #1
0
        public void SpawnPlayer(Player p, bool self)
        {
            try
            {
                Packet spawn = new Packet(74);
                spawn.Append((byte)ServerPacket.SpawnEntity);
                if (self)
                {
                    spawn.Append((byte)255);
                }
                else
                {
                    spawn.Append(p.id);
                }

                spawn.Append(Rank.GetColor(p.rank) + p.username); //username
                spawn.Append((short)p.x);                         //x position
                spawn.Append((short)p.y);                         //y position
                spawn.Append((short)p.z);                         //z position

                spawn.Append(p.rotx);                             //x rotation
                spawn.Append(p.roty);                             //y rotation
                this.SendPacket(spawn);
            }

            catch (IOException) { }
            catch (SocketException) { }
            catch (Exception e) { Program.server.logger.log(e); }
        }
Example #2
0
        public void PlayerMessage()
        {
            this.inputReader.ReadByte();
            string rawmsg = Encoding.ASCII.GetString(this.inputReader.ReadBytes(64)).Trim();

            rawmsg = ParseSpecialChar(rawmsg);
            //Test for commands
            if (!rawmsg.Trim().Equals("") && rawmsg.Trim()[0] == '/')
            {
                string cmd = "", args = "";
                if (rawmsg.Contains(" "))
                {
                    cmd  = rawmsg.Trim().Substring(1, rawmsg.IndexOf(' ') - 1);
                    args = rawmsg.Trim().Substring(rawmsg.IndexOf(' ')).Trim();
                }
                else
                {
                    cmd = rawmsg.Substring(1);
                }
                Command.HandleCommand(this, cmd, args);
                return;
            }

            //Test for PMs
            if (!rawmsg.Trim().Equals("") && rawmsg.Trim()[0] == '@' && rawmsg.Trim()[1] != '@' && rawmsg.Trim().Contains(" "))
            {
                string tname  = rawmsg.Trim().Substring(1, rawmsg.IndexOf(" ") - 1);
                Player target = FindPlayer(this, tname, false);
                if (target != null)
                {
                    target.SendMessage(0x00, Rank.GetColor(this.rank) + "(" + this.prefix + this.username + ")&e " + (char)26 + "&f " + rawmsg.Substring(rawmsg.IndexOf(" ") + 1));
                    this.SendMessage(0x00, Rank.GetColor(target.rank) + "(" + target.prefix + target.username + ")&e " + (char)27 + "&f " + rawmsg.Substring(rawmsg.IndexOf(" ") + 1));
                }
                return;
            }

            string message = "";

            message = Rank.GetColor(rank) + "<" + prefix + username + "> &f" + rawmsg;
            if (rank >= Rank.RankLevel("player") && !message.Contains("@@"))
            {
                message = ParseColors(message);
            }
            Program.server.logger.log(message, Logger.LogType.Chat);

            foreach (Player p in Program.server.playerlist)
            {
                if (p != null && p.loggedIn)
                {
                    p.SendMessage(id, message);
                }
            }
        }
Example #3
0
        public static void Commands(Player p, string message)
        {
            StringBuilder availableCmds = new StringBuilder();

            availableCmds.Append("Available commands:");
            foreach (KeyValuePair <string, Command> cmd in Command.commands)
            {
                if (cmd.Value.minRank <= p.rank)
                {
                    availableCmds.Append(" ");
                    availableCmds.Append(Rank.GetColor(cmd.Value.minRank));
                    availableCmds.Append(cmd.Key);
                }
            }
            p.SendMessage(0xFF, availableCmds.ToString());
        }
Example #4
0
        public static void Who(Player p, string message)
        {
            Player pl = Player.FindPlayer(p, message.Trim(), true);

            if (pl != null)
            {
                StringBuilder msg = new StringBuilder();
                msg.Append(pl.GetFormattedName());
                msg.Append("&e is ranked " + Rank.GetColor(pl.rank) + Rank.RankName(pl.rank));
                msg.Append("&e and is connected from IP &b" + pl.ip);
                p.SendMessage(0x00, msg.ToString());
            }
            else
            {
                p.SendMessage(0xFF, "Command failed (could not find player)");
            }
        }
Example #5
0
        public void Login()
        {
            byte opLogin = this.inputReader.ReadByte();

            if (opLogin != (byte)ClientPacket.Login)
            {
                Program.server.logger.log("Wrong login opcode received from " + ip, Logger.LogType.Warning);
                Kick("Wrong Login Opcode", true);
                return;
            }
            byte plyProtocol = this.inputReader.ReadByte();

            if (plyProtocol != Protocol.version)  //Shouldn't happen
            {
                Program.server.logger.log("Wrong protocol version received from " + ip, Logger.LogType.Warning);
                Kick("Wrong Protocol Version", true);
                return;
            }
            //Read username
            this.username = Encoding.ASCII.GetString(this.inputReader.ReadBytes(64)).Trim();

            //Verify the name
            string mppass = Encoding.ASCII.GetString(this.inputReader.ReadBytes(64)).Trim();

            if (Program.server.verify_names)
            {
                while (mppass.Length < 32)
                {
                    mppass = "******" + mppass;
                }
                MD5    hasher  = new MD5CryptoServiceProvider();
                byte[] cmpHash = hasher.ComputeHash(Encoding.ASCII.GetBytes(Program.server.salt + username));
                for (int i = 0; i < 16; i += 2)
                {
                    if (mppass[i] + "" + mppass[i + 1] != cmpHash[i / 2].ToString("x2"))
                    {
                        Kick("Name verification failed!", true);
                    }
                }
            }

            //Unused byte
            this.inputReader.ReadByte();

            if (Program.server.ipbanned.Contains(ip))
            {
                Kick("You're IP Banned!", true);
                return;
            }

            //Check Rank
            if (Program.server.playerRanksDict.ContainsKey(username.ToLower()))
            {
                this.rank = Program.server.playerRanksDict[username.ToLower()];
            }
            else
            {
                this.rank = Rank.RankLevel("guest");
                Program.server.saveRanks();
            }

            if (rank == Rank.RankLevel("none"))
            {
                Kick("You're banned!", true);
                return;
            }

            //Send a response
            this.outputWriter.Write((byte)ServerPacket.Login);
            this.outputWriter.Write((byte)Protocol.version);                                                           // Protocol version
            this.outputWriter.Write(Encoding.ASCII.GetBytes(Program.server.serverName.PadRight(64).Substring(0, 64))); // name
            this.outputWriter.Write(Encoding.ASCII.GetBytes(Program.server.motd.PadRight(64).Substring(0, 64)));       //motd

            if (rank >= Rank.RankLevel("operator"))
            {
                this.outputWriter.Write((byte)0x64);
            }                                                                                //Can break adminium
            else
            {
                this.outputWriter.Write((byte)0x00);
            }                                             //Cannot break adminium

            Program.server.logger.log(ip + " logged in as " + username);

            //Find an empty slot for them
            bool emptySlot = false;

            for (int i = 0; i < Program.server.playerlist.Length - 1; i++)
            {
                if (Program.server.playerlist[i] == null)
                {
                    emptySlot = true;
                    break;
                }
            }
            if (!emptySlot) //Server is full :(
            {
                Kick("Server is full!", true);
                return;
            }

            //We are logged in now
            loggedIn = true;
            Program.server.plyCount++;

            //Init any player-specific plugins
            //ExamplePlugins.Init(this);

            //If they are ranked operator or admin, give them a snazzy prefix
            if (rank == Rank.RankLevel("operator"))
            {
                prefix = "+";
            }
            if (rank == Rank.RankLevel("owner"))
            {
                prefix = "@";
            }

            //Send the map
            this.SendPacket(new Packet(new byte[1] {
                (byte)ServerPacket.MapBegin
            }));
            SendMap(Program.server.world);

            //Announce the player's arrival
            string loginMessage = Rank.GetColor(rank).ToString();

            if (!prefix.Equals(""))
            {
                loginMessage += prefix;
            }
            loginMessage += username + "&e joined the game";
            GlobalMessage(loginMessage);
            if (this.OnLogin != null) //Call the OnLogin Event
            {
                OnLogin(this);
            }
        }
Example #6
0
 public string GetFormattedName()
 {
     return(Rank.GetColor(this.rank) + this.prefix + this.username);
 }
Example #7
0
        public static void Base(Player p, string message, byte newrank)
        {
            if (message.Trim().Equals(""))
            {
                p.SendMessage(0xFF, "No player specified");
                return;
            }

            Player pl = uMiner.Player.FindPlayer(p, message, false);

            if (pl != null)
            {
                if (pl.username.Equals(p.username))
                {
                    p.SendMessage(0xFF, "You can't change your own rank!");
                }
                if (pl.rank < newrank || p.rank > pl.rank || p.username.Equals("[console]"))
                {
                    byte oldRank = pl.rank;
                    pl.rank = newrank;
                    Program.server.playerRanksDict[pl.username.ToLower()] = pl.rank;
                    Program.server.saveRanks();

                    if (newrank == 0)
                    {
                        pl.prefix = "[:(]";
                    }
                    else if (newrank < Rank.RankLevel("operator"))
                    {
                        pl.prefix = "";
                    }
                    else if (newrank == Rank.RankLevel("operator"))
                    {
                        pl.prefix = "+";
                    }
                    else if (newrank == Rank.RankLevel("owner"))
                    {
                        pl.prefix = "@";
                    }

                    //Clear the player's binding as a safeguard
                    pl.binding = Bindings.None;

                    //If the person was OP before, disable adminium editing
                    //Vice versa as well
                    if (oldRank >= Rank.RankLevel("operator") && newrank < Rank.RankLevel("operator"))
                    {
                        Packet deop = new Packet(2);
                        deop.Append((byte)ServerPacket.RankUpdate);
                        deop.Append((byte)0x0);
                        pl.SendPacket(deop);
                    }
                    else if (oldRank < Rank.RankLevel("operator") && newrank >= Rank.RankLevel("operator"))
                    {
                        Packet deop = new Packet(2);
                        deop.Append((byte)ServerPacket.RankUpdate);
                        deop.Append((byte)0x64);
                        pl.SendPacket(deop);
                    }

                    //Despawn and respawn player
                    Packet despawn = new Packet(2);
                    despawn.Append((byte)ServerPacket.PlayerDie);
                    despawn.Append(pl.id);
                    foreach (Player ply in Program.server.playerlist)
                    {
                        if (ply != null && ply != pl && ply.loggedIn && !ply.disconnected)
                        {
                            ply.SendPacket(despawn);
                        }
                    }
                    uMiner.Player.GlobalSpawnPlayer(pl);
                    uMiner.Player.GlobalMessage(p.GetFormattedName() + "&e set " + pl.GetFormattedName() + "&e's rank to " + Rank.GetColor(newrank) + Rank.RankName(newrank) + "&e");
                }
                else
                {
                    p.SendMessage(0xFF, "Player " + pl.GetFormattedName() + "&e cannot have rank set to " + Rank.GetColor(newrank) + Rank.RankName(newrank));
                }
                return;
            }
        }