Пример #1
0
 public static void placeBlock(Level l, Player p, ushort x, ushort y, ushort z, byte type)
 {
     if (p == null)
         l.Blockchange(x, y, z, type);
     else
         l.Blockchange(p, x, y, z, type);
 }
Пример #2
0
 public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) {
     int lenX = (x2 - x1 + 1), lenY = (y2 - y1 + 1), lenZ = (z2 - z2 + 1);
     int xQuadsVol = Math.Min(lenX, 2) * (lenY * lenZ);
     int yQuadsVol = Math.Max(0, Math.Min(lenY, 2) * ((lenX - 2) * lenZ)); // we need to avoid double counting overlaps
     int zQuadzVol = Math.Max(0, Math.Min(lenZ, 2) * ((lenX - 2) * (lenY - 2)));
     return xQuadsVol + yQuadsVol + zQuadzVol;
 }
Пример #3
0
 public static void GlobalMessageLevel(Level l, string message) {
     Player.players.ForEach(
         delegate(Player p) {
             if ( p.level == l && p.Chatroom == null )
                 Player.SendMessage(p, message);
         });
 }
Пример #4
0
        public static ushort writeLetter(Level l, Player p, char c, ushort x, ushort y, ushort z, byte b, int direction)
        {
            if( (int)c >= 256 || letters[(int)c] == null ) {
                Player.SendMessage(p, "\"" + c + "\" is currently not supported. Space left");
                if (direction == 0) x += 4; else if (direction == 1) x -= 4;
                else if (direction == 2) z += 4; else z -= 4;
            } else {
                byte[] flags = letters[(int)c];
                for( int i = 0; i < flags.Length; i++ ) {
                    byte yUsed = flags[i];
                    for (int j = 0; j < 8; j++) {
                        if ((yUsed & (1 << j)) == 0) continue;
                        
                        placeBlock(l, p, x, (ushort)(y + j), z, b);
                    }
                    
                    if (direction == 0) x++; else if (direction == 1) x--; 
                    else if (direction == 2) z++; else z--;
                }
            }

            if (direction == 0) return (ushort)(x + 1);
            else if (direction == 1) return (ushort)(x - 1);
            else if (direction == 2) return (ushort)(z + 1);
            else return (ushort)(z - 1);
        }
Пример #5
0
 /// <summary>
 /// Register this event
 /// </summary>
 /// <param name="method">This is the delegate that will get called when this event occurs</param>
 /// <param name="priority">The priority (imporantce) of this call</param>
 /// <param name="plugin">The plugin object that is registering the event</param>
 /// <param name="bypass">Register more than one of the same event</param>
 public static void Register(Level.OnLevelSave method, Priority priority, Plugin plugin, bool bypass = false)
 {
     if (Find(plugin) != null)
         if (!bypass)
         throw new Exception("The user tried to register 2 of the same event!");
     events.Add(new OnLevelSaveEvent(method, priority, plugin));
     Organize();
 }
Пример #6
0
 public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
                              ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
     for (ushort y = y1; y <= y2; y++)
         for (ushort z = z1; z <= z2; z++)
             for (ushort x = x1; x <= x2; x++)
     {
         PlaceBlock(p, lvl, x, y, z, brush);
     }
 }
Пример #7
0
 public virtual bool DetermineDrawOpMethod(Level lvl, int affected) {
     if (affected > 10000) {
         method = MethodSetTile;
         return true;
     } else {
         method = lvl.bufferblocks && !lvl.Instant ?
             MethodBlockQueue : MethodBlockChange;
         return false;
     }
 }
Пример #8
0
 public static void Call(ushort x, ushort y, ushort z, byte time, string extra, Level l)
 {
     events.ForEach(delegate(OnPhysicsUpdateEvent p1)
     {
         try
         {
             p1.method(x, y, z, time, extra, l);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the LevelUnload Event!"); Server.ErrorLog(e); }
     });
 }
Пример #9
0
 public static void Call(Level l)
 {
     events.ForEach(delegate(OnLevelSaveEvent p1)
     {
         try
         {
             p1.method(l);
         }
         catch (Exception e) { Server.s.Log("The plugin " + p1.plugin.name + " errored when calling the LevelUnload Event!"); Server.ErrorLog(e); }
     });
 }
Пример #10
0
 public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
                              ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
     while (true) {
         baseOp.Perform(x1, y1, z1, x2, y1, z2, p, lvl, brush);
         if (y1 >= lvl.Height || Math.Abs(x2 - x1) <= 1 || Math.Abs(z2 - z1) <= 1)
             break;                
         x1++; x2--;
         z1++; z2--;
         y1 = (ushort)(y1 + yDir);
     }
 }
