private void Dispose(bool Disposing) { if (!this.mDisposed && Disposing) { this.mDisposed = true; try { base.Shutdown(SocketShutdown.Both); base.Close(); base.Dispose(); } catch { } Array.Clear(this.mDataBuffer, 0, this.mDataBuffer.Length); this.mDataBuffer = null; this.mDataReceivedCallback = null; this.mRouteReceivedDataCallback = null; PhoenixEnvironment.GetConnectionManager().DropConnection(this.mID); TcpAuthorization.FreeConnection(this.mIP); if (PhoenixEnvironment.GetConfig().data["emu.messages.connections"] == "1") { Console.WriteLine(string.Concat(new object[] { ">> Connection Dropped [", this.mID, "] from [", this.ipAddress, "]" })); } } }
public HabboData(string pSSOTicket, string pIPAddress, bool LoadFull) { using (DatabaseClient adapter = PhoenixEnvironment.GetDatabase().GetClient()) { adapter.AddParamWithValue("auth_ticket", pSSOTicket); string str = ""; if (GlobalClass.SecureSessions) { str = "AND ip_last = '" + pIPAddress + "' "; } try { if (int.Parse(PhoenixEnvironment.GetConfig().data["debug"]) == 1) { str = ""; } } catch { } this.mUserInformation = adapter.ReadDataRow("SELECT * FROM users WHERE auth_ticket = @auth_ticket " + str + " LIMIT 1;"); if (this.mUserInformation != null) { this.mUserFound = true; uint Id = (uint)this.mUserInformation["Id"]; if (LoadFull) { this.mAchievementData = adapter.ReadDataTable("SELECT achievement_id,achievement_level FROM user_achievements WHERE user_id = '" + Id + "'"); this.mUserFavouriteRooms = adapter.ReadDataTable("SELECT room_id FROM user_favorites WHERE user_id = '" + Id + "'"); this.mUserIgnores = adapter.ReadDataTable("SELECT ignore_id FROM user_ignores WHERE user_id = '" + Id + "'"); this.mUsertags = adapter.ReadDataTable("SELECT tag FROM user_tags WHERE user_id = '" + Id + "'"); this.mSubscriptionData = adapter.ReadDataTable("SELECT subscription_id, timestamp_activated, timestamp_expire FROM user_subscriptions WHERE user_id = '" + Id + "'"); this.mUserBadges = adapter.ReadDataTable("SELECT user_badges.badge_id,user_badges.badge_slot FROM user_badges WHERE user_id = " + Id + " ORDER BY badge_slot ASC"); this.mUserInventory = adapter.ReadDataTable("SELECT Id,base_item,extra_data FROM items WHERE room_id = 0 AND user_id = " + Id); this.mUserEffects = adapter.ReadDataTable("SELECT user_effects.effect_id,user_effects.total_duration,user_effects.is_activated,user_effects.activated_stamp FROM user_effects WHERE user_id = " + Id); this.mUserFriends = adapter.ReadDataTable("SELECT users.Id,users.username,users.motto,users.look,users.last_online FROM users JOIN messenger_friendships ON users.Id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = '" + Id + "'"); this.mUserRequests = adapter.ReadDataTable("SELECT messenger_requests.Id,messenger_requests.from_id,users.username FROM users JOIN messenger_requests ON users.Id = messenger_requests.from_id WHERE messenger_requests.to_id = '" + Id + "'"); adapter.AddParamWithValue("name", this.mUserInformation["username"]); this.mUsersRooms = adapter.ReadDataTable("SELECT * FROM rooms WHERE owner = @name ORDER BY Id ASC LIMIT " + GlobalClass.MaxRoomsPerUser); this.mUserPets = adapter.ReadDataTable("SELECT Id, user_id, room_id, name, type, race, color, expirience, energy, nutrition, respect, createstamp, x, y, z FROM user_pets WHERE user_id = " + Id + " AND room_id = 0"); this.mFriendStream = adapter.ReadDataTable("SELECT friend_stream.id, friend_stream.type, friend_stream.userid, friend_stream.gender, friend_stream.look, friend_stream.time, friend_stream.data, friend_stream.data_extra FROM friend_stream JOIN messenger_friendships ON friend_stream.userid = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = '" + Id + "' ORDER BY friend_stream.time DESC LIMIT 15"); //FriendStream fix adapter.ExecuteQuery(string.Concat(new object[] { "UPDATE users SET online = '1'" + /*auth_ticket = ''*/ "WHERE Id = '", Id, "' LIMIT 1; UPDATE user_info SET login_timestamp = '", PhoenixEnvironment.GetUnixTimestamp(), "' WHERE user_id = '", Id, "' LIMIT 1;" })); } } else { this.mUserFound = false; } } }
internal void RemoveAllRooms() { using (ClonedTable class26_ = this.Rooms.GetThreadSafeTable) { IEnumerator enumerator; using (DatabaseClient @class = PhoenixEnvironment.GetDatabase().GetClient()) { enumerator = class26_.Values.GetEnumerator(); try { while (enumerator.MoveNext()) { Room class2 = (Room)enumerator.Current; class2.method_65(@class); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } if (PhoenixEnvironment.GetConfig().data["emu.messages.roommgr"] == "1") { Console.WriteLine("[RoomMgr] Done with furniture saving, disposing rooms"); } enumerator = class26_.Values.GetEnumerator(); try { while (enumerator.MoveNext()) { Room class2 = (Room)enumerator.Current; try { class2.method_62(); } catch { } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } if (PhoenixEnvironment.GetConfig().data["emu.messages.roommgr"] == "1") { Console.WriteLine("[RoomMgr] Done disposing rooms!"); } } }
public void HandleConnectionData(ref byte[] data) { if (data[0] == 64) { int pos = 0; while (pos < data.Length) { try { int MessageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] }); uint MessageId = Base64Encoding.DecodeUInt32(new byte[] { data[pos++], data[pos++] }); byte[] Content = new byte[MessageLength - 2]; for (int j = 0; j < Content.Length; j++) { Content[j] = data[pos++]; } if (this.MessageHandler == null) { this.InitHandler(); } ClientMessage Message = new ClientMessage(MessageId, Content); if (Message != null) { try { if (int.Parse(PhoenixEnvironment.GetConfig().data["debug"]) == 1) { Logging.WriteLine(string.Concat(new object[] { "[", ClientId, "] --> [", Message.Id, "] ", Message.Header, Message.GetBody() })); } } catch { } MessageEvent MessageHandler; if (PhoenixEnvironment.GetPacketManager().Get(Message.Id, out MessageHandler)) { MessageHandler.parse(this, Message); } } } catch (Exception ex) { Logging.LogException("Error: " + ex.ToString()); this.Disconnect(); } } } else { if (true) { this.Connection.SendData(CrossdomainPolicy.GetXmlPolicy()); this.Connection.Dispose(); } } }
public Game(int conns) { ClientManager = new GameClientManager(conns); if (PhoenixEnvironment.GetConfig().data["client.ping.enabled"] == "1") { ClientManager.StartConnectionChecker(); } DateTime Now = DateTime.Now; Logging.Write("Connecting to database..."); using (DatabaseClient adapter = PhoenixEnvironment.GetDatabase().GetClient()) { Logging.WriteLine("completed!"); PhoenixEnvironment.GameInstance = this; LoadSettings(adapter); BanManager = new ModerationBanManager(); RoleManager = new RoleManager(); HelpTool = new HelpTool(); Catalog = new Catalog(); Navigator = new Navigator(); ItemManager = new ItemManager(); RoomManager = new RoomManager(); AdvertisementManager = new AdvertisementManager(); PixelManager = new PixelManager(); AchievementManager = new AchievementManager(); ModerationTool = new ModerationTool(); BotManager = new BotManager(); Marketplace = new Marketplace(); QuestManager = new QuestManager(); TextManage = new TextManager(); Guilds = new GroupManager(); TextManager.LoadTexts(adapter); BanManager.LoadBans(adapter); RoleManager.LoadRoles(adapter); HelpTool.LoadCategories(adapter); HelpTool.LoadTopics(adapter); ModerationTool.LoadMessagePresets(adapter); ModerationTool.LoadPendingTickets(adapter); ItemManager.LoadItems(adapter); Catalog.Initialize(adapter); Catalog.InitCache(); Navigator.Initialize(adapter); RoomManager.LoadModels(adapter); RoomManager.LoadCache(); NavigatorCache = new NavigatorCache(); AdvertisementManager.LoadRoomAdvertisements(adapter); BotManager.LoadBots(adapter); AchievementManager.LoadAchievements(adapter); PixelManager.Start(); ChatCommandHandler.InitFilter(adapter); QuestManager.InitQuests(); GroupManager.LoadGroups(adapter); DatabaseCleanup(adapter, 1); } Task = new Task(new Action(LowPriorityWorker.Process)); Task.Start(); }
private void TestClientConnections() { int millisecondsTimeout = int.Parse(PhoenixEnvironment.GetConfig().data["client.ping.interval"]); if (millisecondsTimeout <= 100) { throw new ArgumentException("Invalid configuration value for ping interval! Must be above 100 miliseconds."); } while (true) { try { ServerMessage Message = new ServerMessage(50); List <GameClient> SuccessTest = new List <GameClient>(); List <GameClient> FailTest = new List <GameClient>(); for (int i = 0; i < this.Session.Length; i++) { GameClient Session = this.Session[i]; if (Session != null) { if (Session.PongOK) { Session.PongOK = false; FailTest.Add(Session); } else { SuccessTest.Add(Session); } } } foreach (GameClient Session in SuccessTest) { try { Session.Disconnect(); } catch { } } byte[] bytes = Message.GetBytes(); foreach (GameClient Session in FailTest) { try { Session.GetConnection().SendData(bytes); } catch { } } } catch (Exception ex) { Logging.LogThreadException(ex.ToString(), "Connection checker task"); } Thread.Sleep(millisecondsTimeout); } }
internal void HandleNewConnection(SocketInformation connectioninfo, int PreconnID) { TcpConnection connection = new TcpConnection(Convert.ToUInt32(PreconnID), connectioninfo); this.Connections[PreconnID] = connection; PhoenixEnvironment.GetGame().GetClientManager().CreateAndStartClient((uint)PreconnID, ref connection); if (PhoenixEnvironment.GetConfig().data["emu.messages.connections"] == "1") { Logging.WriteLine(string.Concat(new object[] { ">> Connection [", PreconnID, "] from [", connection.ipAddress, "]" })); } }
public void parse(GameClient Session, ClientMessage Event) { uint num = Event.PopWiredUInt(); string string_ = Event.PopFixedString(); Event.PopWiredInt32(); if (PhoenixEnvironment.GetConfig().data["emu.messages.roommgr"] == "1") { Logging.WriteLine("[RoomMgr] Requesting Private Room [ID: " + num + "]"); } Session.GetMessageHandler().PrepareRoomForUser(num, string_); }
internal void UnloadRoom(Room Room) { if (Room != null) { this.Rooms.Remove(Room.RoomId); this.method_18(Room.RoomId); Room.method_62(); if (PhoenixEnvironment.GetConfig().data["emu.messages.roommgr"] == "1") { Logging.WriteLine("[RoomMgr] Unloaded room [ID: " + Room.RoomId + "]"); } } }
public void parse(GameClient Session, ClientMessage Event) { Event.PopWiredInt32(); uint num = Event.PopWiredUInt(); Event.PopWiredInt32(); if (PhoenixEnvironment.GetConfig().data["emu.messages.roommgr"] == "1") { Logging.WriteLine("[RoomMgr] Requesting Public Room [ID: " + num + "]"); } RoomData @class = PhoenixEnvironment.GetGame().GetRoomManager().GenerateRoomData(num); if (@class != null && !(@class.Type != "public")) { Session.GetMessageHandler().PrepareRoomForUser(num, ""); } }
public static void Process() { using (DatabaseClient client = PhoenixEnvironment.GetDatabase().GetClient()) { UserCountCache = (uint)client.ReadInt32("SELECT users FROM system_stats ORDER BY ID DESC LIMIT 1"); } while (true) { try { TimeSpan span = (TimeSpan)(DateTime.Now - PhoenixEnvironment.ServerStarted); int Status = 1; int UsersCount = PhoenixEnvironment.GetGame().GetClientManager().ClientCount + -1; int loadedRoomsCount = PhoenixEnvironment.GetGame().GetRoomManager().LoadedRoomsCount; bool flag = true; try { if (int.Parse(PhoenixEnvironment.GetConfig().data["debug"]) == 1) { flag = false; } } catch { } if (flag) { using (DatabaseClient adapter = PhoenixEnvironment.GetDatabase().GetClient()) { adapter.ExecuteQuery(string.Concat(new object[] { "UPDATE server_status SET stamp = UNIX_TIMESTAMP(), status = '", Status, "', users_online = '", UsersCount, "', rooms_loaded = '", loadedRoomsCount, "', server_ver = '", PhoenixEnvironment.PrettyVersion, "' LIMIT 1" })); if (UsersCount > UserCountCache) { adapter.ExecuteQuery(string.Concat(new object[] { "UPDATE system_stats SET users = '", UsersCount, "', rooms = '", loadedRoomsCount, "' ORDER BY ID DESC LIMIT 1" })); } } } PhoenixEnvironment.GetGame().GetClientManager().CheckEffects(); Console.Title = string.Concat(new object[] { "Phoenix 3.0 | Online Users: ", UsersCount, " | Rooms Loaded: ", loadedRoomsCount, " | Uptime: ", span.Days, " days, ", span.Hours, " hours and ", span.Minutes, " minutes" }); } catch (Exception exception) { Logging.LogThreadException(exception.ToString(), "Server status update task"); } Thread.Sleep(5000); } }
public MusSocket(string mHost, int mPort, string[] mAllowedIps, int backlog) { this.Host = mHost; this.Port = mPort; this.allowedIps = new HashSet <string>(); foreach (string str in mAllowedIps) { this.allowedIps.Add(str); } try { this.Sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); this.Sock.Bind(new IPEndPoint(IPAddress.Parse(PhoenixEnvironment.GetConfig().data["mus.tcp.bindip"]), this.Port)); this.Sock.Listen(backlog); this.Sock.BeginAccept(new AsyncCallback(this.OnEvent_NewConnection), this.Sock); Logging.WriteLine("Listening for MUS on port: " + this.Port); } catch (Exception ex) { throw new Exception("Could not set up MUS socket:\n" + ex.ToString()); } }
public void DatabaseCleanup(DatabaseClient adapter, int serverStatus) { Logging.Write(TextManager.GetText("emu_cleandb")); bool debug = true; try { if (int.Parse(PhoenixEnvironment.GetConfig().data["debug"]) == 1) { debug = false; } } catch { } if (debug) { adapter.ExecuteQuery("UPDATE users SET online = '0' WHERE online != '0'"); adapter.ExecuteQuery("UPDATE rooms SET users_now = '0' WHERE users_now != '0'"); adapter.ExecuteQuery("UPDATE user_roomvisits SET exit_timestamp = UNIX_TIMESTAMP() WHERE exit_timestamp <= 0"); adapter.ExecuteQuery(string.Concat(new object[] { "UPDATE server_status SET status = '", serverStatus, "', users_online = '0', rooms_loaded = '0', server_ver = '", PhoenixEnvironment.PrettyVersion, "', stamp = UNIX_TIMESTAMP() LIMIT 1;" })); } Logging.WriteLine("completed!"); }