شـريـط الاهـداءات | |
قـسـم الـ Centerbot هذا القسم يشتمل على كل ما يخص الـ Centerbot |
|
أدوات الموضوع | انواع عرض الموضوع |
10-10-2014, 04:21 PM | #11 | ||||||||||||
|
وهي عشان يتعلمو :) using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Net; using System.Net.Sockets; using System.Collections; using System.Threading; namespace Silkroad { class BotClientTest { private static Socket _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); private const int _PORT = 100; private const int _BUFFER_SIZE = 2048; private static readonly byte[] _buffer = new byte[_BUFFER_SIZE]; public static void Manager() { ConnectToServer(); //RequestLoop(); //Exit(); } private static void ConnectToServer() { int attempts = 0; while (!_clientSocket.Connected) { try { attempts++; Globals.UpdateLogs("Connection attempt " + attempts); _clientSocket.Connect(IPAddress.Loopback, _PORT); } catch (SocketException) { //Console.Clear(); } } //Console.Clear(); Globals.UpdateLogs("Connected"); } public static void SendHSPacketToBotServer(byte[] data) { Globals.UpdateLogs("HS Packet Sent to Server"); _clientSocket.Send(data); Globals.UpdateLogs("Awaiting Response from Server"); _clientSocket.BeginReceive(_buffer, 0, _BUFFER_SIZE, SocketFlags.None, ReceiveCallback, _clientSocket); } private static void ReceiveCallback(IAsyncResult AR) { Globals.UpdateLogs("Server Sent the Response Packet"); Socket _clientSocket = (Socket)AR.AsyncState; int received=1; try { received = _clientSocket.EndReceive(AR); } catch (SocketException) { Globals.UpdateLogs("ERROR"); } byte[] recBuf = new byte[received]; Array.Copy(_buffer, recBuf, received); Globals.UpdateLogs("Sending Received Response Packet to Joymax Servers"); Globals.ServerPC.CreatePacket3(recBuf); _clientSocket.BeginReceive(_buffer, 0, _BUFFER_SIZE, SocketFlags.None, ReceiveCallback, _clientSocket); } /// <summary> /// Close socket and exit app /// </summary> private static void Exit() { SendString("exit"); // Tell the server we re exiting _clientSocket.Shutdown(SocketShutdown.Both); _clientSocket.Close(); Environment.Exit(0); } public static void SendStuffToBS() { Globals.UpdateLogs("Send a request: "); string request = "get time"; SendString(request); if (request.ToLower() == "exit") { Exit(); } Globals.UpdateLogs("begin receiving"); ReceiveResponse(); } /// <summary> /// Sends a string to the server with ASCII encoding /// </summary> private static void SendString(string text) { byte[] buffer = Encoding.ASCII.GetBytes(text); _clientSocket.Send(buffer, 0, buffer.Length, SocketFlags.None); } private static void ReceiveResponse() { var buffer = new byte[2048]; Globals.UpdateLogs("lol"); int received = _clientSocket.Receive(buffer, SocketFlags.None); Globals.UpdateLogs("lol"); if (received == 0) { return; } Globals.UpdateLogs("lol"); var data = new byte[received]; Array.Copy(buffer, data, received); //string text = Encoding.ASCII.GetString(data); //Globals.UpdateLogs(text); Globals.UpdateLogs("got server response"); } } } |
||||||||||||
|
يتصفح الموضوع حالياً : 3 (0 عضو و 3 زائر) | |
أدوات الموضوع | |
انواع عرض الموضوع | |
|
|