Пример #11
0
 public override int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) {
     int total = 0;
     while (true) {
         total += baseOp.GetBlocksAffected(lvl, x1, y1, z2, x2, y1, z2);
         if (y1 >= lvl.Height || Math.Abs(x2 - x1) <= 1 || Math.Abs(z2 - z1) <= 1)
             break;            
         x1++; x2--;
         z1++; z2--;
         y1 = (ushort)(y1 + yDir);
     }
     return total;
 }
Пример #12
0
        public PlayerBot(string n, Level l)
        {
            Server.s.Log("adding " + n + " bot");
            name = n;
            color = "&1";
            id = FreeId();

            level = l;
            ushort x = (ushort)((0.5 + level.spawnx) * 32);
            ushort y = (ushort)((1 + level.spawny) * 32);
            ushort z = (ushort)((0.5 + level.spawnz) * 32);
            pos = new ushort[3] { x, y, z }; rot = new byte[2] { level.rotx, level.roty };
            GlobalSpawn();
        }
Пример #13
0
 protected void PlaceBlock(Player p, Level lvl, ushort x, ushort y, ushort z, byte type, byte extType) {
     switch (method) {
         case MethodBlockQueue:
             BlockQueue.Addblock(p, x, y, z, type, extType);
             break;
         case MethodBlockChange:
             p.level.Blockchange(p, x, y, z, type, extType);
             break;
         case MethodSetTile:
             byte old = lvl.GetTile(x, y, z);
             if (old == Block.Zero || !lvl.CheckAffectPermissions(p, x, y, z, old, type))
             	return;
             p.level.SetTile(x, y, z, type, p, extType);
             break;
     }
 }
Пример #14
0
 public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
                              ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
     /* Courtesy of fCraft's awesome Open-Source'ness :D */
     double cx = (x1 + x2) / 2.0, cy = (y1 + y2) / 2.0, cz = (z1 + z2) / 2.0;
     double rx = (x2 - x1) / 2.0 + 0.25, ry = (y2 - y1) / 2.0 + 0.25, rz = (z2 - z1) / 2.0 + 0.25;
     double rx2 = 1 / (rx * rx), ry2 = 1 / (ry * ry), rz2 = 1 / (rz * rz);
     
     for (ushort yy = y1; yy <= y2; yy++)
         for (ushort zz = z1; zz <= z2; zz++)
             for (ushort xx = x1; xx <= x2; xx++)
     {
         double dx = xx - cx, dy = yy - cy, dz = zz - cz;
         if ((dx * dx) * rx2 + (dy * dy) * ry2 + (dz * dz) * rz2 <= 1)
             PlaceBlock(p, lvl, xx, yy, zz, brush);
     }
 }
Пример #15
0
 public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
                              ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
     int lenX = (x2 - x1 + 1), lenY = (y2 - y1 + 1);
     QuadY(y1, x1, z1, x2, z2, p, lvl, brush);
     QuadY(y2, x1, z1, x2, z2, p, lvl, brush);
     if (lenY > 2) {
         QuadX(x1, (ushort)(y1 + 1), z1, (ushort)(y2 - 1), z2, p, lvl, brush);
         QuadX(x2, (ushort)(y1 + 1), z1, (ushort)(y2 - 1), z2, p, lvl, brush);
     }
     if (lenX > 2 && lenY > 2) {
         QuadZ(z1, (ushort)(x1 + 1), (ushort)(y1 + 1),
               (ushort)(x2 - 1), (ushort)(y2 - 1), p, lvl, brush);
         QuadZ(z2, (ushort)(x1 + 1), (ushort)(y1 + 1),
               (ushort)(x2 - 1), (ushort)(y2 - 1), p, lvl, brush);
     }
 }
Пример #16
0
 public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
                              ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
     for (ushort y = y1; y <= y2; y++)
         for (ushort z = z1; z <= z2; z++)
     {
         int i = (y & 1) == 0 ? 0 : 1;
         if ((z & 1) == 0) i++;
         
         for (ushort x = x1; x <= x2; x++) {
             if ((i & 1) == 0)
             	PlaceBlock(p, lvl, x, y, z, brush);
             else
             	PlaceBlock(p, lvl, x, y, z, Block.air, 0);
             i++;
         }
     }
 }
Пример #17
0
 public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
                              ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
     ReplaceBlock[] toReplace = ToReplace;
     ReplaceBlock target = Target;
     for (ushort y = y1; y <= y2; y++)
         for (ushort z = z1; z <= z2; z++)
             for (ushort x = x1; x <= x2; x++)
     {
         byte tile = lvl.GetTile(x, y, z), extTile = 0;
         if (tile == Block.custom_block)
             extTile = lvl.GetExtTile(x, y, z);
         
         for (int i = 0; i < toReplace.Length; i++) {
             ReplaceBlock block = toReplace[i];
             if (tile != block.Type || (tile == Block.custom_block && extTile != block.ExtType)) {
                 PlaceBlock(p, lvl, x, y, z, target.Type, target.ExtType); break;
             }
         }
     }
 }
