Пример #1
0
 public static bool Increment(ref Tmp.Entry Entry, bool Check = false)
 {
     if (Get(ref Entry))
     {
         if (Entry.Days >= 1 && !Entry.Enabled)
         {
             if (Check)
             {
                 return(true);
             }
             using (MySqlConnection Connection = SQL.iniHandle()) {
                 using (MySqlCommand Command = Connection.CreateCommand()) {
                     if (SQL.Open(Connection))
                     {
                         Command.CommandText = "UPDATE `consoles` SET `expire`=DATE_ADD(NOW(), INTERVAL 1 DAY), `daysLeft`=`daysLeft`-1, `enabled`=1, `daysUsed`=`daysUsed`+1 WHERE `id`=@id;";
                         Command.Parameters.AddWithValue("@id", Entry.ID);
                         Command.ExecuteNonQuery();
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
Пример #2
0
 public static bool Get(ref Tmp.Entry Entry, bool GetBySession = false)
 {
     using (MySqlConnection Connection = SQL.iniHandle()) {
         using (MySqlCommand Command = Connection.CreateCommand()) {
             if (SQL.Open(Connection))
             {
                 Command.CommandText = String.Format("SELECT * FROM `consoles` WHERE `{0}`=@arg;", GetBySession ? "session" : "cpukey");
                 Command.Parameters.AddWithValue("@arg", GetBySession ? Entry.Session : Entry.CPUKey);
                 using (MySqlDataReader Reader = Command.ExecuteReader()) {
                     if (Reader.Read())
                     {
                         Entry.Session   = GetBySession ? Entry.Session : (string)Reader["session"];
                         Entry.CPUKey    = (string)Reader["cpukey"];
                         Entry.Name      = (string)Reader["name"];
                         Entry.Suspended = (bool)Reader["suspended"];
                         Entry.Lifetime  = (bool)Reader["lifetime"];
                         Entry.Enabled   = (bool)Reader["enabled"];
                         Entry.Banned    = (bool)Reader["banned"];
                         Entry.Days      = (int)Reader["daysLeft"];
                         Entry.Used      = (int)Reader["daysUsed"];
                         Entry.ID        = (int)Reader["id"];
                         Entry.Expire    = Convert.ToDateTime(Reader["expire"]);
                         return(true);
                     }
                 }
             }
             return(false);
         }
     }
 }
Пример #3
0
        public static void Update(ref Tmp.Entry Entry, EndianIO WriterIO, EndianIO ReaderIO)
        {
            Entry.Session  = ReaderIO.Reader.ReadBytes(0x10).ToHex();
            Entry.Title    = ReaderIO.Reader.ReadBytes(0x4).ToHex();
            Entry.GamerTag = ReaderIO.Reader.ReadBytes(0x15).ToString();

            if (ClientSQL.Get(ref Entry, true))
            {
                if (Entry.Enabled)
                {
                    WriterIO.Writer.Write((uint)respCode.RESP_SUCCESS);
                }
                else
                {
                    if (ClientSQL.Increment(ref Entry, true))
                    {
                        if (Entry.AutoIncrement)
                        {
                            ClientSQL.Increment(ref Entry);
                        }
                        WriterIO.Writer.Write(Entry.AutoIncrement ? (Entry.noto_DayStarted ? (uint)respCode.RESP_DAY_STARTED : (uint)respCode.RESP_SUCCESS) : (uint)respCode.RESP_REBOOT);
                    }
                    else
                    {
                        WriterIO.Writer.Write((uint)respCode.RESP_ERROR);
                    }
                } ClientSQL.Set(ref Entry);
            }
        }
Пример #4
0
        public static void Get(ref Tmp.Entry Entry, EndianIO WriterIO, EndianIO ReaderIO)
        {
            Entry.Session    = ReaderIO.Reader.ReadBytes(0x10).ToHex();
            Entry.ClientHash = ReaderIO.Reader.ReadBytes(0x10);

            if (ClientSQL.Get(ref Entry, true))
            {
                if (!Entry.Enabled)
                {
                    GlobalFunc.WriteError(ConsoleColor.DarkGray, "Client [{0}]", "{1} has expired.", Entry.IP, Entry.Name);
                    WriterIO.Writer.Write((uint)respCode.RESP_EXPIRED);
                }

                if (!GlobalVar.b_xexChecks)
                {
                    GlobalFunc.WriteError(ConsoleColor.Red, "[SERVER]", "XEX Checks are disabled!");
                    WriterIO.Writer.Write((uint)respCode.RESP_SUCCESS);
                }

                if (Entry.Checks)
                {
                    if (BitsNBytes.ByteCompare(Entry.ClientHash, HMAC.SHA1(GlobalVar.by_xexBytes, Entry.Session.ToByte(), 0, 16)))
                    {
                        GlobalFunc.WriteError(ConsoleColor.Green, "Client [{0}]", "{1} passed checks.", Entry.IP, Entry.Name);
                        WriterIO.Writer.Write((uint)respCode.RESP_SUCCESS);
                    }
                    else
                    {
                        GlobalFunc.WriteError(ConsoleColor.Yellow, "Client [{0}]", "Out of date client! Sending update.", Entry.IP);
                        WriterIO.Writer.Write((uint)respCode.RESP_UPDATE);
                        WriterIO.Writer.Write(GlobalVar.by_xexBytes.Length);
                        WriterIO.Writer.Write(GlobalVar.by_xexBytes);
                    }
                }
                else
                {
                    GlobalFunc.WriteError(ConsoleColor.DarkYellow, "[ADMIN]", "Admin has omitted checks on user.");
                    WriterIO.Writer.Write((uint)respCode.RESP_SUCCESS);
                }
            }
            else
            {
                GlobalFunc.WriteError(ConsoleColor.Red, "[UNAUTHORIZED]", "Unknown client. IP: {0}", Entry.IP);
                WriterIO.Writer.Write((uint)respCode.RESP_ERROR);
            }
        }
Пример #5
0
 public static bool Set(ref Tmp.Entry Entry)
 {
     try {
         using (MySqlConnection Connection = SQL.iniHandle()) {
             using (MySqlCommand Command = Connection.CreateCommand()) {
                 if (SQL.Open(Connection))
                 {
                     Command.CommandText = "UPDATE `consoles` SET `ip`=@ip, `gamertag`=@gt, `titleID`=@title, `session`=@session, `lastSeen`=NOW() WHERE `cpukey`=@cpukey;";
                     Command.Parameters.AddWithValue("@ip", Entry.IP);
                     Command.Parameters.AddWithValue("@gt", Entry.GamerTag);
                     Command.Parameters.AddWithValue("@title", Entry.Title);
                     Command.Parameters.AddWithValue("@session", Entry.Session);
                     Command.Parameters.AddWithValue("@cpukey", Entry.CPUKey);
                     Command.ExecuteNonQuery();
                     return(true);
                 }
                 return(false);
             }
         }
     } catch { return(false); }
 }
Пример #6
0
        public static void Get(ref Tmp.Entry Entry, EndianIO WriterIO, EndianIO ReaderIO)
        {
            bool conType = Convert.ToBoolean(ReaderIO.Reader.ReadInt32());

            Entry.CPUKey = ReaderIO.Reader.ReadBytes(0x10).ToHex();

            if (ClientSQL.Get(ref Entry))
            {
                Entry.Session = BitsNBytes.RandomBytes(0x10).ToHex();
                if (Entry.Enabled)
                {
                    GlobalFunc.Write("Client [{0}] {1}'s {2} Authorized!", Entry.IP, Entry.Name, conType ? "Devkit" : "Jtag/RGH");
                    WriterIO.Writer.Write((uint)respCode.RESP_STEALTHED);
                    WriterIO.Writer.Write(Entry.Session.ToByte());
                }
                else
                {
                    if (ClientSQL.Increment(ref Entry, true))
                    {
                        if (Entry.AutoIncrement)
                        {
                            if (ClientSQL.Increment(ref Entry))
                            {
                                if (Entry.noto_AskDayStart && Entry.noto_DayStarted)
                                {
                                    // ask about starting the day
                                    if (/*Asking result*/ true == false)
                                    {
                                        WriterIO.Writer.Write((uint)respCode.RESP_EXPIRED);
                                    }
                                    WriterIO.Writer.Write((uint)respCode.RESP_DAY_STARTED);
                                }
                                else if (Entry.noto_DayStarted)
                                {
                                    if (Entry.Lifetime)
                                    {
                                        WriterIO.Writer.Write((uint)respCode.RESP_STEALTHED);                 // Responds without notification
                                    }
                                    else
                                    {
                                        WriterIO.Writer.Write((uint)respCode.RESP_DAY_STARTED);
                                    }
                                }
                                else if (!Entry.noto_DayStarted)
                                {
                                    WriterIO.Writer.Write((uint)respCode.RESP_STEALTHED); // Responds without notification
                                }
                                WriterIO.Writer.Write(Entry.Session.ToByte());
                            }
                            else
                            {
                                GlobalFunc.WriteError(ConsoleColor.DarkGray, "Client [{0}]", "{1}'s Time Expired!", Entry.IP, Entry.Name);
                                WriterIO.Writer.Write((uint)respCode.RESP_EXPIRED);
                            }
                        }
                        else
                        {
                            GlobalFunc.WriteError(ConsoleColor.DarkGray, "Client [{0}]", "{1} opted out of incrementing a day.", Entry.IP, Entry.Name);
                            WriterIO.Writer.Write((uint)respCode.RESP_REBOOT);
                        }
                    }
                }
            }
            else
            {
                // who duh fuk u be
            }
        }