コード例 #1
0
ファイル: Level.cs プロジェクト: noahjoyce31/MCGalaxy
 public void Message(string message)
 {
     Chat.Message(ChatScope.Level, message, this, null);
 }
コード例 #2
0
ファイル: Server.cs プロジェクト: 1stupidname/MCGalaxy
        public void Start()
        {
            serverConfig = ConfigElement.GetAll(typeof(Server), typeof(ZombieGame));

            PlayerInfo.players   = PlayerInfo.Online.list;
            Player.players       = PlayerInfo.Online.list;
            Server.levels        = LevelInfo.Loaded.list;
            PlayerBot.playerbots = PlayerBot.Bots.list;
            StartTime            = DateTime.UtcNow;
            StartTimeLocal       = StartTime.ToLocalTime();
            shuttingDown         = false;
            Log("Starting Server");
            try {
                if (File.Exists("Restarter.exe"))
                {
                    File.Delete("Restarter.exe");
                }
            } catch { }
            try {
                if (File.Exists("Restarter.pdb"))
                {
                    File.Delete("Restarter.pdb");
                }
            } catch { }

            CheckFile("MySql.Data.dll");
            CheckFile("System.Data.SQLite.dll");
            CheckFile("sqlite3.dll");
            CheckFile("Newtonsoft.Json.dll");
            CheckFile("LibNoise.dll");

            EnsureFilesExist();
            MoveOutdatedFiles();
            Chat.LoadCustomTokens();

            if (File.Exists("text/emotelist.txt"))
            {
                foreach (string s in File.ReadAllLines("text/emotelist.txt"))
                {
                    Player.emoteList.Add(s);
                }
            }
            else
            {
                File.Create("text/emotelist.txt").Dispose();
            }

            lava      = new LavaSurvival();
            zombie    = new ZombieGame();
            Countdown = new CountdownGame();
            LoadAllSettings();

            InitDatabase();
            Economy.LoadDatabase();
            Server.zombie.CheckTableExists();

            Level[] loaded = LevelInfo.Loaded.Items;
            foreach (Level l in loaded)
            {
                l.Unload();
            }
            ml.Queue(LoadMainLevel);
            Plugin.Load();
            ml.Queue(LoadPlayerLists);
            ml.Queue(LoadAutoloadCommands);
            ml.Queue(LoadGCAccepted);

            ml.Queue(InitTimers);
            ml.Queue(InitRest);
            ml.Queue(InitHeartbeat);
            UpdateStaffList();
        }
コード例 #3
0
        public bool Unload(bool silent = false, bool save = true)
        {
            if (Server.mainLevel == this || IsMuseum)
            {
                return(false);
            }
            if (Server.lava.active && Server.lava.map == this)
            {
                return(false);
            }
            if (LevelUnload != null)
            {
                LevelUnload(this);
            }
            OnLevelUnloadEvent.Call(this);
            if (cancelunload)
            {
                Server.s.Log("Unload canceled by Plugin! (Map: " + name + ")");
                cancelunload = false;
                return(false);
            }
            MovePlayersToMain();

            if (changed && ShouldSaveChanges())
            {
                Save(false, true);
                saveChanges();
            }
            if (TntWarsGame.Find(this) != null)
            {
                foreach (TntWarsGame.player pl in TntWarsGame.Find(this).Players)
                {
                    pl.p.CurrentTntGameNumber = -1;
                    Player.SendMessage(pl.p, "TNT Wars: The TNT Wars game you are currently playing has been deleted!");
                    pl.p.PlayingTntWars = false;
                    pl.p.canBuild       = true;
                    TntWarsGame.SetTitlesAndColor(pl, true);
                }
                Server.s.Log("TNT Wars: Game deleted on " + name);
                TntWarsGame.GameList.Remove(TntWarsGame.Find(this));
            }
            MovePlayersToMain();
            LevelInfo.Loaded.Remove(this);

            try
            {
                PlayerBot.RemoveAllFromLevel(this);
                //physChecker.Stop();
                //physChecker.Dispose();
                physThread.Abort();
                physThread.Join();
            }
            catch
            {
            }

            finally
            {
                Dispose();
                GC.Collect();
                GC.WaitForPendingFinalizers();

                if (!silent)
                {
                    Chat.GlobalMessageOps("&3" + name + Server.DefaultColor + " was unloaded.");
                }
                Server.s.Log(string.Format("{0} was unloaded.", name));
            }
            return(true);
        }
