Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 17:24

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Working with sockets - Server & client [Send - Receive Packets]

Discussion on Working with sockets - Server & client [Send - Receive Packets] within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
Arrow Working with sockets - Server & client [Send - Receive Packets]

Working with sockets - Server & client [Send - Receive Packets]

Hello Epvps Members .. as title says ..

i am working on client and server deployment on C#

i used Conquer server socket " [Conquer_Online_Server] V 5518+ " and i created a client that connect to it .

i can send and receive bytes and convert it to message like here :

this is Client code :

Code:
        private void cmdReceiveData()
        {
            try
            {
                while (true)
                {
                    byte[] buffer = new byte[1024];
                    int iRx = m_socClient.Receive(buffer);
                    char[] chars = new char[iRx];

                    System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
                    int charLen = d.GetChars(buffer, 0, iRx, chars, 0);
                    System.String szData = new System.String(chars);
                    UpdateScreen(szData);
                }
            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message);
            }
        }

        private void SendMessage_Click(object sender, EventArgs e)
        {
            try
            {
                string objData = TypeMessage.Text;
                try
                {
                    Send(m_socClient, Encoding.UTF8.GetBytes(objData), 0, objData.Length, 10000);
                }
                catch (Exception ex) { /* ... */ }
            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message);
            }
        }
        public static void Send(Socket socket, byte[] buffer, int offset, int size, int timeout)
        {
            int startTickCount = Environment.TickCount;
            int sent = 0;  // how many bytes is already sent
            do
            {
                if (Environment.TickCount > startTickCount + timeout)
                    throw new Exception("Timeout.");
                try
                {
                    sent += socket.Send(buffer, offset + sent, size - sent, SocketFlags.None);
                }
                catch (SocketException ex)
                {
                    if (ex.SocketErrorCode == SocketError.WouldBlock ||
                        ex.SocketErrorCode == SocketError.IOPending ||
                        ex.SocketErrorCode == SocketError.NoBufferSpaceAvailable)
                    {
                        // socket buffer is probably full, wait and try again
                        Thread.Sleep(30);
                    }
                    else
                        throw ex;  // any serious error occurr
                }
            } while (sent < size);
        }
but now if ia want to create something like conquer login ,, thats contains a text box for Username and another one for Password , and i want send them to server when i click on the login button to check if they are correct or not then pass to login action ,, exactly like conquer online source and client ..

can anyone suggest me how do i start this ??

or anybody create an example " Client " that connects to conquer server and apply my idea ...

Thanx for reading my Thread even if you are will not help
abdeen is offline  
Old 11/11/2013, 12:11   #2
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 946
This is some very old code of mine, but...

Client's Loginscreen:
Code:
//Project by BaussHacker aka. L33TS

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Net.Sockets;

namespace PBClient.Screens
{
	/// <summary>
	/// Description of LoginScreen.
	/// </summary>
	public partial class LoginScreen : UserControl
	{
		public LoginScreen()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			this.DoubleBuffered = true;
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			
			this.BackgroundImage = Core.ImageCollection.GetImage("login", "background");
			
			btnExit.Text = Core.Strings.StringCollection["LOGIN_BTN_EXIT"];
			btnLogin.Text = Core.Strings.StringCollection["LOGIN_BTN_LOGIN"];
			lblAccount.Text = Core.Strings.StringCollection["LOGIN_LBL_ACCOUNT"];
			lblPassword.Text = Core.Strings.StringCollection["LOGIN_LBL_PASSWORD"];
			
			Core.MusicPlayer.Play("music");
		}
		
		void BtnExitClick(object sender, EventArgs e)
		{
			Program.Quit(false);
		}
		
		public void HideShow()
		{
			btnExit.Visible = !btnExit.Visible;
			btnLogin.Visible = !btnLogin.Visible;
			txtAccount.Visible = !txtAccount.Visible;
			txtPassword.Visible = !txtPassword.Visible;
			lblAccount.Visible = !lblAccount.Visible;
			lblPassword.Visible = !lblPassword.Visible;
			lblStatus.Visible = !lblStatus.Visible;
			progressLogin.Visible = !progressLogin.Visible;
		}
		
