Example #1
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 #2
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;
            }
        }
Example #3
0
 public static void Operator(Player p, string message)
 {
     Base(p, message, Rank.RankLevel("operator"));
 }
Example #4
0
 public static void Owner(Player p, string message)
 {
     Base(p, message, Rank.RankLevel("owner"));
 }
Example #5
0
 public static void Guest(Player p, string message)
 {
     Base(p, message, Rank.RankLevel("guest"));
 }