コード例 #4
0
ファイル: Level.cs プロジェクト: ProtheanGod/KingMC
        public bool Unload(bool silent = false, bool save = true)
        {
            if (Server.mainLevel == this || IsMuseum)
            {
                return(false);
            }
            if (Server.lava.active && Server.lava.map == this)
            {
                return(false);
            }
            OnLevelUnloadEvent.Call(this);
            if (cancelunload)
            {
                Logger.Log(LogType.SystemActivity, "Unload canceled by Plugin! (Map: {0})", name);
                cancelunload = false; return(false);
            }
            MovePlayersToMain();

            if (save && Changed && ShouldSaveChanges())
            {
                Save(false, true);
            }
            if (save && ShouldSaveChanges())
            {
                SaveBlockDBChanges();
            }

            if (TntWarsGame.Find(this) != null)
            {
                foreach (TntWarsGame.player pl in TntWarsGame.Find(this).Players)
                {
                    pl.p.CurrentTntGameNumber = -1;
                    Player.Message(pl.p, "TNT Wars: The TNT Wars game you are currently playing has been deleted!");
                    pl.p.PlayingTntWars = false;
                    pl.p.canBuild       = true;
                    TntWarsGame.SetTitlesAndColor(pl, true);
                }
                Logger.Log(LogType.GameActivity, "TNT Wars: Game deleted on " + name);
                TntWarsGame.GameList.Remove(TntWarsGame.Find(this));
            }
            MovePlayersToMain();
            LevelInfo.Loaded.Remove(this);

            try {
                if (!unloadedBots)
                {
                    unloadedBots = true;
                    BotsFile.Save(this);
                    PlayerBot.RemoveLoadedBots(this, false);
                }

                physThread.Abort();
                physThread.Join();
            } catch {
            } finally {
                Dispose();
                Server.DoGC();

                if (!silent)
                {
                    Chat.MessageOps(ColoredName + " %Swas unloaded.");
                }
                Logger.Log(LogType.SystemActivity, name + " was unloaded.");
            }
            return(true);
        }