		public void ConnectAuth()
		{
			lblStatus.Text = Core.Strings.StringCollection["LOGIN_STATUS_LOGIN"];
			
			Socket loginsocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
			Network.SocketEvents events = new PBClient.Network.SocketEvents();
			events.OnDisconnection = new PBClient.Network.ConnectionEvent(Network.NetworkConnections.Handle_Disconnection_Login);
			events.OnReceive = new PBClient.Network.BufferEvent(Network.NetworkConnections.Handle_Receive_Login);
			Program.GameClient = null;
			Program.LoginClient = new PBClient.Network.SocketClient(loginsocket, events);
			progressLogin.Value = 16;
			
			byte tries = 0;
			while (tries < 3 && !Program.LoginClient.Connected)
			{
				try
				{
					Program.LoginClient.Connect("127.0.0.1", 8896);
					break;
				}
				catch { }
				tries++;
				System.Threading.Thread.Sleep(2000);
			}
			progressLogin.Value += 16;
			if (!Program.LoginClient.Connected)
			{
				ErrorReport.ErrorHandler.MsgBox("CONNECT_FAIL_AUTH");
				HideShow();
			}
		}
		
		public void SendAuth()
		{
			using (var auth = new Packets.AuthRequestPacket())
			{
				auth.Account = txtAccount.Text;
				auth.Password = txtPassword.Text;
				Program.LoginClient.Send(auth);
			}
		}
		public void ConnectGame(string ip,ushort port, uint uid, ulong hash)
		{
			progressLogin.Value += 16;
			lblStatus.Text = Core.Strings.StringCollection["LOGIN_STATUS_GAME"];
			Socket gamesocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
			Network.SocketEvents events = new PBClient.Network.SocketEvents();
			events.OnDisconnection = new PBClient.Network.ConnectionEvent(Network.NetworkConnections.Handle_Disconnection_Game);
			events.OnReceive = new PBClient.Network.BufferEvent(Network.NetworkConnections.Handle_Receive_Game);
			Program.GameClient = new PBClient.Network.SocketClient(gamesocket, events);
			Program.LoginClient.Disconnect("NEW_CONN");
			Program.LoginClient = null;
			
			byte tries = 0;
			while (tries < 3 && !Program.GameClient.Connected)
			{
				try
				{
					Program.GameClient.Connect(ip, (int)port);
					break;
				}
				catch { }
				tries++;
				System.Threading.Thread.Sleep(2000);
			}
			if (Program.GameClient.Connected)
			{
				progressLogin.Value += 16;
				using (var forward = new Packets.ForwardPacket())
				{
					forward.EntityUID = uid;
					forward.LoginHash = hash;
					Program.GameClient.Send(forward);
				}
			}
			else
			{
				ErrorReport.ErrorHandler.MsgBox("CONNECT_FAIL_GAME");
				HideShow();
			}
		}
		void BtnLoginClick(object sender, System.EventArgs e)
		{
			HideShow();
			ConnectAuth();
		}
	}
}
Auth response ...
Code:
//Project by BaussHacker aka. L33TS

using System;
using System.Windows.Forms;
using PBClient.Network;

namespace PBClient.Packets
{
	/// <summary>
	/// Server -> Client
	/// </summary>
	public class AuthResponsePacket : DataPacket
	{
		public AuthResponsePacket(DataPacket inPacket)
			: base(inPacket)
		{
		}
		
		public uint EntityUID
		{
			get { return ReadUInt32(4); }
			set { WriteUInt32(value, 4); }
		}
		
		public ulong LoginHash
		{
			get { return ReadUInt64(8); }
			set { WriteUInt64(value, 8); }
		}
		
		public string IPAddress
		{
			get { return ReadString(16, 16); }
			set { WriteString(value, 16); }
		}
		
		public ushort Port
		{
			get { return ReadUInt16(32); }
			set { WriteUInt16(value, 32); }
		}
		
