public static void GetUserRooms(Session Session, ClientMessage Message) { ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message); if (Response != null) { Session.SendData(Response); return; } List <RoomInfo> Rooms = new List <RoomInfo>(); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { MySqlClient.SetParameter("ownerid", Session.CharacterId); MySqlClient.SetParameter("limit", MaxRoomsPerUser); DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM rooms WHERE owner_id = @ownerid ORDER BY name ASC LIMIT @limit"); foreach (DataRow Row in Table.Rows) { Rooms.Add(RoomInfoLoader.GenerateRoomInfoFromRow(Row)); } } Response = NavigatorRoomListComposer.Compose(0, 5, string.Empty, Rooms); AddToCacheIfNeeded(Session.CharacterId, Message, Response); Session.SendData(Response); }
public static ServerMessage Compose(ModerationTicket Ticket) { string DisplayRoomName = string.Empty; if (Ticket.RoomId > 0) { RoomInfo Info = RoomInfoLoader.GetRoomInfo(Ticket.RoomId); DisplayRoomName = Info == null ? "(Unknown room " + Ticket.RoomId + ")" : Info.Name; } ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_TICKET); Message.AppendUInt32(Ticket.Id); Message.AppendUInt32(Ticket.TabId); Message.AppendUInt32(11); // ?? unknown Message.AppendUInt32(Ticket.CategoryId); Message.AppendUInt32(11); // ?? unknown Message.AppendUInt32(Ticket.Score); Message.AppendUInt32(Ticket.ReporteeUserId); Message.AppendStringWithBreak(CharacterResolverCache.GetNameFromUid(Ticket.ReporteeUserId)); Message.AppendUInt32(Ticket.ReportedUserId); Message.AppendStringWithBreak(CharacterResolverCache.GetNameFromUid(Ticket.ReportedUserId)); Message.AppendUInt32(Ticket.ModeratorUserId); Message.AppendStringWithBreak(CharacterResolverCache.GetNameFromUid(Ticket.ModeratorUserId)); Message.AppendStringWithBreak(Ticket.Message); Message.AppendUInt32(Ticket.RoomId); Message.AppendStringWithBreak(DisplayRoomName); return(Message); }
private static void GetTicketChatlog(Session Session, ClientMessage Message) { if (!Session.HasRight("moderation_tool")) { return; } ModerationTicket Ticket = ModerationTicketManager.GetTicket(Message.PopWiredUInt32()); if (Ticket == null || Ticket.ModeratorUserId != Session.CharacterId) { Session.SendData(NotificationMessageComposer.Compose("Ticket not found or ticket is not assigned to you.")); return; } RoomInfo Info = null; if (Ticket.RoomId > 0) { Info = RoomInfoLoader.GetRoomInfo(Ticket.RoomId); } Session.SendData(ModerationTicketChatlogsComposer.Compose(Ticket, Info, ModerationLogs.GetLogsForRoom(Ticket.RoomId, (Ticket.CreatedTimestamp - 600), UnixTimestamp.GetCurrent()))); }
private static void GetRatedRooms(Session Session, ClientMessage Message) { ServerMessage Response = TryGetResponseFromCache(0, Message); if (Response != null) { Session.SendData(Response); return; } List <RoomInfo> Rooms = new List <RoomInfo>(); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM rooms WHERE type = 'flat' AND score > 0 ORDER BY score DESC LIMIT 50"); foreach (DataRow Row in Table.Rows) { Rooms.Add(RoomInfoLoader.GenerateRoomInfoFromRow(Row)); } } Response = NavigatorRoomListComposer.Compose(0, 2, string.Empty, Rooms); AddToCacheIfNeeded(0, Message, Response); Session.SendData(Response); }
public static ServerMessage Compose(uint UserId, Dictionary <ModerationRoomVisit, ReadOnlyCollection <ModerationChatlogEntry> > Entries) { string CharacterNameString = CharacterResolverCache.GetNameFromUid(UserId); ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_CHATLOGS_USER); Message.AppendUInt32(UserId); Message.AppendStringWithBreak(CharacterNameString); Message.AppendInt32(Entries.Count); foreach (KeyValuePair <ModerationRoomVisit, ReadOnlyCollection <ModerationChatlogEntry> > EntryData in Entries) { RoomInfo Info = RoomInfoLoader.GetRoomInfo(EntryData.Key.RoomId); Message.AppendBoolean(Info != null && Info.Type == RoomType.Public); Message.AppendUInt32(Info != null ? Info.Id : 0); Message.AppendStringWithBreak(Info != null ? Info.Name : "(Unknown room)"); Message.AppendInt32(EntryData.Value.Count); foreach (ModerationChatlogEntry Entry in EntryData.Value) { DateTime Time = UnixTimestamp.GetDateTimeFromUnixTimestamp(Entry.Timestamp); Message.AppendInt32(Time.Hour); Message.AppendInt32(Time.Minute); Message.AppendUInt32(Entry.UserId); Message.AppendStringWithBreak(Entry.UserId == UserId ? CharacterNameString : CharacterResolverCache.GetNameFromUid(Entry.UserId)); Message.AppendStringWithBreak(Entry.Message); } } return(Message); }
private static void GetFriendsRooms(Session Session, ClientMessage Message) { ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message); if (Response != null) { Session.SendData(Response); return; } List <RoomInfo> Rooms = new List <RoomInfo>(); ReadOnlyCollection <uint> Friends = Session.MessengerFriendCache.Friends; if (Friends.Count > 0) { using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { StringBuilder QueryBuilder = new StringBuilder("SELECT * FROM rooms WHERE "); int i = 0; foreach (uint FriendId in Friends) { if (i >= 1) { QueryBuilder.Append("OR "); } QueryBuilder.Append("owner_id = " + FriendId + " "); i++; } QueryBuilder.Append("ORDER BY current_users DESC LIMIT 50"); DataTable Table = MySqlClient.ExecuteQueryTable(QueryBuilder.ToString()); foreach (DataRow Row in Table.Rows) { Rooms.Add(RoomInfoLoader.GenerateRoomInfoFromRow(Row)); } } } Response = NavigatorRoomListComposer.Compose(0, 3, string.Empty, Rooms); AddToCacheIfNeeded(Session.CharacterId, Message, Response); Session.SendData(Response); }
private static void GetRoomInfo(Session Session, ClientMessage Message) { if (!Session.HasRight("moderation_tool")) { return; } RoomInfo Info = RoomInfoLoader.GetRoomInfo(Message.PopWiredUInt32()); if (Info == null) { Session.SendData(NotificationMessageComposer.Compose("Could not retrieve room information.")); return; } Session.SendData(ModerationRoomInfoComposer.Compose(Info, RoomManager.GetInstanceByRoomId(Info.Id))); }
private static void GetRecentRooms(Session Session, ClientMessage Message) { ServerMessage Response = TryGetResponseFromCache(Session.CharacterId, Message); if (Response != null) { Session.SendData(Response); return; } List <uint> VisitedUids = new List <uint>(); List <RoomInfo> Rooms = new List <RoomInfo>(); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { MySqlClient.SetParameter("userid", Session.CharacterId); DataTable Table = MySqlClient.ExecuteQueryTable("SELECT room_id FROM room_visits WHERE user_id = @userid ORDER BY timestamp_entered DESC LIMIT 50"); foreach (DataRow Row in Table.Rows) { uint Id = (uint)Row["room_id"]; if (VisitedUids.Contains(Id)) { continue; } RoomInfo Info = RoomInfoLoader.GetRoomInfo(Id); if (Info == null || Info.Type == RoomType.Public) { continue; } Rooms.Add(Info); VisitedUids.Add(Info.Id); } } Response = NavigatorRoomListComposer.Compose(0, 7, string.Empty, Rooms); AddToCacheIfNeeded(Session.CharacterId, Message, Response); Session.SendData(Response); }
private static void GetRoomChatlog(Session Session, ClientMessage Message) { if (!Session.HasRight("moderation_tool")) { return; } int Unknown1 = Message.PopWiredInt32(); uint RoomId = Message.PopWiredUInt32(); RoomInfo Info = RoomInfoLoader.GetRoomInfo(RoomId); if (Info == null) { Session.SendData(NotificationMessageComposer.Compose("Room not found; could not load chatlogs.")); return; } Session.SendData(ModerationRoomChatlogsComposer.Compose(Info, ModerationLogs.GetLogsForRoom(RoomId, (UnixTimestamp.GetCurrent() - 3600), UnixTimestamp.GetCurrent()))); }
public static ServerMessage Compose(uint UserId, ReadOnlyCollection <ModerationRoomVisit> Visits) { ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_ROOM_VISITS); Message.AppendUInt32(UserId); Message.AppendStringWithBreak(CharacterResolverCache.GetNameFromUid(UserId)); Message.AppendInt32(Visits.Count); foreach (ModerationRoomVisit Visit in Visits) { RoomInfo Info = RoomInfoLoader.GetRoomInfo(Visit.RoomId); DateTime Time = UnixTimestamp.GetDateTimeFromUnixTimestamp(Visit.TimestampEntered); Message.AppendBoolean(Info != null && Info.Type == RoomType.Public); Message.AppendUInt32(Info != null ? Info.Id : 0); Message.AppendStringWithBreak(Info != null ? Info.Name : "Unknown Room"); Message.AppendInt32(Time.Hour); Message.AppendInt32(Time.Minute); } return(Message); }
private static void OnFollowBuddy(Session Session, ClientMessage Message) { uint BuddyId = Message.PopWiredUInt32(); if (!Session.MessengerFriendCache.Friends.Contains(BuddyId)) { return; } Session BuddySession = SessionManager.GetSessionByCharacterId(BuddyId); if (BuddySession == null || !BuddySession.InRoom) { return; } RoomInfo Info = RoomInfoLoader.GetRoomInfo(BuddySession.CurrentRoomId); if (Info != null) { Session.SendData(MessengerFollowResultComposer.Compose(Info)); } }
public static void Main(string[] args) { mAlive = true; DateTime InitStart = DateTime.Now; // Set up basic output, configuration, etc Output.InitializeStream(true, OutputLevel.DebugInformation); Output.WriteLine("Initializing Snowlight..."); ConfigManager.Initialize(Constants.DataFileDirectory + "\\server-main.cfg"); Output.SetVerbosityLevel((OutputLevel)ConfigManager.GetValue("output.verbositylevel")); // Load Lang LangManager.Initialize(Constants.LangFileDirectory + "\\lang_" + ConfigManager.GetValue("lang") + ".lang"); // Process args foreach (string arg in args) { Output.WriteLine("Command line argument: " + arg); Input.ProcessInput(arg.Split(' ')); } try { // Initialize and test database Output.WriteLine("Initializing MySQL manager..."); SqlDatabaseManager.Initialize(); // Initialize network components Output.WriteLine("Setting up server listener on port " + (int)ConfigManager.GetValue("net.bind.port") + "..."); mServer = new SnowTcpListener(new IPEndPoint(IPAddress.Any, (int)ConfigManager.GetValue("net.bind.port")), (int)ConfigManager.GetValue("net.backlog"), new OnNewConnectionCallback( SessionManager.HandleIncomingConnection)); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { Output.WriteLine("Resetting database counters and statistics..."); PerformDatabaseCleanup(MySqlClient); Output.WriteLine("Initializing game components and workers..."); // Core DataRouter.Initialize(); // Sessions, characters Handshake.Initialize(); GlobalHandler.Initialize(); SessionManager.Initialize(); CharacterInfoLoader.Initialize(); RightsManager.Initialize(MySqlClient); SingleSignOnAuthenticator.Initialize(); // Room management and navigator RoomManager.Initialize(MySqlClient); RoomInfoLoader.Initialize(); RoomHandler.Initialize(); RoomItemHandler.Initialize(); Navigator.Initialize(MySqlClient); // Help and moderation HelpTool.Initialize(MySqlClient); ModerationPresets.Initialize(MySqlClient); ModerationTicketManager.Initialize(MySqlClient); ModerationHandler.Initialize(); ModerationBanManager.Initialize(MySqlClient); // Catalog, pets and items ItemDefinitionManager.Initialize(MySqlClient); CatalogManager.Initialize(MySqlClient); CatalogPurchaseHandler.Initialize(); Inventory.Initialize(); ItemEventDispatcher.Initialize(); PetDataManager.Initialize(MySqlClient); // Messenger MessengerHandler.Initialize(); // Achievements and quests AchievementManager.Initialize(MySqlClient); QuestManager.Initialize(MySqlClient); // Misc/extras CrossdomainPolicy.Initialize("Data\\crossdomain.xml"); InfobusManager.Initialize(); ActivityPointsWorker.Initialize(); BotManager.Initialize(MySqlClient); InterstitialManager.Initialize(MySqlClient); ChatEmotions.Initialize(); EffectsCacheWorker.Initialize(); RecyclerManager.Initialize(MySqlClient); DrinkSetManager.Initialize(MySqlClient); SongManager.Initialize(); TradeHandler.Initialize(); RandomGenerator.Initialize(); StatisticsSyncUtil.Initialize(); // Polish WarningSurpressors.Initialize(); } } catch (Exception e) { HandleFatalError("Could not initialize Snowlight: " + e.Message + "\n" + e.StackTrace); return; } // Init complete TimeSpan TimeSpent = DateTime.Now - InitStart; Output.WriteLine("The server has initialized successfully (" + Math.Round(TimeSpent.TotalSeconds, 2) + " seconds). Ready for connections.", OutputLevel.Notification); Output.WriteLine((string)LangManager.GetValue("initialized.info.cmd"), OutputLevel.Notification); Console.Beep(); Input.Listen(); // This will make the main thread process console while Program.Alive. }
public static void Main(string[] args) { mAlive = true; DateTime InitStart = DateTime.Now; // Set up basic output Console.WriteLine("Initializing Snowlight..."); // Cannot be localized before config+lang is loaded // Load configuration, translation, and re-configure output from config data ConfigManager.Initialize(Constants.DataFileDirectory + "server-main.cfg"); Output.InitializeStream(true, (OutputLevel)ConfigManager.GetValue("output.verbositylevel")); Output.WriteLine("Initializing Snowlight..."); Localization.Initialize(Constants.LangFileDirectory + "lang_" + ConfigManager.GetValue("lang") + ".lang"); // Process args foreach (string arg in args) { Output.WriteLine(Localization.GetValue("core.init.cmdarg", arg)); Input.ProcessInput(arg.Split(' ')); } try { // Initialize and test database Output.WriteLine(Localization.GetValue("core.init.mysql")); SqlDatabaseManager.Initialize(); // Initialize network components Output.WriteLine(Localization.GetValue("core.init.net", ConfigManager.GetValue("net.bind.port").ToString())); mServer = new SnowTcpListener(new IPEndPoint((IPAddress)ConfigManager.GetValue("net.bind.ip"), (int)ConfigManager.GetValue("net.bind.port")), (int)ConfigManager.GetValue("net.backlog"), new OnNewConnectionCallback( SessionManager.HandleIncomingConnection)); Output.WriteLine(Localization.GetValue("core.init.net", ConfigManager.GetValue("net.cmd.bind.port").ToString())); musServer = new SnowTcpListener(new IPEndPoint((IPAddress)ConfigManager.GetValue("net.cmd.bind.ip"), (int)ConfigManager.GetValue("net.cmd.bind.port")), (int)ConfigManager.GetValue("net.backlog"), new OnNewConnectionCallback( CommandListener.parse)); using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { Output.WriteLine(Localization.GetValue("core.init.dbcleanup")); PerformDatabaseCleanup(MySqlClient); Output.WriteLine(Localization.GetValue("core.init.game")); // Core DataRouter.Initialize(); // Sessions, characters Handshake.Initialize(); GlobalHandler.Initialize(); SessionManager.Initialize(); CharacterInfoLoader.Initialize(); RightsManager.Initialize(MySqlClient); SingleSignOnAuthenticator.Initialize(); // Room management and navigator RoomManager.Initialize(MySqlClient); RoomInfoLoader.Initialize(); RoomHandler.Initialize(); RoomItemHandler.Initialize(); Navigator.Initialize(MySqlClient); // Help and moderation HelpTool.Initialize(MySqlClient); ModerationPresets.Initialize(MySqlClient); ModerationTicketManager.Initialize(MySqlClient); ModerationHandler.Initialize(); ModerationBanManager.Initialize(MySqlClient); // Catalog, pets and items ItemDefinitionManager.Initialize(MySqlClient); CatalogManager.Initialize(MySqlClient); CatalogPurchaseHandler.Initialize(); Inventory.Initialize(); ItemEventDispatcher.Initialize(); PetDataManager.Initialize(MySqlClient); // Messenger MessengerHandler.Initialize(); // Achievements and quests AchievementManager.Initialize(MySqlClient); QuestManager.Initialize(MySqlClient); // Misc/extras CrossdomainPolicy.Initialize("Data\\crossdomain.xml"); InfobusManager.Initialize(); ActivityPointsWorker.Initialize(); BotManager.Initialize(MySqlClient); InterstitialManager.Initialize(MySqlClient); ChatEmotions.Initialize(); EffectsCacheWorker.Initialize(); RecyclerManager.Initialize(MySqlClient); DrinkSetManager.Initialize(MySqlClient); SongManager.Initialize(); TradeHandler.Initialize(); RandomGenerator.Initialize(); StatisticsSyncUtil.Initialize(); Wordfilter.Initialize(MySqlClient); // Polish WarningSurpressors.Initialize(); } } catch (Exception e) { HandleFatalError(Localization.GetValue("core.init.error.details", new string[] { e.Message, e.StackTrace })); return; } // Init complete TimeSpan TimeSpent = DateTime.Now - InitStart; Output.WriteLine(Localization.GetValue("core.init.ok", Math.Round(TimeSpent.TotalSeconds, 2).ToString()), OutputLevel.Notification); Output.WriteLine((string)Localization.GetValue("core.init.ok.cmdinfo"), OutputLevel.Notification); Console.Write("$" + Environment.UserName.ToLower() + "@snowlight> "); Console.Beep(); Input.Listen(); // This will make the main thread process console while Program.Alive. }
public RoomInfo GetRoomInfo() { return(RoomInfoLoader.GetRoomInfo(mRoomId)); }
private static void PerformSearch(Session Session, ClientMessage Message) { ServerMessage Response = TryGetResponseFromCache(0, Message); if (Response != null) { Session.SendData(Response); return; } Dictionary <uint, RoomInfo> Rooms = new Dictionary <uint, RoomInfo>(); string Query = UserInputFilter.FilterString(Message.PopString()).ToLower().Trim(); int SearchEventCatId = 0; if (mEventSearchQueries.ContainsKey(Query.ToLower())) { SearchEventCatId = mEventSearchQueries[Query.ToLower()]; } // Limit query length. just a precaution. if (Query.Length > 64) { Query = Query.Substring(0, 64); } if (Query.Length > 0) { IEnumerable <RoomInstance> InstanceMatches = (from RoomInstance in RoomManager.RoomInstances where RoomInstance.Value.HumanActorCount > 0 && RoomInstance.Value.Info.Type == RoomType.Flat && (RoomInstance.Value.Info.OwnerName.StartsWith(Query) || RoomInstance.Value.SearchableTags.Contains(Query) || RoomInstance.Value.Info.Name.Contains(Query) || (RoomInstance.Value.HasOngoingEvent && (RoomInstance.Value.Event.Name.StartsWith(Query) || (SearchEventCatId > 0 && RoomInstance.Value.Event.CategoryId == SearchEventCatId)))) orderby RoomInstance.Value.HumanActorCount descending select RoomInstance.Value).Take(50); foreach (RoomInstance Instance in InstanceMatches) { Rooms.Add(Instance.RoomId, Instance.Info); } if (Rooms.Count < 50) // need db results? { using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { MySqlClient.SetParameter("query", Query + "%"); MySqlClient.SetParameter("fquery", "%" + Query + "%"); uint ToUid = CharacterResolverCache.GetUidFromName(Query); if (ToUid > 0) { MySqlClient.SetParameter("owneruid", ToUid); } DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM rooms WHERE name LIKE @query AND type = 'flat' OR tags LIKE @fquery AND type = 'flat'" + (ToUid > 0 ? " OR owner_id = @owneruid AND type = 'flat'" : string.Empty) + " LIMIT 50"); foreach (DataRow Row in Table.Rows) { uint RoomId = (uint)Row["id"]; if (!Rooms.ContainsKey(RoomId)) { Rooms.Add(RoomId, RoomInfoLoader.GenerateRoomInfoFromRow(Row)); } } } } } Response = NavigatorRoomListComposer.Compose(1, 9, Query, Rooms.Values.Take(50).ToList()); AddToCacheIfNeeded(0, Message, Response); Session.SendData(Response); }