/// <summary> /// Handles the login request packet sent by the client /// </summary> static public void Handle_CS_Login(CS_Login pkt, Client <Player> client) { //Let's escalate our client's status to player! ZoneServer server = (client._handler as ZoneServer); // check for excessive joins to zone from same IP if (pkt.bCreateAlias != true && server._connections.ContainsKey(client._ipe.Address)) { Helpers.Login_Response(client, SC_Login.Login_Result.Failed, "Please wait 10 seconds before logging in again."); Log.write(TLog.Warning, "Possible throttler removed: {0}", client._ipe.ToString()); return; } else if (!server._connections.ContainsKey(client._ipe.Address)) { server._connections.Add(client._ipe.Address, DateTime.Now.AddSeconds(10)); } //Check their client version and UIDs //TODO: find out what the UIDs are and what an invalid UID might look like, and reject spoofed ones if (pkt.Version != Helpers._serverVersion || pkt.UID1 <= 10000 || pkt.UID2 <= 10000 || pkt.UID3 <= 10000) { Log.write(TLog.Warning, "Suspicious login packet from {0} : Version ({1}) UID1({2}) UID2({3}) UID3({4})", pkt.Username, pkt.Version, pkt.UID1, pkt.UID2, pkt.UID3); } String alias = pkt.Username; //Check alias for illegal characters if (String.IsNullOrWhiteSpace(alias)) { Helpers.Login_Response(client, SC_Login.Login_Result.Failed, "Alias cannot be blank."); return; } try { //Temporary till we find the login bug if (!char.IsLetterOrDigit(alias, 0) || char.IsWhiteSpace(alias, 0) || char.IsWhiteSpace(alias, alias.Length - 1) || alias != Logic_Text.RemoveIllegalCharacters(alias)) { //Boot him.. Helpers.Login_Response(client, SC_Login.Login_Result.Failed, "Alias contains illegal characters, must start with a letter or number and cannot end with a space."); return; } } catch (ArgumentOutOfRangeException) { Log.write(TLog.Warning, "Player login name is {0}", alias); Helpers.Login_Response(client, SC_Login.Login_Result.Failed, "Alias contains illegal characters, must start with a letter or number and cannot end with a space."); return; } if (alias.Length > 64) { //Change this if alias.name in the db is changed.. currently at varchar(64) Helpers.Login_Response(client, SC_Login.Login_Result.Failed, "Alias length is too long."); return; } //Are we in permission mode? if (server._config["server/permitMode"].boolValue && !Logic_Permit.checkPermit(alias)) { Helpers.Login_Response(client, SC_Login.Login_Result.Failed, "Zone is in permission only mode."); return; } Player newPlayer = server.newPlayer(client, alias); //If it failed for some reason, present a failure message if (newPlayer == null) { Helpers.Login_Response(client, SC_Login.Login_Result.Failed, "Login Failure, Zone is full."); Log.write(TLog.Error, "New player is null possibly due to zone being full."); return; } newPlayer._UID1 = pkt.UID1; newPlayer._UID2 = pkt.UID2; newPlayer._UID3 = pkt.UID3; //Are we in standalone mode? if (server.IsStandalone) { //Always first time setup in standalone mode newPlayer.assignFirstTimeStats(false); //Success! Let him in. Helpers.Login_Response(client, SC_Login.Login_Result.Success, "This server is currently in stand-alone mode. Your character's scores and stats will not be saved."); } else { //Defer the request to the database server CS_PlayerLogin <Data.Database> plogin = new CS_PlayerLogin <Data.Database>(); plogin.bCreateAlias = pkt.bCreateAlias; plogin.player = newPlayer.toInstance(); plogin.alias = alias; plogin.ticketid = pkt.TicketID; plogin.UID1 = pkt.UID1; plogin.UID2 = pkt.UID2; plogin.UID3 = pkt.UID3; plogin.NICInfo = pkt.NICInfo; plogin.ipaddress = pkt._client._ipe.Address.ToString().Trim(); server._db.send(plogin); } }
/// <summary> /// Triggered when the client is attempting to enter the game and sends his security reply /// </summary> static public void Handle_CS_Environment(CS_Environment pkt, Player player) { //Does he have a target ready to receive the information? Player target = player.getVar("envReq") as Player; List <string> badPrograms = new List <string>(); badPrograms.Add("cheat engine 6.2"); badPrograms.Add("ollydbg"); badPrograms.Add("cheat engine"); badPrograms.Add("cheatengine"); badPrograms.Add("ollydbg.exe"); badPrograms.Add("wireshark"); badPrograms.Add("wireshark.exe"); badPrograms.Add("speederxp"); badPrograms.Add("L. Spiro"); badPrograms.Add("spiro"); badPrograms.Add("mhs"); badPrograms.Add("hex editor"); if (target == null) {//It was a request by the server //Check the processes foreach (string element in pkt.processes) { if (badPrograms.Contains(Logic_Text.RemoveIllegalCharacters(element).ToLower()) && player._permissionStatic != Data.PlayerPermission.Sysop) {//They have a cheat running or debugger, kick them out and inform mods if (!player._server.IsStandalone) { CS_ChatQuery <Data.Database> pktquery = new CS_ChatQuery <Data.Database>(); pktquery.queryType = CS_ChatQuery <Data.Database> .QueryType.alert; pktquery.sender = player._alias; pktquery.payload = String.Format("&ALERT - Player Kicked: (Zone={0}, Arena={1}, Player={2}) Reason=Using a hack or cheat engine. Program={3}", player._server.Name, player._arena._name, player._alias, Logic_Text.RemoveIllegalCharacters(element).ToLower()); //Send it! player._server._db.send(pktquery); } else { foreach (Player ppl in player._arena.Players.ToList()) { if (ppl.PermissionLevelLocal >= Data.PlayerPermission.ArenaMod) { ppl.sendMessage(-1, String.Format("&ALERT - Player Kicked: (Zone={0}, Arena={1}, Player={2}) Reason=Using a hack or cheat engine. Program={3}", player._server.Name, player._arena._name, player._alias, Logic_Text.RemoveIllegalCharacters(element).ToLower())); } } } Log.write(TLog.Security, String.Format("Player Kicked: (Zone={0}, Arena={1}, Player={2}) Reason=Using a hack or cheat engine. Program={3}", player._server.Name, player._arena._name, player._alias, Logic_Text.RemoveIllegalCharacters(element).ToLower())); player.disconnect(); return; } } //Check the windows foreach (string element in pkt.windows) { if (badPrograms.Contains(Logic_Text.RemoveIllegalCharacters(element).ToLower()) && player._permissionStatic != Data.PlayerPermission.Sysop) {//They have a cheat running or debugger, kick them out and inform mods if (!player._server.IsStandalone) { CS_ChatQuery <Data.Database> pktquery = new CS_ChatQuery <Data.Database>(); pktquery.queryType = CS_ChatQuery <Data.Database> .QueryType.alert; pktquery.sender = player._alias; pktquery.payload = String.Format("&ALERT - Player Kicked: (Zone={0}, Arena={1}, Player={2}) Reason=Using a hack or cheat engine. Program={3}", player._server.Name, player._arena._name, player._alias, Logic_Text.RemoveIllegalCharacters(element).ToLower()); //Send it! player._server._db.send(pktquery); } else { foreach (Player ppl in player._arena.Players.ToList()) { if (ppl.PermissionLevelLocal >= Data.PlayerPermission.ArenaMod) { ppl.sendMessage(-1, String.Format("&ALERT - Player Kicked: (Zone={0}, Arena={1}, Player={2}) Reason=Using a hack or cheat engine.", player._server.Name, player._arena._name, player._alias)); } } } player.disconnect(); } } return; } player.setVar("envReq", null); //Display to him the results target.sendMessage(0, "&Processes:"); foreach (string element in pkt.processes) { target.sendMessage(0, "*" + Logic_Text.RemoveIllegalCharacters(element)); } target.sendMessage(0, "&Windows:"); foreach (string element in pkt.windows) { target.sendMessage(0, "*" + Logic_Text.RemoveIllegalCharacters(element)); } // TODO: Write these out to a file so that later we can compare them. if (!String.IsNullOrWhiteSpace(player.getVar("envReqParams") as String)) { var filename = ""; // read envReqParams // Write out to a file. } }