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.
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
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 ?
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.
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
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.
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?
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: