static void LFunc() { //Stuffs :) while (true) { Thread.Sleep(10); TcpClient R = Listener.AcceptTcpClient(); // This has it's own built-in wait system. It's Dynamic :) //Listener.Server. //Console.WriteLine(R.Client.RemoteEndPoint.ToString()); ClientClass a = new ClientClass(); a.Client = R; a.name = "anon";//This is anonymous for now. a.ns = new NetworkStream(R.Client); //a.MkKey(); // Right when the client joins, it is sent it's own brand new key :D a.ClientService = new Thread(new ThreadStart(ClientService)); CC = a; a.ClientService.Start(); } }
public static void ClientService() { // try { ClientClass C = CC; NetworkStream ns = C.Client.GetStream(); bool LoggedIn = false; //StreamReader sr = new StreamReader( while (true) { Thread.Sleep(5); //:D //Console.Write(400); if (C.Client.Available >= 3) { byte[] buffer = new byte[C.Client.Available]; //ns.Read(buffer,0,buffer.Length); C.Client.Client.Receive(buffer); Base64Decoder B64 = new Base64Decoder(E.GetChars(buffer)); buffer = B64.GetDecoded(); string data = E.GetString(buffer); //Console.WriteLine(data); bool o = C.LoggedIn; if (C.Decode(data, out data, EncodingType.CSEnc)) { } else { //Limited options for the user to have... string[] la = new string[1]; if (data.Contains("|")) { la = data.Replace("||", Convert.ToChar(2).ToString()).Split('|'); for (int I = 0; I < la.Length; I++) { la[I] = la[I].Replace(Convert.ToChar(2).ToString(), "|"); } } else { la[0] = data; } if (o) { //Full capability... if (data.StartsWith("cht|") && !(C.Permission.Contains("CB"))) { //Send chat to the other clients...} foreach (ClientClass a in Clients) { a.SendPacket("cht|(" + DateTime.Now.Hour + DateTime.Now.Minute + ") " + C.name + "[" + C.Permission + "]: " + la[1], EncodingType.CSEnc); } } else if (data.StartsWith("file|") && (C.Permission.Contains("DEV"))) { //since we have perm, lets continue... if (data.StartsWith("file|w|")) { } //Write the file } else if (data.StartsWith("sqlq|")) { //sql query + return string[] sp = data.Split('|'); string CRC = sp[1]; string dar = ""; string y = sp[2]; if (C.CheckPermissions(ref y, true, true)) { //Console.WriteLine("TEST!"); try { Com.CommandText = y; System.Data.SqlClient.SqlDataReader mcm = Com.ExecuteReader(); while (mcm.Read()) { string ao = ""; for (int I = 0; I < mcm.FieldCount; I++) { string d = Convert.ToChar(2) + ""; if (I == mcm.FieldCount - 1) { d = ""; } if (mcm.IsDBNull(I)) { ao += d; } else { ao += Convert.ToString(mcm.GetValue(I)) + d; } } dar += ao + Convert.ToChar(1); } mcm.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } try { dar = dar.Remove(dar.Length - 1, 1); } catch { } //Console.WriteLine(dar); C.Client.SendBufferSize = ("sqlq|" + CRC + "|" + dar).Length; C.SendPacket("sqlq|" + CRC + "|" + dar, EncodingType.CSEnc); } else { C.SendPacket("sqlq|" + CRC + "|", EncodingType.CSEnc); C.SendPacket("noper", EncodingType.CSEnc); } } else if (data.StartsWith("sqlc|")) { //Sql query string[] sp = data.Split('|'); string y1 = sp[1]; if (C.CheckPermissions(ref sp[1], true, true)) { //Com.CommandText = y1; //Com.ExecuteNonQuery(); } else { C.SendPacket("noper", EncodingType.CSEnc); } Com.CommandText = y1; Com.ExecuteNonQuery(); } else if (data.StartsWith("logout|")) //separators...| { C.name = "anon"; C.LoggedIn = false; LoggedIn = false; } else if (data.StartsWith("DBNames|")) //Client is asking for the set DB names... { C.SendPacket("DBNames|" + GetSetting("SQLAccDB") + "|" + GetSetting("SQLGameDB"), EncodingType.CSEnc); } else { if (C.CheckPermissions(ref data, false, false)) { } else { C.SendPacket("noper", EncodingType.CSEnc); } } } if (data.StartsWith("login|")) //separators...| { try { string[] l = data.Split('|'); Com.CommandText = "SELECT * FROM [" + GetSetting("SQLAccDB") + "].[dbo].[account_login] WHERE [name] = '" + l[1] + "'"; System.Data.SqlClient.SqlDataReader dr = Com.ExecuteReader(); bool UserPassed = false, ISGM = false; if (dr.Read()) { if (dr.GetString(2) == l[2]) { //Password has passed also. UserPassed = true; } } dr.Close(); Com.CommandText = "SELECT * FROM [" + GetSetting("SQLGameDB") + "].[dbo].[account] WHERE [act_name] = '" + l[1] + "'"; dr = Com.ExecuteReader(); if (dr.Read()) { if (Convert.ToString(dr.GetValue(2)) == "99") { ISGM = true; } } dr.Close(); C.GetPermissions(l[1], ISGM); //Console.ForegroundColor = ConsoleColor.Red; //Console.WriteLine(C.Permission); if (UserPassed && !(C.Permission.StartsWith("X"))) //People that still have "X" will not pass!!! { C.SendPacket("login|true", EncodingType.CSEnc); C.LoggedIn = true; LoggedIn = true; //this doesn't work? wtf..lol..? C.name = l[1]; Console.WriteLine(C.name + " Logged in. IP: " + C.Client.Client.RemoteEndPoint.ToString() + " Perm: " + C.Permission); LG("Logged_In", DateTime.Now.Month + "/" + DateTime.Now.Day + "/" + DateTime.Now.Year + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + " - User[" + C.name + "] Logs in. IP: " + C.Client.Client.RemoteEndPoint.ToString()); } else { C.SendPacket("login|false", EncodingType.CSEnc); Console.WriteLine(C.name + " Failed to log in with '" + l[1] + "' as a username. IP: " + C.Client.Client.RemoteEndPoint.ToString()); LG("Logged_Fail", DateTime.Now.Date + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + " - User[" + l[1] + "] Unable to log in. IP: " + C.Client.Client.RemoteEndPoint.ToString()); } } catch (Exception e) { Console.WriteLine(e.Message); } } } } } } catch { } }