Пример #18
0
        public void AddCactus(Level Lvl, ushort x, ushort y, ushort z, Random Rand, bool blockChange = false, bool overwrite = true, Player p = null)
        {
            byte height = (byte)Rand.Next(3, 6);
            ushort yy;

            for (yy = 0; yy <= height; yy++)
            {
                if (overwrite || Lvl.GetTile(z, (ushort)(y + yy), z) == Block.air)
                    if (blockChange)
                        if (p == null) Lvl.Blockchange(x, (ushort)(y + yy), z, Block.green);
                        else Lvl.Blockchange(p, x, (ushort)(y + yy), z, Block.green);
                    else Lvl.skipChange(x, (ushort)(y + yy), z, Block.green);
            }

            int inX = 0, inZ = 0;

            switch (Rand.Next(1, 3))
            {
                case 1: inX = -1; break;
                case 2:
                default: inZ = -1; break;
            }

            for (yy = height; yy <= Rand.Next(height + 2, height + 5); yy++)
            {
                if (overwrite || Lvl.GetTile((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ)) == Block.air)
                    if (blockChange)
                        if (p == null) Lvl.Blockchange((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green);
                        else Lvl.Blockchange(p, (ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green);
                    else Lvl.skipChange((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ), Block.green);
            }
            for (yy = height; yy <= Rand.Next(height + 2, height + 5); yy++)
            {
                if (overwrite || Lvl.GetTile((ushort)(x + inX), (ushort)(y + yy), (ushort)(z + inZ)) == Block.air)
                    if (blockChange)
                        if (p == null) Lvl.Blockchange((ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green);
                        else Lvl.Blockchange(p, (ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green);
                    else Lvl.skipChange((ushort)(x - inX), (ushort)(y + yy), (ushort)(z - inZ), Block.green);
            }
        }
Пример #19
0
 public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
                              ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
     /* Courtesy of fCraft's awesome Open-Source'ness :D */
     double cx = (x1 + x2) / 2.0, cy = (y1 + y2) / 2.0, cz = (z1 + z2) / 2.0;
     double rx = (x2 - x1) / 2.0 + 0.25, ry = (y2 - y1) / 2.0 + 0.25, rz = (z2 - z1) / 2.0 + 0.25;
     double rx2 = 1 / (rx * rx), ry2 = 1 / (ry * ry), rz2 = 1 / (rz * rz);
     
     double smallrx2 = 1 / ((rx - 1) * (rx - 1));
     double smallry2 = 1 / ((ry - 1) * (ry - 1));
     double smallrz2 = 1 / ((rz - 1) * (rz - 1));
     
     for (ushort yy = y1; yy <= y2; yy++)
         for (ushort zz = z1; zz <= z2; zz++)
             for (ushort xx = x1; xx <= x2; xx++)
     {
         double dx = xx - cx, dy = yy - cy, dz = zz - cz;
         dx *= dx; dy *= dy; dz *= dz;
         bool inRange = dx * rx2 + dy * ry2 + dz * rz2 <= 1;
         if (inRange && (dx * smallrx2 + dy * smallry2 + dz * smallrz2 > 1))
         	PlaceBlock(p, lvl, xx, yy, zz, brush);
     }
 }
Пример #20
0
 public static TntWarsGame Find(Level level)
 {
     return GameList.FirstOrDefault(g => g.lvl == level);
 }
Пример #21
0
        public void Start()
        {

            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 { }
                if (!File.Exists("MySql.Data.dll"))
                {
                    Log("MySql.Data.dll doesn't exist, Downloading");
                    try
                    {
                        using (WebClient WEB = new WebClient())
                        {
                            WEB.DownloadFile("https://github.com/Hetal728/MCGalaxy/blob/master/MySql.Data.dll?raw=true", "MySql.Data.dll");
                        }
                        if (File.Exists("MySql.Data.dll"))
                        {
                            Log("MySql.Data.dll download succesful!");
                        }
                    }
                    catch
                    {
                        Log("Downloading MySql.Data.dll failed, please try again later");
                    }
                }
                if (!File.Exists("System.Data.SQLite.dll"))
                {
                    Log("System.Data.SQLite.dll doesn't exist, Downloading");
                    try
                    {
                        using (WebClient WEB = new WebClient())
                        {
                            WEB.DownloadFile("https://github.com/Hetal728/MCGalaxy/blob/master/System.Data.SQLite.dll?raw=true", "System.Data.SQLite.dll");
                        }
                        if (File.Exists("System.Data.SQLite.dll"))
                        {
                            Log("System.Data.SQLite.dll download succesful!");
                        }
                    }
                    catch
                    {
                        Log("Downloading System.Data.SQLite.dll failed, please try again later");
                    }
                }
                if (!File.Exists("sqlite3.dll"))
                {
                    Log("sqlite3.dll doesn't exist, Downloading");
                    try
                    {
                        using (WebClient WEB = new WebClient())
                        {
                            WEB.DownloadFile("https://github.com/Hetal728/MCGalaxy/blob/master/sqlite3.dll?raw=true", "sqlite3.dll");
                        }
                        if (File.Exists("sqlite3.dll"))
                        {
                            Log("sqlite3.dll download succesful!");
                        }
                    }
                    catch
                    {
                        Log("Downloading sqlite3.dll failed, please try again later");
                    }
                }
                if (!File.Exists("Newtonsoft.Json.dll"))
                {
                	Log("Newtonsoft.Json.dll doesn't exist, Downloading");
                	try
                	{
                		using (WebClient WEB = new WebClient())
                		{
                            WEB.DownloadFile("https://github.com/Hetal728/MCGalaxy/blob/master/Newtonsoft.Json/Newtonsoft.Json.dll?raw=true", "Newtonsoft.Json.dll");
                		}
                		if (File.Exists("Newtonsoft.Json.dll"))
                		{
                			Log("Newtonsoft.Json.dll download successful!");
                		}
                	}
                	catch
                	{
                		Log("Download Newtonsoft.Json.dll failed, please try again later");
                	}
                }
            }
            //UpdateGlobalSettings();
            if (!Directory.Exists("properties")) Directory.CreateDirectory("properties");
            if (!Directory.Exists("levels")) Directory.CreateDirectory("levels");
            if (!Directory.Exists("bots")) Directory.CreateDirectory("bots");
            if (!Directory.Exists("text")) Directory.CreateDirectory("text");
            if (!File.Exists("text/tempranks.txt")) File.CreateText("text/tempranks.txt").Dispose();
            if (!File.Exists("text/rankinfo.txt")) File.CreateText("text/rankinfo.txt").Dispose();
            if (!File.Exists("text/transexceptions.txt")) File.CreateText("text/transexceptions.txt").Dispose();
            if (!File.Exists("text/gcaccepted.txt")) File.CreateText("text/gcaccepted.txt").Dispose();
            if (!File.Exists("text/bans.txt")) File.CreateText("text/bans.txt").Dispose();
            // DO NOT STICK ANYTHING IN BETWEEN HERE!!!!!!!!!!!!!!!
            else
            {
                string bantext = File.ReadAllText("text/bans.txt");
                if (!bantext.Contains("%20") && bantext != "")
                {
                    bantext = bantext.Replace("~", "%20");
                    bantext = bantext.Replace("-", "%20");
                    File.WriteAllText("text/bans.txt", bantext);
                }
            }



            if (!Directory.Exists("extra")) Directory.CreateDirectory("extra");
            if (!Directory.Exists("extra/undo")) Directory.CreateDirectory("extra/undo");
            if (!Directory.Exists("extra/undoPrevious")) Directory.CreateDirectory("extra/undoPrevious");
            if (!Directory.Exists("extra/copy/")) { Directory.CreateDirectory("extra/copy/"); }
            if (!Directory.Exists("extra/copyBackup/")) { Directory.CreateDirectory("extra/copyBackup/"); }
            if (!Directory.Exists("extra/Waypoints")) { Directory.CreateDirectory("extra/Waypoints"); }

            try
            {
                if (File.Exists("server.properties")) File.Move("server.properties", "properties/server.properties");
                if (File.Exists("rules.txt")) File.Move("rules.txt", "text/rules.txt");
                if (File.Exists("welcome.txt")) File.Move("welcome.txt", "text/welcome.txt");
                if (File.Exists("messages.txt")) File.Move("messages.txt", "text/messages.txt");
                if (File.Exists("externalurl.txt")) File.Move("externalurl.txt", "text/externalurl.txt");
                if (File.Exists("autoload.txt")) File.Move("autoload.txt", "text/autoload.txt");
                if (File.Exists("IRC_Controllers.txt")) File.Move("IRC_Controllers.txt", "ranks/IRC_Controllers.txt");
                if (useWhitelist) if (File.Exists("whitelist.txt")) File.Move("whitelist.txt", "ranks/whitelist.txt");
            }
            catch { }

            if (File.Exists("text/custom$s.txt"))
            {
                using (StreamReader r = new StreamReader("text/custom$s.txt"))
                {
                    string line;
                    while ((line = r.ReadLine()) != null)
                    {
                        if (line.StartsWith("//")) continue;
                        var split = line.Split(new[] { ':' }, 2);
                        if (split.Length == 2 && !String.IsNullOrEmpty(split[0]))
                        {
                            customdollars.Add(split[0], split[1]);
                        }
                    }
                }
            }
            else
            {
                s.Log("custom$s.txt does not exist, creating");
                using (StreamWriter SW = File.CreateText("text/custom$s.txt"))
                {
                    SW.WriteLine("// This is used to create custom $s");
                    SW.WriteLine("// If you start the line with a // it wont be used");
                    SW.WriteLine("// It should be formatted like this:");
                    SW.WriteLine("// $website:mcgalaxy.ml");
                    SW.WriteLine("// That would replace '$website' in any message to 'mcgalaxy.ml'");
                    SW.WriteLine("// It must not start with a // and it must not have a space between the 2 sides and the colon (:)");
                    SW.Close();
                }
            }

            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();
            }


            // LavaSurvival constructed here...
            lava = new LavaSurvival();

            zombie = new ZombieGame();

            LoadAllSettings();

            //derp
            if (!Server.LevelList.Contains("#(Must be comma seperated, no spaces. Must have changing levels and use level list enabled.)"))
                Server.LevelList.Add("#(Must be comma seperated, no spaces. Must have changing levels and use level list enabled.)");

            // OmniBan
            omniban = new OmniBan();

            timeOnline = DateTime.Now;
            {//MYSQL stuff
                try
                {
                    Database.executeQuery("CREATE DATABASE if not exists `" + MySQLDatabaseName + "`", true); // works in both now, SQLite simply ignores this.
                }
                //catch (MySql.Data.MySqlClient.MySqlException e)
                //{
                //    Server.s.Log("MySQL settings have not been set! Many features will not be available if MySQL is not enabled");
                //  //  Server.ErrorLog(e);
                //}
                catch (Exception e)
                {
                    ErrorLog(e);
                    s.Log("MySQL settings have not been set! Please Setup using the properties window.");
                    //process.Kill();
                    return;
                }
                Database.executeQuery(string.Format("CREATE TABLE if not exists Players (ID INTEGER {0}AUTO{1}INCREMENT NOT NULL, Name TEXT, IP CHAR(15), FirstLogin DATETIME, LastLogin DATETIME, totalLogin MEDIUMINT, Title CHAR(20), TotalDeaths SMALLINT, Money MEDIUMINT UNSIGNED, totalBlocks BIGINT, totalCuboided BIGINT, totalKicked MEDIUMINT, TimeSpent VARCHAR(20), color VARCHAR(6), title_color VARCHAR(6){2});", (useMySQL ? "" : "PRIMARY KEY "), (useMySQL ? "_" : ""), (Server.useMySQL ? ", PRIMARY KEY (ID)" : "")));
                Database.executeQuery(string.Format("CREATE TABLE if not exists Opstats (ID INTEGER {0}AUTO{1}INCREMENT NOT NULL, Time DATETIME, Name TEXT, Cmd VARCHAR(40), Cmdmsg VARCHAR(40){2});", (useMySQL ? "" : "PRIMARY KEY "), (useMySQL ? "_" : ""), (Server.useMySQL ? ", PRIMARY KEY (ID)" : "")));
                if (!File.Exists("extra/alter.txt") && Server.useMySQL) {
                	Database.executeQuery("ALTER TABLE Players MODIFY Name TEXT");
                	Database.executeQuery("ALTER TABLE Opstats MODIFY Name TEXT");
                	File.Create("extra/alter.txt");
                }
                //since 5.5.11 we are cleaning up the table Playercmds
                string query = Server.useMySQL ? "SHOW TABLES LIKE 'Playercmds'" : "SELECT name FROM sqlite_master WHERE type='table' AND name='Playercmds';";
                DataTable playercmds = Database.fillData(query); DataTable opstats = Database.fillData("SELECT * FROM Opstats");
                //if Playercmds exists copy-filter to Ostats and remove Playercmds
                if (playercmds.Rows.Count != 0) {
                    foreach (string cmd in Server.Opstats)
                        Database.executeQuery(string.Format("INSERT INTO Opstats (Time, Name, Cmd, Cmdmsg) SELECT Time, Name, Cmd, Cmdmsg FROM Playercmds WHERE cmd = '{0}';", cmd));
                    Database.executeQuery("INSERT INTO Opstats (Time, Name, Cmd, Cmdmsg) SELECT Time, Name, Cmd, Cmdmsg FROM Playercmds WHERE cmd = 'review' AND cmdmsg = 'next';");
                    Database.fillData("DROP TABLE Playercmds");
                }
                playercmds.Dispose(); opstats.Dispose();

                // Here, since SQLite is a NEW thing from 5.3.0.0, we do not have to check for existing tables in SQLite.
                if (useMySQL)
                {
                    // Check if the color column exists.
                    DataTable colorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='color'");

                    if (colorExists.Rows.Count == 0)
                    {
                        MySQL.executeQuery("ALTER TABLE Players ADD COLUMN color VARCHAR(6) AFTER totalKicked");
                        //else SQLite.executeQuery("ALTER TABLE Players ADD COLUMN color VARCHAR(6) AFTER totalKicked");
                    }
                    colorExists.Dispose();

                    // Check if the title color column exists.
                    DataTable tcolorExists = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='title_color'");

                    if (tcolorExists.Rows.Count == 0)
                    {
                        MySQL.executeQuery("ALTER TABLE Players ADD COLUMN title_color VARCHAR(6) AFTER color");
                        // else SQLite.executeQuery("ALTER TABLE Players ADD COLUMN title_color VARCHAR(6) AFTER color");
                    }
                    tcolorExists.Dispose();

                    DataTable timespent = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='TimeSpent'");

                    if (timespent.Rows.Count == 0)
                        MySQL.executeQuery("ALTER TABLE Players ADD COLUMN TimeSpent VARCHAR(20) AFTER totalKicked"); //else SQLite.executeQuery("ALTER TABLE Players ADD COLUMN TimeSpent VARCHAR(20) AFTER totalKicked");
                    timespent.Dispose();

                    DataTable totalCuboided = MySQL.fillData("SHOW COLUMNS FROM Players WHERE `Field`='totalCuboided'");

                    if (totalCuboided.Rows.Count == 0)
                        MySQL.executeQuery("ALTER TABLE Players ADD COLUMN totalCuboided BIGINT AFTER totalBlocks"); //else SQLite.executeQuery("ALTER TABLE Players ADD COLUMN totalCuboided BIGINT AFTER totalBlocks");
                    totalCuboided.Dispose();
                }
            }

            Economy.LoadDatabase();
            UpdateStaffList();

            if (levels != null)
                foreach (Level l in levels) { l.Unload(); }
            ml.Queue(delegate
            {
                try
                {
                    levels = new List<Level>(maps);
                    MapGen = new RealisticMapGen();

                    if (File.Exists("levels/" + level + ".lvl"))
                    {
                        mainLevel = Level.Load(level);
                        mainLevel.unload = false;
                        if (mainLevel == null)
                        {
                            if (File.Exists("levels/" + level + ".lvl.backup"))
                            {
                                Log("Attempting to load backup of " + level + ".");
                                File.Copy("levels/" + level + ".lvl.backup", "levels/" + level + ".lvl", true);
                                mainLevel = Level.Load(level);
                                if (mainLevel == null)
                                {
                                    Log("BACKUP FAILED!");
                                    Console.ReadLine(); return;
                                }
                            }
                            else
                            {
                                Log("mainlevel not found");
                                mainLevel = new Level(level, 128, 64, 128, "flat") { permissionvisit = LevelPermission.Guest, permissionbuild = LevelPermission.Guest };
                                mainLevel.Save();
                                Level.CreateLeveldb(level);
                            }
                        }
                        //Wom Textures
                        if (UseTextures)
                        {
                            mainLevel.textures.sendwomid = true;
                            mainLevel.textures.enabled = true;
                            mainLevel.textures.MOTD = motd;
                            mainLevel.textures.CreateCFG();
                        }
                    }
                    else
                    {
                        Log("mainlevel not found");
                        mainLevel = new Level(level, 128, 64, 128, "flat") { permissionvisit = LevelPermission.Guest, permissionbuild = LevelPermission.Guest };
                        mainLevel.Save();
                        Level.CreateLeveldb(level);
                    }

                    addLevel(mainLevel);

                    // fenderrock - Make sure the level does have a physics thread
                    if (mainLevel.physThread == null)
                        mainLevel.StartPhysics();
                }
                catch (Exception e) { ErrorLog(e); }
            });
            Plugin.Load();
            ml.Queue(delegate
            {
                bannedIP = PlayerList.Load("banned-ip.txt", null);
                ircControllers = PlayerList.Load("IRC_Controllers.txt", null);
                muted = PlayerList.Load("muted.txt", null);

                foreach (Group grp in Group.GroupList)
                    grp.playerList = PlayerList.Load(grp.fileName, grp);
                if (useWhitelist)
                    whiteList = PlayerList.Load("whitelist.txt", null);
                if (!File.Exists("ranks/jailed.txt")) { File.Create("ranks/jailed.txt").Close(); Server.s.Log("CREATED NEW: ranks/jailed.txt"); }
                Extensions.UncapitalizeAll("ranks/banned.txt");
                Extensions.UncapitalizeAll("ranks/muted.txt");
            });

            ml.Queue(delegate
            {
                if (File.Exists("text/autoload.txt"))
                {
                    try
                    {
                        string[] lines = File.ReadAllLines("text/autoload.txt");
                        foreach (string _line in lines.Select(line => line.Trim()))
                        {
                            try
                            {
                                if (_line == "") { continue; }
                                if (_line[0] == '#') { continue; }

                                string key = _line.Split('=')[0].Trim();
                                string value;
                                try
                                {
                                    value = _line.Split('=')[1].Trim();
                                }
                                catch
                                {
                                    value = "0";
                                }

                                if (!key.Equals(mainLevel.name))
                                {
                                    Command.all.Find("load").Use(null, key + " " + value);
                                    Level l = Level.FindExact(key);
                                }
                                else
                                {
                                    try
                                    {
                                        int temp = int.Parse(value);
                                        if (temp >= 0 && temp <= 3)
                                        {
                                            mainLevel.setPhysics(temp);
                                        }
                                    }
                                    catch
                                    {
                                        s.Log("Physics variable invalid");
                                    }
                                }


                            }
                            catch
                            {
                                s.Log(_line + " failed.");
                            }
                        }
                    }
                    catch
                    {
                        s.Log("autoload.txt error");
                    }
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                else
                {
                    Log("autoload.txt does not exist");
                }
            });

            ml.Queue(delegate
            {
                foreach (string line in File.ReadAllLines("text/gcaccepted.txt"))
                {
                    gcaccepted.Add(line); //loading all playernames of people who turned off translation
                }
                Log("Creating listening socket on port " + port + "... ");
                Setup();
                //s.Log(Setup() ? "Done." : "Could not create socket connection. Shutting down.");
            });

            ml.Queue(delegate
            {
                updateTimer.Elapsed += delegate
                {
                    Player.GlobalUpdate();
                    PlayerBot.GlobalUpdatePosition();
                };

                updateTimer.Start();
            });


            // Heartbeat code here:

            ml.Queue(delegate
            {
                try
                {
                    Heart.Init();
                }
                catch (Exception e)
                {
                    Server.ErrorLog(e);
                }
            });

            ml.Queue(delegate
            {
                messageTimer.Elapsed += delegate
                {
                    RandomMessage();
                };
                messageTimer.Start();

                if (File.Exists("text/messages.txt"))
                {
                    using (StreamReader r = File.OpenText("text/messages.txt"))
                    {
                        while (!r.EndOfStream)
                            messages.Add(r.ReadLine());
                    }
                }
                else File.Create("text/messages.txt").Close();

                try
                {
                    APIServer = new WebServer(SendResponse, "http://localhost:8080/api/");
                    APIServer.Run();
                    InfoServer = new WebServer(WhoIsResponse, "http://localhost:8080/whois/");
                    InfoServer.Run();
                }
                catch
                {
                    Server.s.Log("Failed to start local API server");
                }

                IRC = new ForgeBot(Server.ircChannel, Server.ircOpChannel, Server.ircNick, Server.ircServer);
                GlobalChat = new GlobalChatBot(GlobalChatNick());

                if (Server.irc) IRC.Connect();
                if (Server.UseGlobalChat) GlobalChat.Connect();

                // OmniBan stuff!
                new Thread(new ThreadStart(() => omniban.Load(true))).Start();

                omnibanCheckTimer.Elapsed += delegate
                {
                    omniban.Load(true);
                    omniban.KickAll();
                };
                omnibanCheckTimer.Start();


                new AutoSaver(Server.backupInterval);

                blockThread = new Thread(new ThreadStart(delegate
                {
                    while (true)
                    {
                        Thread.Sleep(blockInterval * 1000);
                        try {
                            levels.ForEach(
                                delegate(Level l) {
                                    try {
                                        l.saveChanges();
                                    } catch (Exception e) {
                                        Server.ErrorLog(e);
                                    }
                                });
                        } catch (Exception e) {
                            // an exception is raised on Mono if level list is modified
                            // while enumerating over it with ForEach
                            Server.ErrorLog(e);
                        }
                    }
                }));
                blockThread.Name = "MCG_BlockUpdates";
                blockThread.Start();

                locationChecker = new Thread(new ThreadStart(delegate
                {
                    Player p, who;
                    ushort x, y, z;
                    int i;
                    while (true)
                    {
                        Thread.Sleep(3);
                        for (i = 0; i < Player.players.Count; i++)
                        {
                            try
                            {
                                p = Player.players[i];

                                if (p.frozen)
                                {
                                    unchecked { p.SendPos((byte)-1, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]); } continue;
                                }
                                else if (p.following != "")
                                {
                                    who = Player.Find(p.following);
                                    if (who == null || who.level != p.level)
                                    {
                                        p.following = "";
                                        if (!p.canBuild)
                                        {
                                            p.canBuild = true;
                                        }
                                        if (who != null && who.possess == p.name)
                                        {
                                            who.possess = "";
                                        }
                                        continue;
                                    }
                                    if (p.canBuild)
                                    {
                                        unchecked { p.SendPos((byte)-1, who.pos[0], (ushort)(who.pos[1] - 16), who.pos[2], who.rot[0], who.rot[1]); }
                                    }
                                    else
                                    {
                                        unchecked { p.SendPos((byte)-1, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1]); }
                                    }
                                }
                                else if (p.possess != "")
                                {
                                    who = Player.Find(p.possess);
                                    if (who == null || who.level != p.level)
                                        p.possess = "";
                                }

                                x = (ushort)(p.pos[0] / 32);
                                y = (ushort)(p.pos[1] / 32);
                                z = (ushort)(p.pos[2] / 32);

                                if (p.level.Death)
                                    p.RealDeath(x, y, z);
                                p.CheckBlock(x, y, z);

                                p.oldBlock = (ushort)(x + y + z);
                            }
                            catch (Exception e) { Server.ErrorLog(e); }
                        }
                    }
                }));
                locationChecker.Name = "MCG_LocationCheck";
                locationChecker.Start();
#if DEBUG
	  UseTextures = true;          
#endif
                Log("Finished setting up server");
                ServerSetupFinished = true;
                Checktimer.StartTimer();
                Commands.CommandKeywords.SetKeyWords();
                try
                {
                    if (Server.lava.startOnStartup)
                        Server.lava.Start();
                    if (Server.startZombieModeOnStartup)
                        Server.zombie.StartGame(1, 0);
                    //This doesnt use the main map
                    if (Server.UseCTF)
                        ctf = new Auto_CTF();
                }
                catch (Exception e) { Server.ErrorLog(e); }
                BlockQueue.Start();
            });
        }