		public static void Handle(DataPacket packet)
		{
			using (var resp = new AuthResponsePacket(packet))
			{
				if (resp.EntityUID > 1000000)
				{
					Core.Entity client = new PBClient.Core.Entity();
					client.EntityUID = resp.EntityUID;
					Core.Entity.MainClient = client;
					if (!Core.Entity.Entities.TryAdd(client.EntityUID, client))
					{
						ErrorReport.ErrorHandler.MsgBox(Enums.AuthKey.INVALID_ACCOUNT_PASS.ToString());
						Program.GameForm.Invoke(new MethodInvoker(() => {
						                                          	Screens.ScreenCollection.Login.HideShow();
						                                          }));
						return;
					}
					Program.GameForm.Invoke(new MethodInvoker(() => {
					                                          	Screens.ScreenCollection.Login.ConnectGame(resp.IPAddress, resp.Port, resp.EntityUID, resp.LoginHash);
					                                          }));
				}
				else
				{
					Enums.AuthKey key = (Enums.AuthKey)resp.Port;
					ErrorReport.ErrorHandler.MsgBox(key.ToString());

					Program.GameForm.Invoke(new MethodInvoker(() => {
					                                          	Screens.ScreenCollection.Login.HideShow();
					                                          }));
				}
			}
		}
	}
}
Server side:
Code:
//Project by BaussHacker aka. L33TS

using System;
using PBShared.Network;
using PBShared.Database;
using PBShared.Extensions;

namespace PBLoginServer.Packets
{
	/// <summary>
	/// Client -> Server
	/// </summary>
	public class AuthRequestPacket : DataPacket
	{
		public AuthRequestPacket(DataPacket inPacket)
			: base(inPacket)
		{
		}
		
		public string Account
		{
			get { return ReadString(4, 16).MakeReadable(true, false, true, false, false); }
			set { WriteString(value, 4); }
		}
		
		public string Password
		{
			get { return ReadString(20, 16).MakeReadable(true, false, true, false, false); }
			set { WriteString(value, 20); }
		}
		
		public static void Handle(Client.AuthClient client, DataPacket packet)
		{
			using (var auth = new AuthRequestPacket(packet))
			{
				Enums.AuthKey key = Enums.AuthKey.DATABASE_ERROR;
				using (AuthResponsePacket resp = new AuthResponsePacket())
				{
					try
					{
						key = Database.ServerDatabase.Authenticate(client, auth.Account, auth.Password);
						switch (key)
						{
							case Enums.AuthKey.LOGIN_OK:
								{
									uint ahash = (uint)Program.Random.Next(100000000, 999999999);
									uint bhash = (uint)Program.Random.Next(100000000, 999999999);
									client.LoginHash = (ahash + bhash);
									client.EntityUID = (uint)Program.Random.Next(1000000, 999999999);
									resp.LoginHash = client.LoginHash;
									resp.EntityUID = client.EntityUID;
									resp.IPAddress = Program.Config.ReadString("GameIP");
									resp.Port = Program.Config.ReadUInt16("GamePort");
									Database.ServerDatabase.UpateGameServer(client, ref key);
									break;
								}
						}
					}
					catch (Exception e)
					{
						Console.WriteLine(e);
						key = Enums.AuthKey.DATABASE_ERROR;
					}
					
					if (key != Enums.AuthKey.LOGIN_OK)
					{
						resp.EntityUID = 0;
						resp.LoginHash = 0;
						resp.IPAddress = "";
						resp.Port = (ushort)key;
					}
					client.Send(resp);
				}
			}
		}
	}
}
Super Aids is offline  
Thanks
1 User
Old 11/11/2013, 12:36   #3
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
Quote:
Originally Posted by Super Aids View Post
This is some very old code of mine, but...

Client's Loginscreen:
Code:
//Project by BaussHacker aka. L33TS

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Net.Sockets;

namespace PBClient.Screens
{
	/// <summary>
	/// Description of LoginScreen.
	/// </summary>
	public partial class LoginScreen : UserControl
	{
		public LoginScreen()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			this.DoubleBuffered = true;
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			
			this.BackgroundImage = Core.ImageCollection.GetImage("login", "background");
			
