Beispiel #1
0
 public static bool hasDays(ref TmpEntry entry)
 {
     using (MySqlConnection connection = sql.iniHandle()) {
         using (MySqlCommand command = connection.CreateCommand()) {
             if (sql.open(connection))
             {
                 command.CommandText = "SELECT `days` FROM `consoles` WHERE `cpukey`=@cpukey";
                 command.Parameters.AddWithValue("@cpukey", entry.CPUKey);
                 using (MySqlDataReader reader = command.ExecuteReader()) {
                     if (reader.Read())
                     {
                         if (Convert.ToInt32(reader[0]) > 0)
                         {
                             return(true);
                         }
                         else
                         {
                             return(false);
                         }
                     }
                 }
             }
             return(false);
         }
     }
 }
Beispiel #2
0
 public static bool getConsole(ref TmpEntry entry, bool getConsoleBySession = false) // arg = clientSalt or CPUKey depending on the session bool.
 {
     using (MySqlConnection connection = SQL.iniHandle()) {
         using (MySqlCommand command = connection.CreateCommand()) {
             if (SQL.open(connection))
             {
                 command.CommandText = String.Format("SELECT * FROM `consoles` WHERE `{0}`=@arg", getConsoleBySession ? "session" : "cpukey");
                 command.Parameters.AddWithValue("@arg", getConsoleBySession ? entry.ClientSession : entry.CPUKey);
                 using (MySqlDataReader reader = command.ExecuteReader()) {
                     if (reader.Read())
                     {
                         entry.ClientName      = (string)reader["name"];
                         entry.ClientEnabled   = (bool)reader["enabled"];
                         entry.ClientBanned    = (bool)reader["isbanned"];
                         entry.ClientXeXChecks = (bool)reader["xexchecks"];
                         entry.daysLeft        = (int)reader["days"];
                         entry.CPUKey          = getConsoleBySession ? (string)reader["cpukey"] : entry.CPUKey;
                         entry.ClientSession   = !getConsoleBySession ? (!reader.IsDBNull(reader.GetOrdinal("session")) ? (string)reader["session"] : "") : entry.ClientSession;
                         entry.KVDat           = !reader.IsDBNull(reader.GetOrdinal("kvdata")) ? (byte[])reader["kvdata"] : null;
                         connection.Close();
                         return(true);
                     }
                 }
             }
             return(false);
         }
     }
 }
Beispiel #3
0
 // Adding the time, then removing the day we added from `days`
 public static void AddTime(ref TmpEntry entry)
 {
     using (MySqlConnection connection = sql.iniHandle()) {
         using (MySqlCommand command = connection.CreateCommand()) {
             if (sql.open(connection))
             {
                 command.CommandText = "UPDATE `consoles` SET `time`=DATE_ADD(NOW(), INTERVAL 1 DAY ), `days`=days-1, `enabled`=1 WHERE `cpukey`=@cpukey";
                 command.Parameters.AddWithValue("@cpukey", entry.CPUKey);
                 command.ExecuteNonQuery();
                 connection.Close();
             }
         }
     }
 }