Пример #22
0
        public byte Stop()
        {
            if (!active) return 1; // Not started

            if (OnGameStop != null)
                OnGameStop();
            active = false;
            roundActive = false;
            voteActive = false;
            flooded = false;
            deaths.Clear();
            if (announceTimer.Enabled) announceTimer.Stop();
            try { mapData.Dispose(); }
            catch { }
            try { voteTimer.Dispose(); }
            catch { }
            try { transferTimer.Dispose(); }
            catch { }
            map.Unload(true, false);
            map = null;
            Server.s.Log("[Lava Survival] Game stopped.");
            return 0;
        }
Пример #23
0
 internal OnLevelSaveEvent(Level.OnLevelSave method, Priority priority, Plugin plugin)
 {
     this.plugin = plugin; this.priority = priority; this.method = method;
 }
Пример #24
0
 public static void GlobalBlockchange(Level level, int b, byte type, byte extType) {
     ushort x, y, z;
     level.IntToPos(b, out x, out y, out z);
     GlobalBlockchange(level, x, y, z, type, extType);
 }
Пример #25
0
 protected void PlaceBlock(Player p, Level lvl, ushort x, ushort y, ushort z, Brush brush) {
 	byte type = brush.NextBlock();
     if (type == Block.Zero) return;
     PlaceBlock(p, lvl, x, y, z, type, brush.NextExtBlock());
 }
