public void OnUserRequestDesKey(Client client) { if (OPT.SettingExists("des.key")) { string desKey = OPT.GetString("des.key"); PacketStream stream = new PacketStream(0x9999); stream.WriteString(desKey); if (OPT.GetBool("debug")) { Console.WriteLine("[{0}] Sent!", desKey); } ClientManager.Instance.Send(client, stream); } else { Console.WriteLine("Failed to find des.key in settings!"); } }
internal void OnUserRequestFile(Client client, string fileName) { if (OPT.GetBool("debug")) { Console.WriteLine("Client [{0}] requested file: {1}", client.Id, fileName); } string updatePath = string.Format(@"{0}\{1}", updatesDir, fileName); string archiveName = compressFile(updatePath); string archivePath = string.Format(@"{0}\{1}.zip", Program.tmpPath, archiveName); if (File.Exists(archivePath)) { ClientPackets.Instance.SC_SendFile(client, archivePath); } }
internal void OnRequestFileInfo(Client client, string fileName) { if (OPT.GetBool("debug")) { Console.WriteLine("Client [{0}] requested file info for: {1}", client.Id, fileName); } string updatePath = string.Format(@"{0}\{1}", IndexManager.UpdatesDirectory, fileName); string archiveName = compressFile(updatePath); string archivePath = string.Format(@"{0}\{1}.zip", Program.tmpPath, archiveName); if (File.Exists(archivePath)) { ClientPackets.Instance.SC_SendFileInfo(client, archiveName, new FileInfo(archivePath).Length); } else /*TODO: Send File Does Not Exist Error?*/ } {
public void LoadUpdateList() { switch (OPT.GetInt("send.type")) { case 0: // Google drive using (StreamReader sr = new StreamReader(File.Open(string.Format(@"{0}\{1}", Directory.GetCurrentDirectory(), "gIndex.opt"), FileMode.Open, FileAccess.Read))) { string line; while ((line = sr.ReadLine()) != null) { string[] optBlocks = line.Split('|'); if (optBlocks.Length == 4) { UpdateIndex.Add(new IndexEntry { FileName = optBlocks[0], SHA512 = optBlocks[1], Legacy = Convert.ToBoolean(Convert.ToInt32(optBlocks[2])), Delete = Convert.ToBoolean(Convert.ToInt32(optBlocks[3])) }); } } } break; case 1: // HTTP break; case 2: // FTP break; case 3: // TCP foreach (string filePath in Directory.GetFiles(updatesDir)) { string fileName = Path.GetFileName(filePath); UpdateIndex.Add(new IndexEntry { FileName = fileName, SHA512 = Hash.GetSHA512Hash(filePath), Legacy = OPT.IsLegacy(fileName), Delete = OPT.IsDelete(fileName) }); } break; } }
internal void OnRequestResourceUpdateIndex(Client client) { if (Program.Wait) { ClientPackets.Instance.SC_SendWait(client, ClientPackets.Instance.currentPacketId, OPT.GetInt("wait.period")); } else { List <IndexEntry> filteredIndex = IndexManager.Filter(FilterType.Resource); foreach (IndexEntry indexEntry in filteredIndex) { ClientPackets.Instance.SC_SendResourceEntry(client, indexEntry.FileName, indexEntry.SHA512, indexEntry.Delete); } ClientPackets.Instance.SC_SendResourceIndexEOF(client); } }
public void OnRequestDataUpdateIndex(Client client) { if (Program.Wait) { ClientPackets.Instance.SC_SendWait(client, ClientPackets.Instance.currentPacketId, OPT.GetInt("wait.period")); } else { List <IndexEntry> filteredIndex = IndexManager.Filter(FilterType.Data); foreach (IndexEntry indexEntry in filteredIndex) { ClientPackets.Instance.SC_SendDataEntry(client, indexEntry.FileName, indexEntry.SHA512); } ClientPackets.Instance.SC_SendDataIndexEOF(client); } }
public void OnValidateUser(Client client, string username, string password, string fingerprint) { if (debug) { Console.WriteLine("Client [{0}] requested login validation with the following credentials:", client.Id); Console.WriteLine("Username: {0}\nPassword: {1}\nFingerprint: {2}", username, password, fingerprint); } // Check if username / password exist using (SqlConnection sqlCon = Database.Connection) { SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = sqlCon; sqlCmd.CommandText = string.Format("SELECT account_id FROM dbo.{0} WHERE login_name = @name AND password = @password", OPT.GetString("db.auth.table.alias")); sqlCmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = username; sqlCmd.Parameters.Add("@password", SqlDbType.NVarChar).Value = PasswordCipher.CreateHash(OPT.GetString("md5.key"), password); if (debug) { Console.Write("\t-Checking for Account..."); } object result = Database.ExecuteStatement(sqlCmd, 1); if (debug) { Console.WriteLine(((int)result > 0) ? "[FOUND]" : "[NOT FOUND]"); } if ((int)result > 0) // Account exists { int account_id = (int)result; if (debug) { Console.Write("\t-Checking Account ban status..."); } // Check if account is banned sqlCmd.CommandText = string.Format("SELECT ban FROM dbo.{0} WHERE login_name = @name AND password = @password", OPT.GetString("db.auth.table.alias")); result = Database.ExecuteStatement(sqlCmd, 1); if (debug) { Console.WriteLine(((int)result == 0) ? "[NOT BANNED]" : "[BANNED]"); } if ((int)result == 0) // Account is not banned { if (debug) { Console.Write("\t-Checking for FingerPrint..."); } // Check for fingerprint sqlCmd.CommandText = "SELECT COUNT(account_id) FROM dbo.FingerPrint WHERE account_id = @account_id"; sqlCmd.Parameters.Clear(); sqlCmd.Parameters.Add("@account_id", SqlDbType.Int).Value = account_id; result = Database.ExecuteStatement(sqlCmd, 1); if (debug) { Console.WriteLine(((int)result == 1) ? "[FOUND]" : "[NOT FOUND]"); } if ((int)result == 1) // FingerPrint exists { if (debug) { Console.Write("\t-Checking FingerPrint ban status..."); } // Check if FingerPrint is banned sqlCmd.CommandText = "SELECT ban FROM dbo.FingerPrint WHERE account_id = @account_id"; result = Database.ExecuteStatement(sqlCmd, 1); if (debug) { Console.WriteLine(((int)result == 0) ? "[NOT BANNED]" : "[BANNED]"); } if ((int)result == 0) // FingerPrint is not banned { setOTP(ref client, ref sqlCmd, account_id); } else // FingerPrint is banned { if (debug) { Console.Write("\t-Checking if FingerPrint ban is expired..."); } // Get OTP Expiration Date sqlCmd.CommandText = "SELECT expiration_date FROM dbo.FingerPrint WHERE account_id = @account_id"; sqlCmd.Parameters.Clear(); sqlCmd.Parameters.Add("@account_id", SqlDbType.Int).Value = account_id; result = Database.ExecuteStatement(sqlCmd, 1); if ((DateTime)result < DateTime.Now) // Ban is up { if (debug) { Console.WriteLine("[EXPIRED]\n\t-Updating FingerPrint ban..."); } sqlCmd.CommandText = "UPDATE dbo.FingerPrint SET ban = 0 WHERE account_id = @account_id"; result = Database.ExecuteStatement(sqlCmd, 0); if (debug) { Console.WriteLine(((int)result == 1) ? "[SUCCESS]" : "[FAIL]"); } setOTP(ref client, ref sqlCmd, account_id); } else { ClientPackets.Instance.SC_SendBanStatus(client, 1); } } } else { if (debug) { Console.Write("\t-Inserting FingerPrint: {0}...", fingerprint); } sqlCmd.CommandText = "INSERT INTO dbo.FingerPrint (account_id, finger_print, ban, expiration_date) VALUES (@account_id, @finger_print, @ban, @expiration_date)"; sqlCmd.Parameters.Clear(); sqlCmd.Parameters.Add("@account_id", SqlDbType.Int).Value = account_id; sqlCmd.Parameters.Add("@finger_print", SqlDbType.NVarChar).Value = fingerprint; sqlCmd.Parameters.Add("@ban", SqlDbType.Int).Value = 0; sqlCmd.Parameters.Add("@expiration_date", SqlDbType.DateTime).Value = new DateTime(1999, 1, 1, 12, 0, 0, 0); result = Database.ExecuteStatement(sqlCmd, 0); if (debug) { Console.WriteLine(((int)result == 1) ? "[SUCCESS]" : "[FAIL]"); } } } else { ClientPackets.Instance.SC_SendBanStatus(client, 0); } // Account is banned } else { ClientPackets.Instance.SC_SendAccountNull(client); } // Account doesn't exist } }
internal void OnUserRequestArguments(Client client) { string arguments = string.Format("/auth_ip:{0} /auth_port:{1} /locale:? country:? /use_nprotect:0 /cash /commercial_shop /allow_double_exec:{2}", OPT.GetString("auth.io.ip"), OPT.GetString("auth.io.port"), OPT.GetString("double.execute")); if (OPT.GetBool("imbc.login")) { arguments += "/imbclogin /account:? /password:?"; } ClientPackets.Instance.SC_SendArguments(client, arguments, OPT.GetInt("sframe.bypass")); }
internal void OnAuthenticationTypeRequest(Client client) { ClientPackets.Instance.SC_SendAuthenticationType(client, OPT.GetInt("imbc.login")); }
public UserHandler() { debug = OPT.GetBool("debug"); }
internal void OnUserRequestArguments(Client client) { ClientPackets.Instance.SC_SendArguments(client, string.Format("/auth_ip:{0} /auth_port:{1} /locale:? /country:? /use_nprotect:0 /cash /commercial_shop /allow_double_exec:1 /imbclogin /account:? /password:?", OPT.GetString("auth.io.ip"), OPT.GetString("auth.io.port")); }
public static void Build(bool rebuild) { if (rebuild && OPT.GetBool("debug")) { Console.Write("Rebuilding the Update Index..."); } else { Console.Write("Building the Update Index..."); } Program.Wait = true; if (Index.Count > 0) { Index.Clear(); } switch (OPT.GetInt("send.type")) { case 0: // Google drive using (StreamReader sr = new StreamReader(File.Open(string.Format(@"{0}\{1}", System.IO.Directory.GetCurrentDirectory(), "gIndex.opt"), FileMode.Open, FileAccess.Read))) { //string line; //while ((line = sr.ReadLine()) != null) //{ // string[] optBlocks = line.Split('|'); // if (optBlocks.Length == 4) // { // Index.Add(new IndexEntry { FileName = optBlocks[0], SHA512 = optBlocks[1], Legacy = Convert.ToBoolean(Convert.ToInt32(optBlocks[2])), Delete = Convert.ToBoolean(Convert.ToInt32(optBlocks[3])) }); // } //} } break; case 1: // HTTP break; case 2: // FTP break; case 3: // TCP foreach (string filePath in System.IO.Directory.GetFiles(UpdatesDirectory)) { string fileName = Path.GetFileName(filePath); Index.Add(new IndexEntry { FileName = fileName, SHA512 = Hash.GetSHA512Hash(filePath), Legacy = OPT.IsLegacy(fileName), Delete = OPT.IsDelete(fileName) }); } break; } if (rebuild && OPT.GetBool("debug")) { Console.WriteLine("[OK]\n\t{0} files indexed", Count); } else { Console.WriteLine("[OK]\n\t{0} files indexed", Count); } Program.Wait = false; }
public static void Build(bool rebuild) { Output.WriteAndLock(new Message() { Text = string.Format("{0} the Update Index...", (rebuild && OPT.GetBool("debug")) ? "Rebuilding" : "Building") }); if (rebuild) { Program.Wait = true; } if (Index.Count > 0) { Index.Clear(); } switch (OPT.GetInt("send.type")) { case 0: // Google drive using (StreamReader sr = new StreamReader(File.Open(string.Format(@"{0}\{1}", System.IO.Directory.GetCurrentDirectory(), "gIndex.opt"), FileMode.Open, FileAccess.Read))) { //string line; //while ((line = sr.ReadLine()) != null) //{ // string[] optBlocks = line.Split('|'); // if (optBlocks.Length == 4) // { // Index.Add(new IndexEntry { FileName = optBlocks[0], SHA512 = optBlocks[1], Legacy = Convert.ToBoolean(Convert.ToInt32(optBlocks[2])), Delete = Convert.ToBoolean(Convert.ToInt32(optBlocks[3])) }); // } //} } break; case 1: // HTTP break; case 2: // FTP break; case 3: // TCP foreach (string filePath in System.IO.Directory.GetFiles(UpdatesDirectory)) { string fileName = Path.GetFileName(filePath); Index.Add(new IndexEntry { FileName = fileName, SHA512 = Hash.GetSHA512Hash(filePath), Legacy = OPT.IsLegacy(fileName), Delete = OPT.IsDelete(fileName) }); } break; } if (OPT.GetBool("debug")) { Output.WriteAndUnlock(new Message() { Text = string.Format("[OK]\n\t- {0} files indexed", Count), AddBreak = true }); } if (rebuild) { Program.Wait = false; } GUI.Instance.Invoke(new System.Windows.Forms.MethodInvoker(delegate { GUI.Instance.updatesViewBtn.Enabled = true; GUI.Instance.updatesView.Enabled = true; })); }