Exemple #1
0
        void CompleteLoginProcess()
        {
            // Lock to ensure that no two players can end up with the same playerid
            lock (PlayerInfo.Online.locker) {
                id = NextFreeId();
                PlayerInfo.Online.Add(this);
            }

            SendMap(null);
            if (disconnected)
            {
                return;
            }
            loggedIn = true;
            connections.Remove(this);
            RemoveFromPending();
            Server.PlayerListUpdate();

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

            Server.Background.QueueOnce(ShowAltsTask, name, TimeSpan.Zero);
            CheckState();
            ZombieStats stats = Server.zombie.LoadZombieStats(name);

            Game.MaxInfected       = stats.MaxInfected; Game.TotalInfected = stats.TotalInfected;
            Game.MaxRoundsSurvived = stats.MaxRounds; Game.TotalRoundsSurvived = stats.TotalRounds;

            if (!Directory.Exists("players"))
            {
                Directory.CreateDirectory("players");
            }
            PlayerDB.Load(this);
            Game.Team = Team.TeamIn(this);
            SetPrefix();
            LoadCpeData();

            if (ServerConfig.verifyadmins && group.Permission >= ServerConfig.VerifyAdminsRank)
            {
                adminpen = true;
            }
            if (Server.noEmotes.Contains(name))
            {
                parseEmotes = !ServerConfig.ParseEmotes;
            }

            LevelPermission adminChatRank = CommandExtraPerms.MinPerm("adminchat", LevelPermission.Admin);

            hidden = group.CanExecute("hide") && Server.hidden.Contains(name);
            if (hidden)
            {
                SendMessage("&8Reminder: You are still hidden.");
            }
            if (group.Permission >= adminChatRank && ServerConfig.AdminsJoinSilently)
            {
                hidden = true; adminchat = true;
            }

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

            string joinm = "&a+ " + FullName + " %S" + PlayerDB.GetLoginMessage(this);

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

            const LevelPermission perm = LevelPermission.Guest;

            if (group.Permission > perm || (ServerConfig.GuestJoinsNotify && group.Permission <= perm))
            {
                Chat.MessageGlobal(this, joinm, false, true);
            }

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

            if (ServerConfig.verifyadmins && group.Permission >= ServerConfig.VerifyAdminsRank)
            {
                if (!Directory.Exists("extra/passwords") || !File.Exists("extra/passwords/" + name + ".dat"))
                {
                    SendMessage("&cPlease set your admin verification password with %T/SetPass [Password]!");
                }
                else
                {
                    SendMessage("&cPlease complete admin verification with %T/Pass [Password]!");
                }
            }

            try {
                if (group.CanExecute("inbox") && Database.TableExists("Inbox" + name))
                {
                    using (DataTable table = Database.Backend.GetRows("Inbox" + name, "*")) {
                        if (table.Rows.Count > 0)
                        {
                            SendMessage("You have &a" + table.Rows.Count + " %Smessages in %T/Inbox");
                        }
                    }
                }
            } catch {
            }

            if (ServerConfig.PositionUpdateInterval > 1000)
            {
                SendMessage("Lowlag mode is currently &aON.");
            }

            if (String.IsNullOrEmpty(appName))
            {
                Logger.Log(LogType.UserActivity, "{0} [{1}] connected.", name, ip);
            }
            else
            {
                Logger.Log(LogType.UserActivity, "{0} [{1}] connected using {2}.", name, ip, appName);
            }
            Game.InfectMessages = PlayerDB.GetInfectMessages(this);
            Server.lava.PlayerJoinedServer(this);

            Position pos = level.SpawnPos;
            byte     yaw = level.rotx, pitch = level.roty;

            OnPlayerSpawningEvent.Call(this, ref pos, ref yaw, ref pitch, false);
            Pos = pos;
            SetYawPitch(yaw, pitch);

            Entities.SpawnEntities(this, true);
            PlayerActions.CheckGamesJoin(this, null);
            Loading = false;
        }
Exemple #2
0
        void LeaveServer(string chatMsg, string discMsg, bool isKick, bool sync = false)
        {
            if (leftServer)
            {
                return;
            }
            leftServer = true;
            CriticalTasks.Clear();

            //Umm...fixed?
            if (name == null || name.Length == 0)
            {
                if (Socket != null)
                {
                    CloseSocket();
                }
                connections.Remove(this);
                disconnected = true;
                Logger.Log(LogType.UserActivity, "{0} disconnected.", ip);
                return;
            }

            Server.reviewlist.Remove(name);
            try {
                if (disconnected)
                {
                    CloseSocket();
                    connections.Remove(this);
                    PlayerInfo.Online.Remove(this);
                    return;
                }
                // FlyBuffer.Clear();
                LastAction = DateTime.UtcNow;
                IsAfk      = false;
                isFlying   = false;
                aiming     = false;

                if (chatMsg != null)
                {
                    chatMsg = Colors.Escape(chatMsg);
                }
                discMsg = Colors.Escape(discMsg);

                string kickPacketMsg = ChatTokens.Apply(discMsg, this);
                Send(Packet.Kick(kickPacketMsg, hasCP437), sync);
                disconnected = true;
                if (isKick)
                {
                    TimesBeenKicked++;
                }

                if (!loggedIn)
                {
                    connections.Remove(this);
                    RemoveFromPending();
                    PlayerInfo.Online.Remove(this);

                    string user = name + " (" + ip + ")";
                    Logger.Log(LogType.UserActivity, "{0} disconnected. ({1})", user, discMsg);
                    return;
                }

                if (Game.team != null)
                {
                    Game.team.RemoveMember(this);
                }
                TntWarsGame tntwarsgame = TntWarsGame.GameIn(this);
                if (tntwarsgame != null)
                {
                    tntwarsgame.Players.Remove(tntwarsgame.FindPlayer(this));
                    tntwarsgame.SendAllPlayersMessage("TNT Wars: " + ColoredName + " %Shas left TNT Wars!");
                }

                Entities.DespawnEntities(this, false);
                ShowDisconnectInChat(chatMsg, isKick);
                save();

                PlayerInfo.Online.Remove(this);
                Server.PlayerListUpdate();
                OnPlayerDisconnectEvent.Call(this, discMsg);

                if (ServerConfig.AutoLoadMaps && level.Config.AutoUnload && !level.IsMuseum && !level.HasPlayers())
                {
                    level.Unload(true);
                }
                Dispose();
            } catch (Exception e) {
                Logger.LogError(e);
            } finally {
                CloseSocket();
            }
        }