private async void discconectUserInactivity(bool withPing = true) { await Task.Delay(120000); if (this.socketClosed == true && this.destroyedClass != true) { using (MySQLManager.Database.Session_Details.Interfaces.IQueryAdapter dbClient = Program.manager.getQueryreactor()) { var json = new System.Web.Script.Serialization.JavaScriptSerializer(); dbClient.query("UPDATE server_1_players SET mapId = '" + this.mapId + "', x = '" + this.Ship.x + "', y = '" + this.Ship.y + "', settings = @settings WHERE playerID = '" + this.userId + "'", (new string[] { "settings" }), (new string[] { json.Serialize(this.Config) })); } this.socketClosed = true; this.destroyedClass = true; this.handler = null; this.Config = null; this.Ship = null; Out.WriteLine("userId " + this.userId + " disconnected from game", this.IP, ConsoleColor.DarkYellow); Program.Maps[this.mapId].RemoveUser(this.userId); Program.removeUser(this.userId); } else if (withPing) { checkPing(); } }
public void discconectUser(int Reason = 0) { try { this.handler.Shutdown(SocketShutdown.Both); this.handler.Close(); this.handler = null; this.socketClosed = true; } catch (Exception) { } if (Reason == -1 || Reason == 1) { using (MySQLManager.Database.Session_Details.Interfaces.IQueryAdapter dbClient = Program.manager.getQueryreactor()) { var json = new System.Web.Script.Serialization.JavaScriptSerializer(); dbClient.query("UPDATE server_1_players SET mapId = '" + this.mapId + "', x = '" + this.Ship.x + "', y = '" + this.Ship.y + "', settings = @settings WHERE playerID = '" + this.userId + "'", (new string[] { "settings" }), (new string[] { json.Serialize(this.Config) })); } } this.Config = null; if (Reason == 0) { Out.WriteLine("userId " + this.userId + " reconnected in another site", this.IP, ConsoleColor.DarkYellow); } else if (Reason == 1) { Out.WriteLine("userId " + this.userId + " has been destroyed", this.IP, ConsoleColor.DarkYellow); } else if (Reason == 2) { Out.WriteLine("Ivalid login", this.IP, ConsoleColor.DarkYellow); } if (Reason != -1) { this.socketClosed = true; this.destroyedClass = true; Program.removeUser(this.userId); } }