Пример #26
0
 public static void GlobalBlockchange(Level level, ushort x, ushort y, ushort z, byte type, byte extType) {
     players.ForEach(delegate(Player p) { if ( p.level == level ) { p.SendBlockchange(x, y, z, type, extType); } });
 }
Пример #27
0
 public abstract void Perform(ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2,
                              Player p, Level lvl, Brush brush);
Пример #28
0
 public abstract int GetBlocksAffected(Level lvl, ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2);
Пример #29
0
        public void LoadMap(string name)
        {
            if (String.IsNullOrEmpty(name) || !HasMap(name)) return;

            name = name.ToLower();
            Level oldMap = null;
            if (active && map != null) oldMap = map;
            Command.all.Find("load").Use(null, name);
            map = Level.Find(name);

            if (map != null)
            {
                mapSettings = LoadMapSettings(name);
                mapData = GenerateMapData(mapSettings);

                map.setPhysics(mapData.destroy ? 2 : 1);
                map.motd = "Lava Survival: " + map.name.Capitalize();
                map.overload = 1000000;
                map.unload = false;
                map.loadOnGoto = false;
                Level.SaveSettings(map);
            }
            
            if (active && map != null)
            {
                sendingPlayers = true;
                try
                {
                    Player.players.ForEach(delegate(Player pl)
                    {
                        if (pl.level == oldMap)
                        {
                            if (sendAfkMain && Server.afkset.Contains(pl.name)) Command.all.Find("main").Use(pl, "");
                            else Command.all.Find("goto").Use(pl, map.name);
                        }
                    });
                    if (OnMapChange != null)
                        OnMapChange(oldMap, map);
                    oldMap.Unload(true, false);
                }
                catch { }
                sendingPlayers = false;

                StartRound();
            }
        }
Пример #30
0
 //======PLUGIN EVENTS======
 public TntWarsGame(Level level)
 {
     Starter = new Thread(Start);
     lvl = level;
 }