Exemple #1
0
 public SaveCommand( TSPlayer p, TileQueue t )
 {
     ply = p;
     tileQueue = t;
 }
Exemple #2
0
 public Logger(TileQueue tq)
 {
     tileQueue = tq;
 }
Exemple #3
0
        public void StartLogTile()
        {
            queue = new TileQueue(this);
            log = new Logger(queue);
            helper = new TileHelper();
            com = new Commands(log);

            if (TShock.Config.StorageType.ToLower() == "sqlite")
            {
                string sql = Path.Combine(TShock.SavePath, "logtile.sqlite");
                DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
            }
            else if (TShock.Config.StorageType.ToLower() == "mysql")
            {
                try
                {
                    var hostport = TShock.Config.MySqlHost.Split(':');
                    DB = new MySqlConnection();
                    DB.ConnectionString =
                        String.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};",
                                      hostport[0],
                                      hostport.Length > 1 ? hostport[1] : "3306",
                                      TShock.Config.MySqlDbName,
                                      TShock.Config.MySqlUsername,
                                      TShock.Config.MySqlPassword
                            );
                }
                catch (MySqlException ex)
                {
                    Log.Error(ex.ToString());
                    throw new Exception("MySql not setup correctly");
                }
            }
            else
            {
                throw new Exception("Invalid storage type");
            }
            var table = new SqlTable("LogTile",
                                     new SqlColumn("id", MySqlDbType.Int32) {Primary = true, AutoIncrement = true},
                                     new SqlColumn("X", MySqlDbType.Int32),
                                     new SqlColumn("Y", MySqlDbType.Int32),
                                     new SqlColumn("IP", MySqlDbType.Int32),
                                     new SqlColumn("Name", MySqlDbType.Text),
                                     new SqlColumn("Action", MySqlDbType.Int32),
                                     new SqlColumn("TileType", MySqlDbType.Int32),
                                     new SqlColumn("Date", MySqlDbType.Int32)
                );
            var creator = new SqlTableCreator(DB,
                                              DB.GetSqlType() == SqlType.Sqlite
                                              	? (IQueryBuilder) new SqliteQueryCreator()
                                              	: new MysqlQueryCreator());
            creator.EnsureExists(table);

            logThread = new Thread(log.SaveTimer);
            CommandQueueThread = new Thread( CommandQueue.ProcessQueue);

            logThread.Start();
            CommandQueueThread.Start();

            queue.addHook();
            com.addHook();

            fileWriter = new Thread(ConfigFileManager);
            fileWriter.Start();
        }
Exemple #4
0
 public Logger(TileQueue tq)
 {
     tileQueue = tq;
 }
Exemple #5
0
 public SaveCommand(TSPlayer p, TileQueue t)
 {
     ply       = p;
     tileQueue = t;
 }
Exemple #6
0
        public void StartLogTile()
        {
            queue  = new TileQueue(this);
            log    = new Logger(queue);
            helper = new TileHelper();
            com    = new Commands(log);

            if (TShock.Config.StorageType.ToLower() == "sqlite")
            {
                string sql = Path.Combine(TShock.SavePath, "logtile.sqlite");
                DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
            }
            else if (TShock.Config.StorageType.ToLower() == "mysql")
            {
                try
                {
                    var hostport = TShock.Config.MySqlHost.Split(':');
                    DB = new MySqlConnection();
                    DB.ConnectionString =
                        String.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};",
                                      hostport[0],
                                      hostport.Length > 1 ? hostport[1] : "3306",
                                      TShock.Config.MySqlDbName,
                                      TShock.Config.MySqlUsername,
                                      TShock.Config.MySqlPassword
                                      );
                }
                catch (MySqlException ex)
                {
                    Log.Error(ex.ToString());
                    throw new Exception("MySql not setup correctly");
                }
            }
            else
            {
                throw new Exception("Invalid storage type");
            }
            var table = new SqlTable("LogTile",
                                     new SqlColumn("id", MySqlDbType.Int32)
            {
                Primary = true, AutoIncrement = true
            },
                                     new SqlColumn("X", MySqlDbType.Int32),
                                     new SqlColumn("Y", MySqlDbType.Int32),
                                     new SqlColumn("IP", MySqlDbType.Int32),
                                     new SqlColumn("Name", MySqlDbType.Text),
                                     new SqlColumn("Action", MySqlDbType.Int32),
                                     new SqlColumn("TileType", MySqlDbType.Int32),
                                     new SqlColumn("Date", MySqlDbType.Int32)
                                     );
            var creator = new SqlTableCreator(DB,
                                              DB.GetSqlType() == SqlType.Sqlite
                                                                ? (IQueryBuilder) new SqliteQueryCreator()
                                                                : new MysqlQueryCreator());

            creator.EnsureExists(table);

            logThread          = new Thread(log.SaveTimer);
            CommandQueueThread = new Thread(CommandQueue.ProcessQueue);

            logThread.Start();
            CommandQueueThread.Start();

            queue.addHook();
            com.addHook();

            fileWriter = new Thread(ConfigFileManager);
            fileWriter.Start();
        }