			btnExit.Text = Core.Strings.StringCollection["LOGIN_BTN_EXIT"];
			btnLogin.Text = Core.Strings.StringCollection["LOGIN_BTN_LOGIN"];
			lblAccount.Text = Core.Strings.StringCollection["LOGIN_LBL_ACCOUNT"];
			lblPassword.Text = Core.Strings.StringCollection["LOGIN_LBL_PASSWORD"];
			
			Core.MusicPlayer.Play("music");
		}
		
		void BtnExitClick(object sender, EventArgs e)
		{
			Program.Quit(false);
		}
		
		public void HideShow()
		{
			btnExit.Visible = !btnExit.Visible;
			btnLogin.Visible = !btnLogin.Visible;
			txtAccount.Visible = !txtAccount.Visible;
			txtPassword.Visible = !txtPassword.Visible;
			lblAccount.Visible = !lblAccount.Visible;
			lblPassword.Visible = !lblPassword.Visible;
			lblStatus.Visible = !lblStatus.Visible;
			progressLogin.Visible = !progressLogin.Visible;
		}
		
		public void ConnectAuth()
		{
			lblStatus.Text = Core.Strings.StringCollection["LOGIN_STATUS_LOGIN"];
			
			Socket loginsocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
			Network.SocketEvents events = new PBClient.Network.SocketEvents();
			events.OnDisconnection = new PBClient.Network.ConnectionEvent(Network.NetworkConnections.Handle_Disconnection_Login);
			events.OnReceive = new PBClient.Network.BufferEvent(Network.NetworkConnections.Handle_Receive_Login);
			Program.GameClient = null;
			Program.LoginClient = new PBClient.Network.SocketClient(loginsocket, events);
			progressLogin.Value = 16;
			
			byte tries = 0;
			while (tries < 3 && !Program.LoginClient.Connected)
			{
				try
				{
					Program.LoginClient.Connect("127.0.0.1", 8896);
					break;
				}
				catch { }
				tries++;
				System.Threading.Thread.Sleep(2000);
			}
			progressLogin.Value += 16;
			if (!Program.LoginClient.Connected)
			{
				ErrorReport.ErrorHandler.MsgBox("CONNECT_FAIL_AUTH");
				HideShow();
			}
		}
		
		public void SendAuth()
		{
			using (var auth = new Packets.AuthRequestPacket())
			{
				auth.Account = txtAccount.Text;
				auth.Password = txtPassword.Text;
				Program.LoginClient.Send(auth);
			}
		}
		public void ConnectGame(string ip,ushort port, uint uid, ulong hash)
		{
			progressLogin.Value += 16;
			lblStatus.Text = Core.Strings.StringCollection["LOGIN_STATUS_GAME"];
			Socket gamesocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
			Network.SocketEvents events = new PBClient.Network.SocketEvents();
			events.OnDisconnection = new PBClient.Network.ConnectionEvent(Network.NetworkConnections.Handle_Disconnection_Game);
			events.OnReceive = new PBClient.Network.BufferEvent(Network.NetworkConnections.Handle_Receive_Game);
			Program.GameClient = new PBClient.Network.SocketClient(gamesocket, events);
			Program.LoginClient.Disconnect("NEW_CONN");
			Program.LoginClient = null;
			
			byte tries = 0;
			while (tries < 3 && !Program.GameClient.Connected)
			{
				try
				{
					Program.GameClient.Connect(ip, (int)port);
					break;
				}
				catch { }
				tries++;
				System.Threading.Thread.Sleep(2000);
			}
			if (Program.GameClient.Connected)
			{
				progressLogin.Value += 16;
				using (var forward = new Packets.ForwardPacket())
				{
					forward.EntityUID = uid;
					forward.LoginHash = hash;
					Program.GameClient.Send(forward);
				}
			}
			else
			{
				ErrorReport.ErrorHandler.MsgBox("CONNECT_FAIL_GAME");
				HideShow();
			}
		}
		void BtnLoginClick(object sender, System.EventArgs e)
		{
			HideShow();
			ConnectAuth();
		}
	}
}
Auth response ...
Code:
//Project by BaussHacker aka. L33TS

using System;
using System.Windows.Forms;
using PBClient.Network;

namespace PBClient.Packets
{
	/// <summary>
	/// Server -> Client
	/// </summary>
	public class AuthResponsePacket : DataPacket
	{
		public AuthResponsePacket(DataPacket inPacket)
			: base(inPacket)
		{
		}
		
		public uint EntityUID
		{
			get { return ReadUInt32(4); }
			set { WriteUInt32(value, 4); }
		}
		
		public ulong LoginHash
		{
			get { return ReadUInt64(8); }
			set { WriteUInt64(value, 8); }
		}
		
		public string IPAddress
		{
			get { return ReadString(16, 16); }
			set { WriteString(value, 16); }
		}
		
		public ushort Port
		{
			get { return ReadUInt16(32); }
			set { WriteUInt16(value, 32); }
		}
		
		public static void Handle(DataPacket packet)
		{
			using (var resp = new AuthResponsePacket(packet))
			{
				if (resp.EntityUID > 1000000)
				{
					Core.Entity client = new PBClient.Core.Entity();
					client.EntityUID = resp.EntityUID;
					Core.Entity.MainClient = client;
					if (!Core.Entity.Entities.TryAdd(client.EntityUID, client))
					{
						ErrorReport.ErrorHandler.MsgBox(Enums.AuthKey.INVALID_ACCOUNT_PASS.ToString());
						Program.GameForm.Invoke(new MethodInvoker(() => {
						                                          	Screens.ScreenCollection.Login.HideShow();
						                                          }));
						return;
					}
					Program.GameForm.Invoke(new MethodInvoker(() => {
					                                          	Screens.ScreenCollection.Login.ConnectGame(resp.IPAddress, resp.Port, resp.EntityUID, resp.LoginHash);
					                                          }));
				}
				else
				{
					Enums.AuthKey key = (Enums.AuthKey)resp.Port;
					ErrorReport.ErrorHandler.MsgBox(key.ToString());

					Program.GameForm.Invoke(new MethodInvoker(() => {
					                                          	Screens.ScreenCollection.Login.HideShow();
					                                          }));
				}
			}
		}
	}
}
Server side:
Code:
//Project by BaussHacker aka. L33TS

using System;
using PBShared.Network;
using PBShared.Database;
using PBShared.Extensions;

namespace PBLoginServer.Packets
{
	/// <summary>
	/// Client -> Server
	/// </summary>
	public class AuthRequestPacket : DataPacket
	{
		public AuthRequestPacket(DataPacket inPacket)
			: base(inPacket)
		{
		}
		
		public string Account
		{
			get { return ReadString(4, 16).MakeReadable(true, false, true, false, false); }
			set { WriteString(value, 4); }
		}
		
		public string Password
		{
			get { return ReadString(20, 16).MakeReadable(true, false, true, false, false); }
			set { WriteString(value, 20); }
		}
		
		public static void Handle(Client.AuthClient client, DataPacket packet)
		{
			using (var auth = new AuthRequestPacket(packet))
			{
				Enums.AuthKey key = Enums.AuthKey.DATABASE_ERROR;
				using (AuthResponsePacket resp = new AuthResponsePacket())
				{
					try
					{
						key = Database.ServerDatabase.Authenticate(client, auth.Account, auth.Password);
						switch (key)
						{
							case Enums.AuthKey.LOGIN_OK:
								{
									uint ahash = (uint)Program.Random.Next(100000000, 999999999);
									uint bhash = (uint)Program.Random.Next(100000000, 999999999);
									client.LoginHash = (ahash + bhash);
									client.EntityUID = (uint)Program.Random.Next(1000000, 999999999);
									resp.LoginHash = client.LoginHash;
									resp.EntityUID = client.EntityUID;
									resp.IPAddress = Program.Config.ReadString("GameIP");
									resp.Port = Program.Config.ReadUInt16("GamePort");
									Database.ServerDatabase.UpateGameServer(client, ref key);
									break;
								}
						}
					}
					catch (Exception e)
					{
						Console.WriteLine(e);
						key = Enums.AuthKey.DATABASE_ERROR;
					}
					
					if (key != Enums.AuthKey.LOGIN_OK)
					{
						resp.EntityUID = 0;
						resp.LoginHash = 0;
						resp.IPAddress = "";
						resp.Port = (ushort)key;
					}
					client.Send(resp);
				}
			}
		}
	}
}
i think this code is helpful , could you please upload the source to test it .. ?
abdeen is offline  
Old 11/11/2013, 13:26   #4
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 946
.. removed it again. I don't really want it leaked :3
Super Aids is offline  
Thanks
1 User
Old 11/11/2013, 13:42   #5
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
thanx brother i will try it , but i think that i need a project which no need to SDL Library , cuz i am not coding a game .

