internal bool RequestExists(int requestID) { if (requests.ContainsKey(requestID)) { return(true); } using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT sender FROM messenger_friendships WHERE sender = @myID AND receiver = @friendID"); dbClient.addParameter("myID", (int)this.UserId); dbClient.addParameter("friendID", (int)requestID); return(dbClient.findsResult()); } }
public bool RequestExists(int requestID) { if (_requests.ContainsKey(requestID)) { return(true); } using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT user_one_id FROM messenger_friendships WHERE user_one_id = @myID AND user_two_id = @friendID"); dbClient.AddParameter("myID", Convert.ToInt32(_userId)); dbClient.AddParameter("friendID", Convert.ToInt32(requestID)); return(dbClient.findsResult()); } }
internal bool RequestExists(uint requestID) { if (this.requests.ContainsKey(requestID)) { return(true); } checked { bool result; using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor.setQuery("SELECT user_one_id FROM messenger_friendships WHERE user_one_id = @myID AND user_two_id = @friendID"); queryreactor.addParameter("myID", (int)this.UserId); queryreactor.addParameter("friendID", (int)requestID); result = queryreactor.findsResult(); } return(result); } }
internal static void Initialize() { PrettyVersion = string.Format("Firewind {0}", Assembly.GetExecutingAssembly().GetName().Version); Console.Clear(); DateTime Start = DateTime.Now; SystemMute = false; ServerStarted = DateTime.Now; Console.Title = "Firewind: Loading environment."; Logging.WriteWithColor(" _______ __ __ __ ", ConsoleColor.Cyan); Logging.WriteWithColor(" | ___|__|.----.-----.--.--.--.|__|.-----.--| |", ConsoleColor.Cyan); Logging.WriteWithColor(" | ___| || _| -__| | | || || | _ |", ConsoleColor.Cyan); Logging.WriteWithColor(" |___| |__||__| |_____|________||__||__|__|_____|", ConsoleColor.Cyan); Logging.WriteLine(""); Logging.WriteLine("=============================================================="); DefaultEncoding = Encoding.Default; Logging.WriteLine(" " + PrettyVersion); Logging.WriteLine(string.Format(" Licenced to {0}", LicenseHolder)); Logging.WriteLine(string.Format(" Maximum players: {0}", MaxUsers == 0 ? "Unlimited!" : MaxUsers.ToString())); Logging.WriteLine(""); Logging.WriteLine(" Go to the GitHub repo for bug reporting/contributions!"); cultureInfo = CultureInfo.CreateSpecificCulture("en-GB"); IsDebugging = IsDebugging ? System.Diagnostics.Debugger.IsAttached : false; try { LanguageLocale.Init(); ChatCommandRegister.Init(); PetCommandHandeler.Init(); PetLocale.Init(); if (IsDebugging) { Configuration = new ConfigurationData(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"Settings_test/configuration.ini")); } else { Configuration = new ConfigurationData(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"Settings/configuration.ini")); } DateTime Starts = DateTime.Now; Logging.WriteLine("Connecting to database..."); manager = new DatabaseManager(uint.Parse(FirewindEnvironment.GetConfig().data["db.pool.maxsize"]), int.Parse(FirewindEnvironment.GetConfig().data["db.pool.minsize"])); manager.setServerDetails( FirewindEnvironment.GetConfig().data["db.hostname"], uint.Parse(FirewindEnvironment.GetConfig().data["db.port"]), FirewindEnvironment.GetConfig().data["db.username"], FirewindEnvironment.GetConfig().data["db.password"], FirewindEnvironment.GetConfig().data["db.name"]); manager.init(); TimeSpan TimeUsed2 = DateTime.Now - Starts; Logging.WriteLine("Connected to database! (" + TimeUsed2.Seconds + " s, " + TimeUsed2.Milliseconds + " ms)"); LanguageLocale.InitSwearWord(); friendRequestLimit = (uint)(int.Parse(FirewindEnvironment.GetConfig().data["client.maxrequests"])); Game = new Game(int.Parse(FirewindEnvironment.GetConfig().data["game.tcp.conlimit"])); Game.ContinueLoading(); ConnectionManager = new ConnectionHandling(int.Parse(FirewindEnvironment.GetConfig().data["game.tcp.port"]), MaxUsers, int.Parse(FirewindEnvironment.GetConfig().data["game.tcp.conperip"]), FirewindEnvironment.GetConfig().data["game.tcp.enablenagles"].ToLower() == "true"); ConnectionManager.init(); ConnectionManager.Start(); StaticClientMessageHandler.Initialize(); ClientMessageFactory.Init(); string[] arrayshit = FirewindEnvironment.GetConfig().data["mus.tcp.allowedaddr"].Split(';'); MusSystem = new RConListener(FirewindEnvironment.GetConfig().data["mus.tcp.bindip"], int.Parse(FirewindEnvironment.GetConfig().data["mus.tcp.port"]), arrayshit, 0); useSSO = true; if (Configuration.data.ContainsKey("auth.ssodisabled")) { if (Configuration.data["auth.ssodisabled"] == "false") { useSSO = false; } } if (Configuration.data.ContainsKey("spambans.enabled")) { if (Configuration.data["spambans.enabled"] == "true") { spamBans = true; spamBans_limit = Convert.ToInt32(Configuration.data["spambans.limit"]); Logging.WriteLine("Spam Bans enabled"); } } if (Configuration.data.ContainsKey("SeparatedTasksInMainLoops.enabled")) { if (Configuration.data["SeparatedTasksInMainLoops.enabled"] == "true") { SeparatedTasksInMainLoops = true; Logging.WriteLine("MultiTasking in MainLoop"); } } if (Configuration.data.ContainsKey("SeparatedTasksInGameClientManager.enabled")) { if (Configuration.data["SeparatedTasksInGameClientManager.enabled"] == "true") { SeparatedTasksInGameClientManager = true; Logging.WriteLine("MultiTasking in ClientManager"); } } TimeSpan TimeUsed = DateTime.Now - Start; Logging.WriteWithColor("Firewind -> READY! (" + TimeUsed.Seconds + " s, " + TimeUsed.Milliseconds + " ms)", ConsoleColor.Cyan); isLive = true; if (System.Diagnostics.Debugger.IsAttached) { Logging.WriteLine("Server is debugging: Console writing enabled", true); } else { Logging.WriteLine("Server is not debugging: Console writing disabled", false); Logging.DisablePrimaryWriting(false); } } catch (KeyNotFoundException e) { Logging.WriteLine("Please check your configuration file - some values appear to be missing."); Logging.WriteLine("Press any key to shut down ..."); Logging.WriteLine(e.ToString()); Console.ReadKey(true); FirewindEnvironment.Destroy(); return; } catch (InvalidOperationException e) { Logging.WriteLine("Failed to initialize Firewind Emulator: " + e.Message); Logging.WriteLine("Press any key to shut down ..."); Console.ReadKey(true); FirewindEnvironment.Destroy(); return; } catch (Exception e) { Logging.WriteLine("Fatal error during startup: " + e.ToString()); Logging.WriteLine("Press a key to exit"); Console.ReadKey(); Environment.Exit(1); } // Check if this is habin or not try { using (IQueryAdapter dbClient = manager.getQueryreactor()) { dbClient.setQuery("SELECT column_name FROM information_schema.columns WHERE table_schema = '" + FirewindEnvironment.GetConfig().data["db.name"] + "' AND table_name = 'users' AND column_name = 'hpo'"); IsHabin = dbClient.findsResult(); } } catch { } }
internal void Chat(GameClient Session, string Message, bool Shout) { if (Session != null) { if (Session.GetHabbo().Rank < 5) { if (GetRoom().RoomMuted) { return; } } } Unidle(); if (!IsPet && !IsBot) { Users.Habbo clientUser = GetClient().GetHabbo(); if (clientUser.Muted) { GetClient().SendNotif("You are muted."); return; } if (Message.StartsWith(":") && Session != null) { string[] parsedCommand = Message.Split(' '); if (ChatCommandRegister.IsChatCommand(parsedCommand[0].ToLower().Substring(1))) { try { ChatCommandHandler handler = new ChatCommandHandler(Message.Split(' '), Session); if (handler.WasExecuted()) { //Logging.LogMessage(string.Format("User {0} issued command {1}", GetUsername(), Message)); if (Session.GetHabbo().Rank > 5) { FirewindEnvironment.GetGame().GetModerationTool().LogStaffEntry(Session.GetHabbo().Username, string.Empty, "Chat command", string.Format("Issued chat command {0}", Message)); } return; } } catch (Exception x) { Logging.LogException("In-game command error: " + x.ToString()); } } if (FirewindEnvironment.IsHabin) { bool result; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id FROM users WHERE (hpo = '1' OR hpo = '1' OR hds = '1' OR hmg = '1' OR hmb = '1' OR ele = '1' OR lar = '1') AND username = @name"); dbClient.addParameter("name", Session.GetHabbo().Username); result = dbClient.findsResult(); string command = parsedCommand[0].Substring(1); // F**k this command system, we make our own! switch (command) { case "relationship": if (!result) { Session.SendMOTD("Du må være medlem av Mafia eller Police for å ha kommandoene til forhold."); break; } dbClient.setQuery("SELECT sender_id FROM users_relationships WHERE (recipent_id = @myid OR sender_id = @myid) AND accepted = '0'"); dbClient.addParameter("myid", Session.GetHabbo().Id); if (dbClient.findsResult()) { Session.SendMOTD("Du har allerede spurt om et forhold med denne personen, vennligst vent på et svar."); return; } dbClient.setQuery("SELECT id FROM users WHERE username = @name"); dbClient.addParameter("name", parsedCommand[1]); int id = dbClient.getInteger(); dbClient.setQuery("INSERT IGNORE INTO users_relationships(sender_id,recipent_id) VALUES(@myid,@hisid)"); dbClient.addParameter("myid", Session.GetHabbo().Id); dbClient.addParameter("hisid", id); dbClient.runQuery(); Session.SendMOTD("Du har sendt en forespørsel til " + parsedCommand[1]); return; case "mystatus": if (!result) { Session.SendMOTD("Du må være medlem av Mafia eller Police for å ha kommandoene til forhold."); break; } if (false) { Session.SendMOTD("Du er i et forhold med {0}, vil du avslutte forholdet skriv :remove {0}"); return; } StringBuilder statusMessage = new StringBuilder(); statusMessage.AppendLine("Du har følgende forespørsler:"); dbClient.setQuery("SELECT sender_id FROM users_relationships WHERE accepted = '0' AND recipent_id = @myid LIMIT 6"); dbClient.addParameter("myid", Session.GetHabbo().Id); DataTable table = dbClient.getTable(); foreach (DataRow row in table.Rows) { statusMessage.AppendLine(FirewindEnvironment.getHabboForId(Convert.ToUInt32(row[0])).Username); } statusMessage.AppendLine("Du kan maks ha 6 forespørsler på en gang."); statusMessage.AppendLine("Skriv :accept navn for å akseptere en forespørsel."); Session.SendMOTD(statusMessage.ToString()); return; case "accept": if (!result) { Session.SendMOTD("Du må være medlem av Mafia eller Police for å ha kommandoene til forhold."); break; } dbClient.setQuery("SELECT sender_id FROM users_relationships WHERE (recipent_id = @myid OR sender_id = @myid) AND accepted = '1'"); dbClient.addParameter("myid", Session.GetHabbo().Id); if (dbClient.findsResult()) { Session.SendMOTD("Du er allerede i et forhold!"); return; } dbClient.setQuery("UPDATE users_relationships SET accepted = '1' WHERE sender_id = @sid AND recipent_id = @myid LIMIT 1"); dbClient.addParameter("myid", Session.GetHabbo().Id); dbClient.addParameter("sid", FirewindEnvironment.getHabboForName(parsedCommand[1]).Id); dbClient.runQuery(); Session.SendMOTD("Du er nå i et forhold med " + parsedCommand[1]); return; case "decline": if (!result) { Session.SendMOTD("Du må være medlem av Mafia eller Police for å ha kommandoene til forhold."); break; } dbClient.setQuery("DELETE FROM users_relationships WHERE sender_id = @sid AND recipent_id = @myid AND accepted = '0' LIMIT 1"); dbClient.addParameter("myid", Session.GetHabbo().Id); dbClient.addParameter("sid", FirewindEnvironment.getHabboForName(parsedCommand[1]).Id); dbClient.runQuery(); Session.SendMOTD("Du har avslått " + parsedCommand[1]); return; case "declineall": if (!result) { Session.SendMOTD("Du må være medlem av Mafia eller Police for å ha kommandoene til forhold."); break; } dbClient.setQuery("DELETE FROM users_relationships WHERE recipent_id = @myid AND accepted = '0' LIMIT 1"); dbClient.addParameter("myid", Session.GetHabbo().Id); dbClient.runQuery(); Session.SendMOTD("Du har avslått alle."); return; case "status": uint userID = FirewindEnvironment.getHabboForName(parsedCommand[1]).Id; dbClient.setQuery("SELECT sender_id,recipent_id FROM users_relationships WHERE (recipent_id = @userid OR sender_id = @userid) AND accepted = '1' LIMIT 1"); dbClient.addParameter("userid", userID); DataRow resultRow = dbClient.getRow(); if (resultRow == null) { Session.SendMOTD(parsedCommand[1] + " er singel."); } else { bool isSender = Convert.ToUInt32(resultRow[0]) == userID; Session.SendMOTD(parsedCommand[1] + " er i et forhold med " + (isSender ? FirewindEnvironment.getHabboForId(Convert.ToUInt32(resultRow[1])).Username : FirewindEnvironment.getHabboForId(Convert.ToUInt32(resultRow[0])).Username)); } return; case "removerelationship": if (!result) { Session.SendMOTD("Du må være medlem av Mafia eller Police for å ha kommandoene til forhold."); break; } dbClient.setQuery("DELETE FROM users_relationships WHERE accepted = '1' AND (recipent_id = @myid OR sender_id = @myid) LIMIT 1"); dbClient.addParameter("myid", Session.GetHabbo().Id); dbClient.runQuery(); Session.SendMOTD("Du er ikke lenger i noen forhold."); return; } } } } uint rank = 1; Message = LanguageLocale.FilterSwearwords(Message); if (Session != null && Session.GetHabbo() != null) { rank = Session.GetHabbo().Rank; } TimeSpan SinceLastMessage = DateTime.Now - clientUser.spamFloodTime; if (SinceLastMessage.TotalSeconds > clientUser.spamProtectionTime && clientUser.spamProtectionBol == true) { FloodCount = 0; clientUser.spamProtectionBol = false; clientUser.spamProtectionAbuse = 0; } else { if (SinceLastMessage.TotalSeconds > 4) { FloodCount = 0; } } if (SinceLastMessage.TotalSeconds < clientUser.spamProtectionTime && clientUser.spamProtectionBol == true) { ServerMessage Packet = new ServerMessage(Outgoing.FloodFilter); int timeToWait = clientUser.spamProtectionTime - SinceLastMessage.Seconds; Packet.AppendInt32(timeToWait); //Blocked for X sec GetClient().SendMessage(Packet); if (FirewindEnvironment.spamBans == true) { clientUser.spamProtectionAbuse++; GameClient toBan; toBan = FirewindEnvironment.GetGame().GetClientManager().GetClientByUsername(Session.GetHabbo().Username); if (clientUser.spamProtectionAbuse >= FirewindEnvironment.spamBans_limit) { FirewindEnvironment.GetGame().GetBanManager().BanUser(toBan, "SPAM*ABUSE", 800, LanguageLocale.GetValue("flood.banmessage"), false); } else { toBan.SendNotif(LanguageLocale.GetValue("flood.pleasewait").Replace("%secs%", Convert.ToString(timeToWait))); } } return; } if (SinceLastMessage.TotalSeconds < 4 && FloodCount > 5 && rank < 5) { ServerMessage Packet = new ServerMessage(Outgoing.FloodFilter); clientUser.spamProtectionCount += 1; if (clientUser.spamProtectionCount % 2 == 0) { clientUser.spamProtectionTime = (10 * clientUser.spamProtectionCount); } else { clientUser.spamProtectionTime = 10 * (clientUser.spamProtectionCount - 1); } clientUser.spamProtectionBol = true; Packet.AppendInt32(clientUser.spamProtectionTime - SinceLastMessage.Seconds); //Blocked for X sec GetClient().SendMessage(Packet); return; } clientUser.spamFloodTime = DateTime.Now; FloodCount++; FirewindEnvironment.GetGame().GetQuestManager().ProgressUserQuest(Session, HabboHotel.Quests.QuestType.SOCIAL_CHAT); GetClient().GetHabbo().GetChatMessageManager().AddMessage(ChatMessageFactory.CreateMessage(Message, this.GetClient(), this.GetRoom())); } InvokedChatMessage message = new InvokedChatMessage(this, Message, Shout); GetRoom().QueueChatMessage(message); }