Beispiel #4
0
 // If true, we can notify the user.
 public static bool canIncrimentTime(ref TmpEntry entry)
 {
     try {
         if (!timeLeft(ref entry))
         {
             if (hasDays(ref entry))
             {
                 AddTime(ref entry);
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex) { /*Globals.write("Exception canIncrimentTime: {0}", ex.Message);*/ return(false); }
 }
Beispiel #5
0
 public static void saveToken(ref TmpEntry entry)
 {
     using (MySqlConnection connection = SQL.iniHandle()) {
         using (MySqlCommand command = connection.CreateCommand()) {
             if (SQL.open(connection))
             {
                 command.CommandText = "UPDATE `tokens` SET `used`=1, `timeused`=NOW(), `cpukey`=@cpukey WHERE `tid`=@tid";
                 command.Parameters.AddWithValue("@cpukey", entry.CPUKey);
                 command.Parameters.AddWithValue("@tid", entry.TokenID);
                 command.ExecuteNonQuery();
                 connection.Close();
             }
         }
     }
 }
Beispiel #6
0
 // Checking if they have time left, if so, we don't add more time.
 public static bool timeLeft(ref TmpEntry entry)
 {
     using (MySqlConnection connection = sql.iniHandle()) {
         using (MySqlCommand command = connection.CreateCommand()) {
             if (sql.open(connection))
             {
                 command.CommandText = "SELECT (CASE WHEN NOW() <= `time` THEN 1 ELSE 0 END) FROM `consoles` WHERE `cpukey`=@cpukey";
                 command.Parameters.AddWithValue("@cpukey", entry.CPUKey);
                 using (MySqlDataReader reader = command.ExecuteReader())
                     if (reader.Read())
                     {
                         return(Convert.ToBoolean(reader[0]));
                     }
             }
             return(true);
         }
     }
 }
Beispiel #7
0
 public static void updateOtherConsoles(ref TmpEntry entry, bool banned = false) // For BANNED and FAILED connections
 {
     try {
         using (MySqlConnection connection = SQL.iniHandle()) {
             using (MySqlCommand command = connection.CreateCommand()) {
                 if (SQL.open(connection))
                 {
                     command.CommandText = String.Format("INSERT INTO `{0}` (`ip`, `kvdata`, `cpukey`) VALUES (@ipaddr, @kvdata, @cpukey) ON DUPLICATE KEY UPDATE `ip`=@ipaddr, `kvdata`=@kvdata", banned ? "banned" : "failed");
                     command.Parameters.AddWithValue("@cpukey", entry.CPUKey);
                     command.Parameters.AddWithValue("@ipaddr", entry.ClientIP);
                     command.Parameters.AddWithValue("@kvdata", entry.KVDat);
                     command.ExecuteNonQuery();
                     connection.Close();
                 }
             }
         }
     } catch (MySqlException ex) { Globals.write("MySQL Exception: {0} || {1}", ex.Message, ex.InnerException); }
 }
Beispiel #8
0
 public static bool addAnon(ref TmpEntry entry) // Inserting an anonymous user and giving them time.
 {
     try {
         using (MySqlConnection connection = SQL.iniHandle()) {
             using (MySqlCommand command = connection.CreateCommand()) {
                 if (SQL.open(connection))
                 {
                     command.CommandText = "INSERT INTO `anon` (`ip`, `cpukey`, `name`, `time`) VALUES (@ip, @cpukey, 'Anon', DATE_ADD(NOW(), INTERVAL 9999 DAY ))";
                     command.Parameters.AddWithValue("@ip", entry.ClientIP);
                     command.Parameters.AddWithValue("@cpukey", entry.CPUKey);
                     command.ExecuteNonQuery();
                     connection.Close();
                     return(true);
                 }
             }
         } return(false);
     } catch { Globals.write("Anon [{0}] addAnon Failed! CPUKey: {1}", entry.ClientIP, entry.CPUKey); return(false); }
 }
Beispiel #9
0
 public static void saveConsole(ref TmpEntry entry) // Globally used save console information for clients.
 {
     using (MySqlConnection connection = SQL.iniHandle()) {
         using (MySqlCommand command = connection.CreateCommand()) {
             if (SQL.open(connection))
             {
                 command.CommandText = "UPDATE `consoles` SET `salt`=@salt, `session`=@session, `enabled`=@enabled, `ip`=@ipaddr, `titleid`=@titleid, `gamertag`=@gt, `lastseen`=NOW() WHERE `cpukey`=@cpukey";
                 command.Parameters.AddWithValue("@salt", entry.ClientSalt);
                 command.Parameters.AddWithValue("@session", entry.ClientSession);
                 command.Parameters.AddWithValue("@enabled", entry.ClientEnabled);
                 command.Parameters.AddWithValue("@ipaddr", entry.ClientIP);
                 command.Parameters.AddWithValue("@titleid", entry.ClientTitle);
                 command.Parameters.AddWithValue("@gt", entry.ClientGT);
                 command.Parameters.AddWithValue("@cpukey", entry.CPUKey);
                 command.ExecuteNonQuery();
                 connection.Close();
             }
         }
     }
 }
Beispiel #10
0
 public static bool autoUpdateTime(ref TmpEntry entry) // Update to the original 24 hour timer.
 {
     if (getConsole(ref entry))
     {
         Globals.write("F**K {0} Days Left | {1}", entry.daysLeft, (bool)(DateTime.Now <= entry.ClientTime));
         if (entry.daysLeft >= 1 && !(entry.ClientTime >= DateTime.Now))   // See if they have time left. No need to open a connection where none is needed.
         {
             using (MySqlConnection connection = SQL.iniHandle()) {
                 using (MySqlCommand command = connection.CreateCommand()) {
                     if (SQL.open(connection))
                     {
                         command.CommandText = "UPDATE `consoles` SET `time`=DATE_ADD(NOW(), INTERVAL 1 DAY ), `days`=days-1, `enabled`=1 WHERE `cpukey`=@cpukey";
                         command.Parameters.AddWithValue("@cpukey", entry.CPUKey);
                         command.ExecuteNonQuery();
                         connection.Close();
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
Beispiel #11
0
 public static bool getToken(ref TmpEntry entry)
 {
     using (MySqlConnection connection = SQL.iniHandle()) {
         using (MySqlCommand command = connection.CreateCommand()) {
             if (SQL.open(connection))
             {
                 command.CommandText = "SELECT * FROM `tokens` WHERE `token`=@token";
                 command.Parameters.AddWithValue("@token", entry.inToken);
                 using (MySqlDataReader reader = command.ExecuteReader()) {
                     if (reader.Read())
                     {
                         entry.outToken  = (string)reader["token"];
                         entry.TokenUsed = (bool)reader["used"];
                         entry.TokenDays = (int)reader["days"];
                         entry.TokenID   = (int)reader["tid"];
                         connection.Close();
                         return(true);
                     }
                 }
             }
             return(false);
         }
     }
 }