anyway let met test your project then i will post here my progress .

thanx in advace ..
abdeen is offline  
Old 11/11/2013, 13:44   #6
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 946
I know, it was just in order to get it to work as it wouldn't compile without it
Super Aids is offline  
Old 11/11/2013, 15:06   #7
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
i checked it and it was so hard for me ,, and all i was asking is just how to get packets ids if i have a client contains 2 boxs for username and password , and how they work with conquer online server source 5518+ which is packet 1052 , 1051 , 1055 is the packet which working on this operation .. got me ?
abdeen is offline  
Old 11/12/2013, 05:22   #8
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,377
... you write a program to do it.

I'm sorry but your questions are still just as mindlessly stupid as they were when you first joined the forum.

You decide what type of application you want to write for your client (likely a winform in C#)

You add textboxes and buttons to that forum

You set the onclick action for one of those buttons to perform certain actions.


In this case clicking the login button would trigger the creation of a new instance of the client encryption system and begin sending the properly populated packets to the server to trigger the login process.


It's literally the exact same thing as writing your server except you're writing a program to send the required data TO the server.

It's the same encryption systems, the same packet structures, the same packet sequences.


If you are not looking to create a proper standalone bot (not something I predict you have the knowledge to do given only a handful of members on here have the required systems and knowledge to pull it off and not be instantly botjailed) then I'd suggest you start with a simple chat program where you have a client/server talk to eachother using your own custom packet structures that fit your needs (such as authentication and sending messages or actions between them)

You can then expand that framework and the knowledge you gained writing it to whatever your true project is... but yah, you will have a very hard time writing a standalone bot if you cannot even drag and drop a text box and button onto a winform.
pro4never is offline  
Thanks
1 User
Old 11/12/2013, 12:56   #9
 
abdeen's Avatar
 
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
Quote:
Originally Posted by pro4never View Post
... you write a program to do it.

I'm sorry but your questions are still just as mindlessly stupid as they were when you first joined the forum.

You decide what type of application you want to write for your client (likely a winform in C#)

You add textboxes and buttons to that forum

You set the onclick action for one of those buttons to perform certain actions.


In this case clicking the login button would trigger the creation of a new instance of the client encryption system and begin sending the properly populated packets to the server to trigger the login process.


It's literally the exact same thing as writing your server except you're writing a program to send the required data TO the server.

It's the same encryption systems, the same packet structures, the same packet sequences.


If you are not looking to create a proper standalone bot (not something I predict you have the knowledge to do given only a handful of members on here have the required systems and knowledge to pull it off and not be instantly botjailed) then I'd suggest you start with a simple chat program where you have a client/server talk to eachother using your own custom packet structures that fit your needs (such as authentication and sending messages or actions between them)

You can then expand that framework and the knowledge you gained writing it to whatever your true project is... but yah, you will have a very hard time writing a standalone bot if you cannot even drag and drop a text box and button onto a winform.
Thanks you brother for reply my post ,, i know that you hate me long time ago O.o
Well .. Look here is Server Auth new connection and auth receive codes , "I am using Conquer Online Full Socket for Chat server "

Code:
#region AuthServer_AnnounceNewConnection
        static void AuthServer_AnnounceNewConnection(Interfaces.ISocketWrapper obj)
        {
            Client.AuthState authState = new Client.AuthState(obj.Socket);
            authState.Cryptographer = new Network.Cryptography.AuthCryptography();
            Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed();
            pcs.Seed = ServerBase.Kernel.Random.Next();
            authState.PasswordSeed = pcs.Seed;
            authState.Send(pcs);
            obj.Connector = authState;
            WriteLine("New Connection");
        }
        #endregion
        #region AuthServer_AnnounceReceive
        static void AuthServer_AnnounceReceive(byte[] arg1, Interfaces.ISocketWrapper arg2)
        {
            WriteLine("New AuthServer_AnnounceReceive with arg1.Length = " + arg1.Length);
            if (arg1.Length == 14)
            {
                Client.AuthState user = arg2.Connector as Client.AuthState;
                user.Cryptographer.Decrypt(arg1);
                user.Info = new Authentication();
                WriteLine("user.Info.Username : " + user.Info.Username);
                user.Info.Deserialize(arg1);
                user.Account = new AccountTable(user.Info.Username);
                msvcrt.msvcrt.srand(user.PasswordSeed);

                byte[] encpw = new byte[16];
                var rc5Key = new byte[0x10];
                for (int i = 0; i < 0x10; i++)
                    rc5Key[i] = (byte)msvcrt.msvcrt.rand();

                Buffer.BlockCopy(arg1, 132, encpw, 0, 16);
                var password = "";
                try
                {

                    password = System.Text.Encoding.ASCII.GetString(
                                        (new Network.Cryptography.ConquerPasswordCryptpographer(user.Info.Username)).Decrypt(
                                            (new Network.Cryptography.RC5(rc5Key)).Decrypt(encpw)));

                    password = password.Split('\0')[0];
                }
                catch
                {
                    MessageBox.Show("Invalid client version you must have client Verion 5550.");
                    return;
                }
                string NoNumPadNumbers = "";
                foreach (char c in password)
                {
                    switch (c.ToString())
                    {
                        case "-": NoNumPadNumbers += "0"; break;
                        case "#": NoNumPadNumbers += "1"; break;
                        case "(": NoNumPadNumbers += "2"; break;
                        case "\"": NoNumPadNumbers += "3"; break;
                        case "%": NoNumPadNumbers += "4"; break;
                        case "\f": NoNumPadNumbers += "5"; break;
                        case "'": NoNumPadNumbers += "6"; break;
                        case "$": NoNumPadNumbers += "7"; break;
                        case "&": NoNumPadNumbers += "8"; break;
                        case "!": NoNumPadNumbers += "9"; break;
                        default: NoNumPadNumbers += c; break;
                    }
                }
                password = NoNumPadNumbers;
                Forward Fw = new Forward();
                if (password == user.Account.Password)
                {
                    if (user.Account.State == AccountTable.AccountState.Banned)
                        Fw.Type = Forward.ForwardType.Banned;
                    else
                        Fw.Type = Forward.ForwardType.Ready;
                }
                else
                {
                    Fw.Type = Forward.ForwardType.InvalidInfo;
                }
                if (Fw.Type != Network.AuthPackets.Forward.ForwardType.InvalidInfo)
                {

                    Fw.Identifier = Network.AuthPackets.Forward.Incrementer.Next;
                    ServerBase.Kernel.AwaitingPool.Add(Fw.Identifier, user.Account);
                }
                Fw.IP = GameIP;
                Fw.Port = GamePort;
                user.Send(Fw);
            }
            else
            {

                arg2.Socket.Disconnect(false);
            }
        }
        #endregion
i changed
Code:
if (arg1.Length == 76)
to

Code:
if (arg1.Length == 14)
cuz ... when i sent this "NEW_CONNECTION" to server using this code
Code:
byte[] buffer = Encoding.ASCII.GetBytes("NEW_CONNECTION");
                    Authserver.Send(buffer);
and this code show me length :
Code:
WriteLine("New AuthServer_AnnounceReceive with arg1.Length = " + arg1.Length);
i got it 14

Code:
public partial class LoginWindow : Form
    {
        private Socket Authserver;
        private Socket ChatServer;
        int AuthPort = 9959;
        int ChatPort = 5816;
        string Username, Password;
        public LoginWindow()
        {
            InitializeComponent();
        }

        private void cancel_button_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void login_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (Canconnect())
                {
                    byte[] buffer = Encoding.ASCII.GetBytes("NEW_CONNECTION");
                    Authserver.Send(buffer);
                }
            }
            catch (Exception es) { MessageBox.Show(es.Message); }
        }

        private void register_link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

        }

        private void resetpass_link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

        }

        private void LoginWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            Environment.Exit(0);
        }
        public static ManualResetEvent allDone = new ManualResetEvent(false);
        private bool Canconnect()
        {
            try
            {
                string host = Dns.GetHostName();
                IPAddress[] IPs = Dns.GetHostAddresses(host);
                allDone.Reset();
                Authserver.BeginConnect(IPs, AuthPort, new AsyncCallback(ConnectCallback), Authserver);
                allDone.WaitOne();
            }
            catch (Exception e) { MessageBox.Show(e.Message); }
            return true;
        }

        private void LoginWindow_Load(object sender, EventArgs e)
        {
            Authserver = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        }
        public static void ConnectCallback(IAsyncResult ar)
        {
            try
            {
                allDone.Set();
                Socket s = (Socket)ar.AsyncState;
                s.EndConnect(ar);
            }
            catch (Exception e) { MessageBox.Show(e.Message); }
        }

        private void username_box_TextChanged(object sender, EventArgs e)
        {
            Username = username_box.Text;
        }

        private void password_box_TextChanged(object sender, EventArgs e)
        {
            Password = password_box.Text;
        }
    }