コード例 #5
0
ファイル: Level.Blocks.cs プロジェクト: ProtheanGod/KingMC
        /// <summary> Returns: <br/>
        /// 0 - block change was not performed <br/>
        /// 1 - old block was same as new block visually (e.g. white to door_white)<br/>
        /// 2 - old block was different to new block visually </summary>
        /// <remarks> The return code can be used to avoid sending redundant block changes. </remarks>
        public int DoBlockchange(Player p, ushort x, ushort y, ushort z, ExtBlock block, bool drawn = false)
        {
            string errorLocation = "start";

            try
            {
                if (x >= Width || y >= Height || z >= Length)
                {
                    return(0);
                }
                ExtBlock old = GetBlock(x, y, z);

                errorLocation = "Permission checking";
                if (!CheckAffectPermissions(p, x, y, z, old, block))
                {
                    p.RevertBlock(x, y, z); return(0);
                }
                if (old == block)
                {
                    return(0);
                }

                if (old.BlockID == Block.Sponge && physics > 0 && block.BlockID != Block.Sponge)
                {
                    OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z), false);
                }
                if (old.BlockID == Block.LavaSponge && physics > 0 && block.BlockID != Block.LavaSponge)
                {
                    OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z), true);
                }

                p.SessionModified++;
                p.TotalModified++;

                if (drawn)
                {
                    p.TotalDrawn++;
                }
                else if (block.BlockID == Block.Air)
                {
                    p.TotalDeleted++;
                }
                else
                {
                    p.TotalPlaced++;
                }

                errorLocation = "Setting tile";
                SetTile(x, y, z, block.BlockID);
                if (old.BlockID == Block.custom_block && block.BlockID != Block.custom_block)
                {
                    RevertExtTileNoCheck(x, y, z);
                }
                if (block.BlockID == Block.custom_block)
                {
                    SetExtTileNoCheck(x, y, z, block.ExtID);
                }

                errorLocation = "Adding physics";
                if (p.PlayingTntWars && block.BlockID == Block.TNT_Small)
                {
                    AddTntCheck(PosToInt(x, y, z), p);
                }
                if (physics > 0 && ActivatesPhysics(block))
                {
                    AddCheck(PosToInt(x, y, z));
                }

                Changed  = true;
                backedup = false;

                return(old.VisuallyEquals(block) ? 1 : 2);
            } catch (Exception e) {
                Logger.LogError(e);
                Chat.MessageOps(p.name + " triggered a non-fatal error on " + ColoredName + ", %Sat location: " + errorLocation);
                Logger.Log(LogType.Warning, "{0} triggered a non-fatal error on {1}, %Sat location: {2}",
                           p.name, ColoredName, errorLocation);
                return(0);
            }
        }
コード例 #6
0
        public 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
                clone = FindClone(truename);
                // 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();
            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;
            }

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

            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;
        }
コード例 #7
0
        void HandleChat(byte[] buffer, int offset)
        {
            if (!loggedIn)
            {
                return;
            }
            byte   continued = buffer[offset + 1];
            string text      = NetUtils.ReadString(buffer, offset + 2);

            LastAction = DateTime.UtcNow;
            if (FilterChat(ref text, continued))
            {
                return;
            }

            if (text != "/afk" && IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }

            // Typing //Command appears in chat as /command
            // Suggested by McMrCat
            if (text.StartsWith("//"))
            {
                text = text.Remove(0, 1);
            }
            else if (DoCommand(text))
            {
                return;
            }

            // People who are muted can't speak or vote
            if (muted)
            {
                Message("You are muted."); return;
            }                                                 //Muted: Only allow commands

            if (Server.voting)
            {
                if (CheckVote(text, this, "y", "yes", ref Server.YesVotes) ||
                    CheckVote(text, this, "n", "no", ref Server.NoVotes))
                {
                    return;
                }
            }

            if (LSGame.Instance.HandlesChatMessage(this, text))
            {
                return;
            }
            if (ZSGame.Instance.HandlesChatMessage(this, text))
            {
                return;
            }

            // Put this after vote collection so that people can vote even when chat is moderated
            if (Server.chatmod && !voice)
            {
                Message("Chat moderation is on, you cannot speak."); return;
            }

            // Filter out bad words
            if (Server.Config.ProfanityFiltering)
            {
                text = ProfanityFilter.Parse(text);
            }

            if (ChatModes.Handle(this, text))
            {
                return;
            }
            text = HandleJoker(text);

            OnPlayerChatEvent.Call(this, text);
            if (cancelchat)
            {
                cancelchat = false; return;
            }

            if (Chatroom != null)
            {
                string roomPrefix = "<ChatRoom: " + Chatroom + "> λNICK: &f";
                Chat.MessageChat(ChatScope.Chatroom, this, roomPrefix + text, Chatroom, null);
            }
            else
            {
                Chat.MessageChat(this, "λFULL: &f" + text, null, true);
            }
        }
