Beispiel #1
0
        static bool HandleConnectingCore(Player p, string mppass)
        {
            if (p.truename.Length > 16)
            {
                p.Leave(null, "Usernames must be 16 characters or less", true); return(false);
            }
            if (!Player.ValidName(p.truename))
            {
                p.Leave(null, "Invalid player name", true); return(false);
            }

            if (!CheckPendingAlts(p))
            {
                return(false);
            }
            if (!VerifyName(p, mppass))
            {
                return(false);
            }
            if (!CheckTempban(p))
            {
                return(false);
            }

            bool whitelisted = CheckWhitelist(p.name, p.ip);

            if (!whitelisted)
            {
                p.Leave(null, "This is a private server!", true);
                return(false);
            }

            Group group = Group.findPlayerGroup(p.name);

            if (!CheckBanned(group, p, whitelisted))
            {
                return(false);
            }
            if (!CheckPlayersCount(group, p))
            {
                return(false);
            }
            if (!CheckOnlinePlayers(p))
            {
                return(false);
            }
            p.group = group;
            return(true);
        }
Beispiel #2
0
        static bool VerifyName(Player p, string mppass)
        {
            p.verifiedName = false;
            if (!Server.verify)
            {
                return(true);
            }

            byte[] hash = null;
            lock (md5Lock)
                hash = md5.ComputeHash(enc.GetBytes(Server.salt + p.truename));

            string hashHex = BitConverter.ToString(hash);

            if (!mppass.CaselessEq(hashHex.Replace("-", "")))
            {
                if (!Player.IPInPrivateRange(p.ip))
                {
                    p.Leave(null, "Login failed! Close the game and sign in again.", true); return(false);
                }
            }
            else
            {
                p.verifiedName = true;
            }
            return(true);
        }
Beispiel #3
0
        void DoKickJini(Player p)
        {
            string app = p.appName;

            if (app != null && app.CaselessContains("jini"))
            {
                p.Leave("Do not use hack clients.", true);
                p.cancellogin = true;
            }
        }
Beispiel #4
0
        void KickNoCC(Player p)
        {
            string app = p.appName;

            if (app == null || !app.CaselessContains("ClassiCube "))
            {
                p.Leave("Please connect using the ClassiCube client with Enhanced mode.", true);
                p.cancellogin = true;
            }
        }
Beispiel #5
0
        static bool CheckPlayersCount(Group group, Player p)
        {
            if (Server.vip.Contains(p.name))
            {
                return(true);
            }

            Player[] online = PlayerInfo.Online.Items;
            if (online.Length >= Server.players && !Player.IPInPrivateRange(p.ip))
            {
                p.Leave(null, "Server full!", true); return(false);
            }
            if (group.Permission > LevelPermission.Guest)
            {
                return(true);
            }

            online = PlayerInfo.Online.Items;
            int guests = 0;

            foreach (Player pl in online)
            {
                if (pl.Rank <= LevelPermission.Guest)
                {
                    guests++;
                }
            }
            if (guests < Server.maxGuests)
            {
                return(true);
            }

            if (Server.guestLimitNotify)
            {
                Chat.MessageOps("Guest " + p.truename + " couldn't log in - too many guests.");
            }
            Server.s.Log("Guest " + p.truename + " couldn't log in - too many guests.");
            p.Leave(null, "Server has reached max number of guests", true);
            return(false);
        }
Beispiel #6
0
        static void Receive(IAsyncResult result)
        {
            //Server.s.Log(result.AsyncState.ToString());
            Player p = (Player)result.AsyncState;

            if (p.disconnected || p.socket == null)
            {
                return;
            }

            try {
                int length = p.socket.EndReceive(result);
                if (length == 0)
                {
                    p.Disconnect(); return;
                }

                byte[] allData = new byte[p.leftBuffer.Length + length];
                Buffer.BlockCopy(p.leftBuffer, 0, allData, 0, p.leftBuffer.Length);
                Buffer.BlockCopy(p.tempbuffer, 0, allData, p.leftBuffer.Length, length);
                p.leftBuffer = p.ProcessReceived(allData);

                if (p.dontmindme && p.leftBuffer.Length == 0)
                {
                    Server.s.Log("Disconnected");
                    p.socket.Close();
                    p.disconnected = true;
                    return;
                }
                if (!p.disconnected)
                {
                    p.socket.BeginReceive(p.tempbuffer, 0, p.tempbuffer.Length, SocketFlags.None,
                                          new AsyncCallback(Receive), p);
                }
            } catch (SocketException) {
                p.Disconnect();
            }  catch (ObjectDisposedException) {
                // Player is no longer connected, socket was closed
                // Mark this as disconnected and remove them from active connection list
                Player.SaveUndo(p);
                connections.Remove(p);
                p.RemoveFromPending();
                p.disconnected = true;
            } catch (Exception e) {
                Server.ErrorLog(e);
                p.Leave("Error!");
            }
        }
