/// <summary> /// Sends a message to the server /// </summary> /// <param name="client"></param> public void Send(String MsgSend) { // Build message client.CreateOutgoingMessage(MsgSend); byte[] data = client.OutgoingMessageToBytes(); // Send it on a 1 second interval if (client.Socket.Connected) { try { client.Socket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), client); } catch (SocketException) { Console.WriteLine("Server Closed"); client.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { Console.WriteLine("ket thuc send roi day"); // Connect(); Thread.Sleep(3000); } }
/// <summary> /// Sends a message to the server /// </summary> /// <param name="client"></param> private static void Send(ConnectedObject client) { // Build message client.CreateOutgoingMessage($"Message from {Console.Title}"); byte[] data = client.OutgoingMessageToBytes(); // Send it on a 1 second interval while (true) { Thread.Sleep(3000); try { client.Socket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), client); } catch (SocketException) { Console.WriteLine("Server Closed"); client.Close(); Thread.CurrentThread.Abort(); } catch (Exception ex) { Console.WriteLine(ex.Message); Thread.CurrentThread.Abort(); } } }
/// <summary> /// Sends a message to the server /// </summary> /// <param name="client"></param> private static void Send(ConnectedObject client, string userinfo) { // Build message string msg = userinfo; client.CreateOutgoingMessage(msg); byte[] data = client.OutgoingMessageToBytes(); // Send it on a 1 second interval try { client.Socket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), client); } catch (SocketException) { Console.WriteLine("Server Closed"); client.Close(); Thread.CurrentThread.Abort(); } catch (Exception ex) { Console.WriteLine(ex.Message); Thread.CurrentThread.Abort(); } }
private static void CloseClient(ConnectedObject client) { client.Close(); if (_clients.Contains(client)) { _clients.Remove(client); } }
/// <summary> /// Closes a client socket and removes it from the client list /// </summary> /// <param name="client"></param> private static void CloseClient(ConnectedObject client) { PrintConnectionState("Client disconnected"); client.Close(); if (_clients.Contains(client)) { _clients.Remove(client); } }
private static void Receive(ConnectedObject client) { int bytesRead = 0; while (true) { // Read message from the server try { bytesRead = client.Socket.Receive(client.Buffer, SocketFlags.None); } catch (SocketException) { Console.WriteLine("Server Closed"); client.Close(); Thread.CurrentThread.Abort(); } catch (Exception) { Thread.CurrentThread.Abort(); return; } // Check message if (bytesRead > 0) { // Build message as it comes in client.BuildIncomingMessage(bytesRead); // Check if we received the full message if (client.MessageReceived()) { // Print message to the console Console.WriteLine("Message Received"); // Reset message client.ClearIncomingMessage(); } } } }
private static void Receive(ConnectedObject client, LoginScreen parent) { int bytesRead = 0; while (true) { // Read message from the server try { bytesRead = client.Socket.Receive(client.Buffer, SocketFlags.None); } catch (SocketException) { Console.WriteLine("Server Closed"); client.Close(); Thread.CurrentThread.Abort(); } catch (Exception) { Thread.CurrentThread.Abort(); return; } // Check message if (bytesRead > 0) { // Build message as it comes in client.BuildIncomingMessage(bytesRead); // Check if we received the full message if (client.MessageReceived()) { // Print message to the console Console.WriteLine("Message Received"); Console.WriteLine(client.getIncommingMessage()); string response = client.getIncommingMessage().Replace("<END>", ""); if (int.Parse(response.Split(',')[0]) == 1) { parent.SetVisible(true); parent.SetText("This Key Got Banned !"); parent.SetColor(System.Drawing.Color.Red); } else if (int.Parse(response.Split(',')[0]) == 2) { parent.SetVisible(true); parent.SetText("Password Wrong !"); parent.SetColor(System.Drawing.Color.Red); } else if (int.Parse(response.Split(',')[0]) == 3) { parent.SetVisible(true); parent.SetText("Key Already Online !"); parent.SetColor(System.Drawing.Color.Yellow); } else if (int.Parse(response.Split(',')[0]) == 4) { parent.SetVisible(true); parent.SetText("Key Binded Click Login Again !"); parent.SetColor(System.Drawing.Color.Lime); } else if (int.Parse(response.Split(',')[0]) == 5) { parent.SetVisible(true); parent.SetText("Key Deleted Because Expired !"); parent.SetColor(System.Drawing.Color.Red); } else if (int.Parse(response.Split(',')[0]) == 6) { parent.SetVisible(true); parent.SetText("Your Key Expired !"); parent.SetColor(System.Drawing.Color.Red); } else if (int.Parse(response.Split(',')[0]) == 7) { parent.SetVisible(true); parent.SetText("You Can't Use On This PC !"); parent.SetColor(System.Drawing.Color.Red); } else if (int.Parse(response.Split(',')[0]) == 8) { parent.SetVisible(true); parent.SetText("You Have Been Banned !"); parent.SetColor(System.Drawing.Color.Red); } else if (int.Parse(response.Split(',')[0]) == 9) { string message1 = "VERSION OUTDATED , PLEASE CLICK OK TO UPDATE OR CANCEL TO SHUTDOWN !"; string title1 = "! BYPASS WARNING !"; MessageBoxButtons buttons1 = MessageBoxButtons.OKCancel; DialogResult result1 = MessageBox.Show(message1, title1, buttons1, MessageBoxIcon.Warning); if (result1 == DialogResult.OK) { updater.DoUpdate(); } else if (result1 == DialogResult.Cancel) { Application.Exit(); } } else if (int.Parse(response.Split(',')[0]) == 10) { parent.SetVisible(false); parent.SafeHide(); using (RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"Techcom", true)) if (Key != null) { string val = (string)Key.GetValue("Name"); if (string.IsNullOrEmpty(val)) { Key.SetValue("Name", "" + response.Split(',')[1] + ""); Key.Close(); } else { Key.SetValue("Name", "" + response.Split(',')[1] + ""); Key.Close(); } } else { RegistryKey key; key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Techcom"); key.SetValue("Name", "" + response.Split(',')[1] + ""); key.Close(); } BypassScreen bypassdialog = new BypassScreen(); TimeSpan timeSpan = new TimeSpan(DateTime.ParseExact(response.Split(',')[2], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture).Ticks); DateTime nistTime = DateTime.Now; TimeSpan timeSpan1 = new TimeSpan(nistTime.Ticks); int totalDays = (int)(timeSpan.TotalDays - timeSpan1.TotalDays); int totalHours = (int)(timeSpan.TotalHours - timeSpan1.TotalHours); int totalMinutes = (int)(timeSpan.TotalMinutes - timeSpan1.TotalMinutes); string str1 = ""; string str2 = ""; if (totalDays > 0) { str1 = string.Concat("Expire By Days : ", totalDays, " Days"); str2 = string.Concat("", totalDays, " Days"); } else if (totalHours > 0) { str1 = string.Concat("Expire By Hours: ", totalHours, " Hours"); str2 = string.Concat("", totalHours, " Hours"); } else if (totalMinutes > 0) { str1 = string.Concat("Expire By Minutes : ", totalMinutes, " Minutes"); str2 = string.Concat("", totalMinutes, " Minutes"); } bypassdialog.Show(); Control[] ctrls = bypassdialog.Controls.Find("username", false); if (ctrls.Length > 0) { Label lbl = (Label)ctrls[0]; lbl.Text += response.Split(',')[1]; } Control[] ctrls2 = bypassdialog.Controls.Find("keyindays", false); if (ctrls2.Length > 0) { Label lbl = (Label)ctrls2[0]; lbl.Text = str1; } Control[] ctrls3 = bypassdialog.Controls.Find("keyindate", false); if (ctrls3.Length > 0) { Label lbl = (Label)ctrls3[0]; lbl.Text = "Expire By Date : " + response.Split(',')[2] + ""; } bypassdialog.Text += str2; parent.SafeHide(); } // Reset message client.ClearIncomingMessage(); } } } }
private void CloseClient(ConnectedObject ConnectedObject) { Log.PrintMsg($"Client {ConnectedObject.Socket.RemoteEndPoint} disconect."); ConnectedObject.Close(); _clients.Remove(ConnectedObject); }