コード例 #8
0
        public bool HandleDeath(BlockID block, string customMsg = "", bool explode = false, bool immediate = false)
        {
            if (!immediate && lastDeath.AddSeconds(2) > DateTime.UtcNow)
            {
                return(false);
            }
            if (invincible || hidden)
            {
                return(false);
            }

            cancelDeath = false;
            OnPlayerDeathEvent.Call(this, block);
            if (cancelDeath)
            {
                cancelDeath = false; return(false);
            }

            onTrain = false; trainInvincible = false; trainGrab = false;
            ushort x = (ushort)Pos.BlockX, y = (ushort)Pos.BlockY, z = (ushort)Pos.BlockZ;

            string deathMsg = level.Props[block].DeathMessage;

            if (deathMsg != null)
            {
                Chat.MessageFromLevel(this, deathMsg.Replace("@p", "λNICK"));
            }

            if (block == Block.RocketHead)
            {
                level.MakeExplosion(x, y, z, 0);
            }
            if (block == Block.Creeper)
            {
                level.MakeExplosion(x, y, z, 1);
            }

            if (block == Block.Stone || block == Block.Cobblestone)
            {
                if (explode)
                {
                    level.MakeExplosion(x, y, z, 1);
                }
                if (block == Block.Stone)
                {
                    Chat.MessageFrom(this, customMsg.Replace("@p", "λNICK"));
                }
                else
                {
                    Chat.MessageFromLevel(this, customMsg.Replace("@p", "λNICK"));
                }
            }

            PlayerActions.Respawn(this);
            TimesDied++;
            // NOTE: If deaths column is ever increased past 16 bits, remove this clamp
            if (TimesDied > short.MaxValue)
            {
                TimesDied = short.MaxValue;
            }

            if (Server.Config.AnnounceDeathCount && (TimesDied > 0 && TimesDied % 10 == 0))
            {
                Chat.MessageFromLevel(this, "λNICK %Shas died &3" + TimesDied + " times");
            }
            lastDeath = DateTime.UtcNow;
            return(true);
        }
コード例 #9
0
ファイル: Level.Physics.cs プロジェクト: TheMegaPVP/MCGalaxy
        void PhysicsLoop()
        {
            int wait = Config.PhysicsSpeed;

            while (true)
            {
                if (PhysicsPaused)
                {
                    Thread.Sleep(500); continue;
                }

                try {
                    if (wait > 0)
                    {
                        Thread.Sleep(wait);
                    }
                    if (physics == 0)
                    {
                        lastCheck = 0; break;
                    }

                    // No block calculations in this tick
                    if (ListCheck.Count == 0)
                    {
                        lastCheck = 0;
                        wait      = Config.PhysicsSpeed;
                        continue;
                    }

                    DateTime tickStart = default(DateTime);
                    try {
                        lock (physTickLock) {
                            tickStart = DateTime.UtcNow;
                            PhysicsTick();
                        }
                    } catch (Exception ex) {
                        Logger.LogError("Error in physics tick", ex);
                    }

                    // Measure how long this physics tick took to execute
                    TimeSpan elapsed = DateTime.UtcNow - tickStart;
                    wait = Config.PhysicsSpeed - (int)elapsed.TotalMilliseconds;

                    // Check if tick took too long to execute (server is falling behind)
                    if (wait < (int)(-Config.PhysicsOverload * 0.75f))
                    {
                        if (wait < -Config.PhysicsOverload)
                        {
                            if (!Server.Config.PhysicsRestart)
                            {
                                SetPhysics(0);
                            }
                            ClearPhysics();
                            Chat.MessageGlobal("Physics shutdown on {0}", ColoredName);

                            Logger.Log(LogType.Warning, "Physics shutdown on " + name);
                            OnPhysicsStateChangedEvent.Call(this, PhysicsState.Stopped);
                            wait = Config.PhysicsSpeed;
                        }
                        else
                        {
                            Message("Physics warning!");
                            Logger.Log(LogType.Warning, "Physics warning on " + name);
                            OnPhysicsStateChangedEvent.Call(this, PhysicsState.Warning);
                        }
                    }
                } catch {
                    wait = Config.PhysicsSpeed;
                }
            }
            physThreadStarted = false;
        }