so whats is next edit in server socket " auth receive " to make it compile with the client and read or get username and password ??

i am learning step by step am not stupid ... brother :P
abdeen is offline  
Old 11/12/2013, 13:17   #10
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 946
Canconnect() will ALWAYS return true in your case, because you only return true and even if it fails then you don't return false.

Also wheter it could connect or not is in the callback not in BeginConnect. BeginConnect will only assign the asynchronous event with the callback you have specified, but it does not actually proceed to connect before the callback and when you call EndConnect.

On the other hand it's not necessary to use Asynchronous sockets for the client, considering it will only have 1 connection.
Super Aids is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
send/receive structs instead of ...
06/21/2013 - CO2 Programming - 8 Replies
i was checking out chat applications in c++ and found this int ServerThread(int ID) { Buffer sbuffer; char* Recv = new char; ZeroMemory(Recv, 256); // In Send we will copy the content of the struct
No receive packets
05/31/2013 - Mabinogi - 9 Replies
Alissa works for me but there are no receive packets displayed. Everything is send. Any idea what this means?
[REQUEST] packets send list , or anyway to sniff send packets
08/10/2012 - Kal Online - 16 Replies
hey everyone , as mentioned , i wanna know if anyone got a complete send packets lists or anyway i can sniff send packets , thanks in advance
How?- receive packets -nuconnector&.Net
08/25/2011 - SRO Coding Corner - 3 Replies
what is the best way to receive data from nuconnector on .Net ?? byte , List<byte> ,List<ArraySegment<byte>>; or what ?? and what is the format that Nuconnector us to send data to the bot !!! ?
WPE Doesn't receive any packets (reason: server or wud? @.@)
09/09/2010 - Ragnarok Online - 1 Replies
Ok. I am a newbie and am new to WPE. I searched, I read, I followed; still, i don't see any packets on my WPE. I already targeted my ro program, and started logging -> Packets : 0 >.<"" (i moved, dropped, picked things, ran around ig tho). The server i tried on was DreamerRo Nightmare Low rate (CS-Arena.com - professionelles Game-, Rootserver- & Housingbusiness). Sooo yea... I really appreciate every piece of advice from everyone. *-* Thankss:confused:



All times are GMT +2. The time now is 17:24.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.