Beispiel #7
0
        static bool CheckPendingAlts(Player p)
        {
            int altsCount = 0;

            lock (Player.pendingLock) {
                DateTime now = DateTime.UtcNow;
                foreach (Player.PendingItem item in Player.pendingNames)
                {
                    if (item.Name == p.truename && (now - item.Connected).TotalSeconds <= 60)
                    {
                        altsCount++;
                    }
                }
                Player.pendingNames.Add(new Player.PendingItem(p.truename));
            }

            if (altsCount > 0)
            {
                p.Leave(null, "Already logged in!", true); return(false);
            }
            return(true);
        }
Beispiel #8
0
        static bool CheckOnlinePlayers(Player p)
        {
            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (pl.name != p.name)
                {
                    continue;
                }

                if (Server.verify)
                {
                    string reason = pl.ip == p.ip ? "(Reconnecting)" : "(Reconnecting from a different IP)";
                    pl.Leave(reason); break;
                }
                else
                {
                    p.Leave(null, "Already logged in!", true);
                    return(false);
                }
            }
            return(true);
        }
Beispiel #9
0
        void CompleteLoginProcess()
        {
            Player clone = null;

            OnPlayerFinishConnectingEvent.Call(this);
            if (cancelconnecting)
            {
                cancelconnecting = false; return;
            }

            lock (PlayerInfo.Online.locker) {
                // Check if any players online have same name
                Player[] players = PlayerInfo.Online.Items;
                foreach (Player pl in players)
                {
                    if (pl.truename == truename)
                    {
                        clone = pl; break;
                    }
                }

                // Remove clone from list (hold lock for as short time as possible)
                if (clone != null && Server.Config.VerifyNames)
                {
                    PlayerInfo.Online.Remove(clone);
                }
                id = NextFreeId();
                PlayerInfo.Online.Add(this);
            }

            if (clone != null && Server.Config.VerifyNames)
            {
                string reason = ip == clone.ip ? "(Reconnecting)" : "(Reconnecting from a different IP)";
                clone.Leave(reason);
            }
            else if (clone != null)
            {
                Leave(null, "Already logged in!", true); return;
            }

            SendRawMap(null, level);
            if (Socket.Disconnected)
            {
                return;
            }
            loggedIn = true;

            SessionStartTime = DateTime.UtcNow;
            LastLogin        = DateTime.Now;
            TotalTime        = TimeSpan.FromSeconds(1);
            GetPlayerStats();
            ShowWelcome();

            Server.Background.QueueOnce(ShowAltsTask, name, TimeSpan.Zero);
            CheckState();

            PlayerDB.LoadNick(this);
            Game.Team = Team.TeamIn(this);
            SetPrefix();
            LoadCpeData();

            if (Server.noEmotes.Contains(name))
            {
                parseEmotes = !Server.Config.ParseEmotes;
            }

            hideRank = Rank;
            hidden   = CanUse("Hide") && Server.hidden.Contains(name);
            if (hidden)
            {
                Message("&8Reminder: You are still hidden.");
            }

            if (Chat.AdminchatPerms.UsableBy(Rank) && Server.Config.AdminsJoinSilently)
            {
                hidden = true; adminchat = true;
            }

            OnPlayerConnectEvent.Call(this);
            if (cancellogin)
            {
                cancellogin = false; return;
            }

            string joinMsg = "&a+ λFULL &S" + PlayerDB.GetLoginMessage(this);

            if (hidden)
            {
                joinMsg = "&8(hidden)" + joinMsg;
            }

            if (Server.Config.GuestJoinsNotify || Rank > LevelPermission.Guest)
            {
                Chat.MessageFrom(ChatScope.All, this, joinMsg, null, Chat.FilterVisible(this), !hidden);
            }

            if (Server.Config.AgreeToRulesOnEntry && Rank == LevelPermission.Guest && !Server.agreed.Contains(name))
            {
                Message("&9You must read the &c/Rules &9and &c/Agree &9to them before you can build and use commands!");
                agreed = false;
            }

            CheckIsUnverified();

            if (CanUse("Inbox") && Database.TableExists("Inbox" + name))
            {
                int count = Database.CountRows("Inbox" + name);
                if (count > 0)
                {
                    Message("You have &a" + count + " &Smessages in &T/Inbox");
                }
            }

            if (Server.Config.PositionUpdateInterval > 1000)
            {
                Message("Lowlag mode is currently &aON.");
            }

            if (String.IsNullOrEmpty(appName))
            {
                Logger.Log(LogType.UserActivity, "{0} [{1}] connected.", truename, IP);
            }
            else
            {
                Logger.Log(LogType.UserActivity, "{0} [{1}] connected using {2}.", truename, IP, appName);
            }

            PlayerActions.PostSentMap(this, null, level, false);
            Loading = false;
        }