|
You last visited: Today at 13:13
Advertisement
C# Get Username and password from the Client using sockets ?
Discussion on C# Get Username and password from the Client using sockets ? within the CO2 Programming forum part of the Conquer Online 2 category.
04/15/2014, 19:44
|
#1
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
|
C# Get Username and password from the Client using sockets ?
Hello , i have a server a client , client have two text box's for Username and password and when i press Login button in the client it shall connect to the server login socket , and the server login socket will check the packet number , if its the specified one for login for example ( 1051) so it will get the username and password value to check if they are same in the database or not , so i can`t do this til now , any help ?
i have an online game code for the server but i don't know the client side how is it ..
here is the code for login at Server
Code:
#region AuthServer_AnnounceReceive
static void AuthServer_AnnounceReceive(byte[] arg1, Interfaces.ISocketWrapper arg2)
{
if (arg1.Length == 240)
{
Client.AuthState player = arg2.Connector as Client.AuthState;
player.Cryptographer.Decrypt(arg1);
//player.Info = new Authentication();
//player.Info.Deserialize(arg1);
byte[] usernamearray = new byte[16];
Buffer.BlockCopy(arg1, 8, usernamearray, 0, 16);
var username = Encoding.Default.GetString(usernamearray).Replace("\0", "");
player.Account = new TQ_Server.Game_Database.cq_account.Table(username);
byte[] passwordarray = new byte[16];
Buffer.BlockCopy(arg1, 72, passwordarray, 0, 16);
var password = (Encoding.Default.GetString(passwordarray).Replace("\0", "")).Split('\0')[0];
}
else
{
arg2.Socket.Disconnect(false);
}
}
#endregion:rolleyes:
|
|
|
04/16/2014, 14:46
|
#2
|
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
|
check this better

SuperAids 's chat project
why u use Cryptographer.Decrypt?
u just need to getbytes from the selected offset then get string then search for the string in the database
|
|
|
04/16/2014, 15:02
|
#3
|
elite*gold: 0
Join Date: Feb 2006
Posts: 726
Received Thanks: 271
|
What patch?
That is the most important thing.
The amount of crypto changes and password seeds and all that wonderful stuff that has changed over the years.
Is it even Conquer or a different TQ game??
I haven't worked with higher patch servers, but 240 for the length of the authorization packet seems high to me. But in higher patches maybe thats what it is
|
|
|
04/16/2014, 15:31
|
#4
|
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
|
Quote:
Originally Posted by Aceking
What patch?
That is the most important thing.
The amount of crypto changes and password seeds and all that wonderful stuff that has changed over the years.
Is it even Conquer or a different TQ game??
I haven't worked with higher patch servers, but 240 for the length of the authorization packet seems high to me. But in higher patches maybe thats what it is
|
now 312 Lenght
|
|
|
04/16/2014, 16:29
|
#5
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
|
Quote:
Originally Posted by abdoumatrix
check this better

SuperAids 's chat project
why u use Cryptographer.Decrypt?
u just need to getbytes from the selected offset then get string then search for the string in the database
|
i will check this source but i am not using Cryptographer.Decrypt, i just posted a sample from conquer ...
Quote:
Originally Posted by Aceking
What patch?
That is the most important thing.
The amount of crypto changes and password seeds and all that wonderful stuff that has changed over the years.
Is it even Conquer or a different TQ game??
I haven't worked with higher patch servers, but 240 for the length of the authorization packet seems high to me. But in higher patches maybe thats what it is
|
Quote:
Originally Posted by abdoumatrix
now 312 Lenght 
|
i am talking about sockets not about CONQUER sockets
EDIT :
another question , how i can serialize and send an packet struct , something like this :
PHP Code:
struct LoginForm
{
public string Username;
public string Password;
}
|
|
|
04/16/2014, 19:18
|
#6
|
elite*gold: 0
Join Date: Feb 2006
Posts: 726
Received Thanks: 271
|
Once you hit enter on the login screen, the client then opens a connection to the authentication server.
Once this connection has been accepted and receive has been called in the socket, then the authentication server receives packet 1051.
Using this packet, you get the username and password depending on the crypto method for that patch.
|
|
|
04/16/2014, 20:35
|
#7
|
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
|
I got Lost
u wanna make a program when u log in using a specific username and pass
and the server search for this username and send the info back.
if so
u need to send for example
username string with max. lenght = 16 at offset 4 for expample.
and pass string with max. lenght = 16 at offset 4+16
from client
and the server get it pack and send the info back into another packet
|
|
|
04/16/2014, 22:41
|
#8
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
|
Quote:
Originally Posted by Aceking
Once you hit enter on the login screen, the client then opens a connection to the authentication server.
Once this connection has been accepted and receive has been called in the socket, then the authentication server receives packet 1051.
Using this packet, you get the username and password depending on the crypto method for that patch.
|
Great , but you are talking about Conquer , its Dot net Chat System ...
|
|
|
04/16/2014, 22:46
|
#9
|
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
|
Quote:
Originally Posted by abdeen
Great , but you are talking about Conquer , its Dot net Chat System ...
|
all the same , all using socket , all using packets.
PS: i'm talk about a client program request info by username and pass with packets
|
|
|
04/16/2014, 22:57
|
#10
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
|
Quote:
Originally Posted by abdoumatrix
I got Lost
u wanna make a program when u log in using a specific username and pass
and the server search for this username and send the info back.
if so
u need to send for example
username string with max. lenght = 16 at offset 4 for expample.
and pass string with max. lenght = 16 at offset 4+16
from client
and the server get it pack and send the info back into another packet
|
could you tell me what about this ?
client Side :
Code:
public class Packet
{
[Serializable]
public class LoginPacket
{
private short Packet;
private int MaxLength;
private string Username;
private string Password;
public LoginPacket(string _Username, string _Password)
{
Packet = 1001;
this.MaxLength = 16;
this.Username = _Username;
this.Password = _Password;
}
}
public static byte[] GetPacketBytes(LoginPacket packetHdr)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(ms, packetHdr);
return ms.ToArray();
}
}
Code:
private void LOGIN_BUTTON_Click(object sender, EventArgs e)
{
Network.Packets.Packet.LoginPacket LOGIN = new Network.Packets.Packet.LoginPacket(USERNAME_BOX.Text, PASSWORD_BOX.Text);
byte[] Packet = Network.Packets.PacketS.GetPacketBytes(LOGIN);
Send(Packet);
}
Code:
private void LOGIN_BUTTON_Click(object sender, EventArgs e)
{
private void Send(Byte[] Buffer)
{
if (Buffer != null)
{
ChatSocket.Connection.Send(Buffer);
}
}
Server Side :
Code:
public void AuthReceive(YukiSocketClient Sender, byte[] packet)
{
Network.Packets.Packet.LoginPacket BB = Network.Packets.Packet.GetPacketObject(packet);
}
Code:
public class Packet
{
[Serializable]
public class LoginPacket
{
private short Packet;
private int MaxLength;
private string Username;
private string Password;
}
public static LoginPacket GetPacketObject(byte[] packetBytes)
{
MemoryStream ms = new MemoryStream();
ms.Write(packetBytes, 0, packetBytes.Length);
ms.Position = 0;
BinaryFormatter formatter = new BinaryFormatter();
return formatter.Deserialize(ms) as LoginPacket;
}
}
|
|
|
04/17/2014, 00:10
|
#11
|
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
|
I'm not fimiliar with ur code
but i think 16 packet lenght? for whole packet that is too short
2 + 2 + 16 +16 = 36 is min. lenght that could fit.
i would prefer using this for write
PHP Code:
public static void WriteString(string arg, int offset, byte[] buffer) { if (buffer == null) return; if (offset > buffer.Length - 1) return; byte[] argEncoded = Program.Encoding.GetBytes(arg); if (buffer.Length >= offset + arg.Length) Array.Copy(argEncoded, 0, buffer, offset, arg.Length); }
and this for reading
PHP Code:
public static void ReadString(out string value, int offset, byte[] buffer) { value = Program.Encoding.GetString(buffer, (offset + 1), buffer[offset]); }
|
|
|
04/17/2014, 03:33
|
#12
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
|
Quote:
Originally Posted by abdoumatrix
I'm not fimiliar with ur code
but i think 16 packet lenght? for whole packet that is too short
2 + 2 + 16 +16 = 36 is min. lenght that could fit.
i would prefer using this for write
PHP Code:
public static void WriteString(string arg, int offset, byte[] buffer)
{
if (buffer == null)
return;
if (offset > buffer.Length - 1)
return;
byte[] argEncoded = Program.Encoding.GetBytes(arg);
if (buffer.Length >= offset + arg.Length)
Array.Copy(argEncoded, 0, buffer, offset, arg.Length);
}
and this for reading
PHP Code:
public static void ReadString(out string value, int offset, byte[] buffer)
{
value = Program.Encoding.GetString(buffer, (offset + 1), buffer[offset]);
}
|
Thanks Button was pressed ... can i get a sample ?
|
|
|
04/17/2014, 12:24
|
#13
|
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
|
first:
i think to make ur code work
try this
PHP Code:
public LoginPacket(string _Username, string _Password) { Packet = 1001; this.MaxLength = 4 + _Username.Lenght + _password.Lenght; this.Username = _Username; this.Password = _Password; }
Secend:
use conquer packet writer
PHP Code:
class LoginPacket { public byte[] packets; /// <summary> /// use it like this from client to server /// LoginPacket login = new LoginPacket(true, "new", "new"); /// send(login.ToArray()); /// /// and from server to client /// LoginPacket login = new LoginPacket(false); /// login.GetValues(recivedbytes); // will get the values for u from the recived bytes /// </summary> public LoginPacket(bool send ,string username="", string pass="") { if (send) { packets = new byte[4 + 16/*username.Length*/ + 16/*pass.Length*/]; Writer.Ushort(1001, 2, packets); Writer.Ushort((ushort)packets.Length, 0, packets); User = username; Pass = pass; } } /// <summary> /// Max Lenght For username and password /// </summary> int Max_Lenght = 16; public string User { get { return Encoding.Default.GetString(packets, 4, Max_Lenght); } set { Writer.String(value, 4, packets); } }
public string Pass { get { return Encoding.Default.GetString(packets, 4+16, Max_Lenght); } set { Writer.String(value, 4, packets); } }
public void GetValues(byte[] packet) { packets = packet; }
public byte[] ToArray() { return packets; } }
|
|
|
04/17/2014, 16:38
|
#14
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
|
Quote:
Originally Posted by abdoumatrix
first:
i think to make ur code work
try this
PHP Code:
public LoginPacket(string _Username, string _Password)
{
Packet = 1001;
this.MaxLength = 4 + _Username.Lenght + _password.Lenght;
this.Username = _Username;
this.Password = _Password;
}
Secend:
use conquer packet writer
PHP Code:
class LoginPacket
{
public byte[] packets;
/// <summary>
/// use it like this from client to server
/// LoginPacket login = new LoginPacket(true, "new", "new");
/// send(login.ToArray());
///
/// and from server to client
/// LoginPacket login = new LoginPacket(false);
/// login.GetValues(recivedbytes); // will get the values for u from the recived bytes
/// </summary>
public LoginPacket(bool send ,string username="", string pass="")
{
if (send)
{
packets = new byte[4 + 16/*username.Length*/ + 16/*pass.Length*/];
Writer.Ushort(1001, 0, packets);
Writer.Ushort((ushort)packets.Length, 2, packets);
User = username;
Pass = pass;
}
}
/// <summary>
/// Max Lenght For username and password
/// </summary>
int Max_Lenght = 16;
public string User
{
get
{
return Encoding.Default.GetString(packets, 4, Max_Lenght);
}
set
{
Writer.String(value, 4, packets);
}
}
public string Pass
{
get
{
return Encoding.Default.GetString(packets, 4+16, Max_Lenght);
}
set
{
Writer.String(value, 4, packets);
}
}
public void GetValues(byte[] packet)
{
packets = packet;
}
public byte[] ToArray()
{
return packets;
}
}
|
thanks brother , its was helpful code , i changed it to be like this :
Server Side :
Code:
public class LoginPacket
{
public byte[] Buffer;
public LoginPacket()
{
// TODO: Complete member initialization
}
public string Username
{
get
{
return Encoding.Default.GetString(Buffer, 4, 16);
}
set
{
Writer.WriteString(value, 4, Buffer);
}
}
public string Password
{
get
{
return Encoding.Default.GetString(Buffer, 20, 16);
}
set
{
Writer.WriteString(value, 20, Buffer);
}
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
public byte[] ToArray()
{
return Buffer;
}
}
Code:
#region AuthServer_AnnounceReceive
static void AuthServer_AnnounceReceive(byte[] arg1, ISocketWrapper arg2)
{
if (arg1.Length == 36)
{
Client.AuthState player = arg2.Connector as Client.AuthState;
player.Info = new Network.LoginPacket();
player.Info.Deserialize(arg1);
byte[] usernamearray = new byte[16];
Buffer.BlockCopy(arg1, 4, usernamearray, 0, 16);
var username = Encoding.Default.GetString(usernamearray).Replace("\0", "");
player.Account = new Database.Account(username);
byte[] passwordarray = new byte[16];
Buffer.BlockCopy(arg1, 20, passwordarray, 0, 16);
var password = (Encoding.Default.GetString(passwordarray).Replace("\0", "")).Split('\0')[0];
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;
Network.Forward Fw = new Network.Forward();
if (password == player.Account.Password)
{
if (player.Account.State == Account.AccountState.Banned)
Fw.Type = Network.Forward.ForwardType.Banned;
else
Fw.Type = Network.Forward.ForwardType.Ready;
}
else
{
Fw.Type = Network.Forward.ForwardType.InvalidInfo;
}
if (Fw.Type != Network.Forward.ForwardType.InvalidInfo)
{
Fw.Identifier = Network.Forward.Incrementer.Next;
ServerBase.Kernel.AwaitingPool.Add(Fw.Identifier, player.Account);
}
Fw.IP = "127.0.0.1";
Fw.Port = 8888;
player.Send(Fw);
}
else
{
arg2.Socket.Disconnect(false);
}
}
#endregion
Client Side
Code:
public class LoginPacket
{
public byte[] Buffer;
public LoginPacket(bool send, string username, string pass)
{
if (send)
{
Buffer = new byte[36];
Writer.WriteUInt16(1001, 0, Buffer);
Writer.WriteUInt16((ushort)Buffer.Length, 2, Buffer);
Username = username;
Password = pass;
}
}
public string Username
{
get
{
return Encoding.Default.GetString(Buffer, 4, 16);
}
set
{
Writer.WriteString(value, 4, Buffer);
}
}
public string Password
{
get
{
return Encoding.Default.GetString(Buffer, 20, 16);
}
set
{
Writer.WriteString(value, 20, Buffer);
}
}
public void Deserialize(byte[] buffer)
{
Buffer = buffer;
}
public byte[] ToArray()
{
return Buffer;
}
}
Code:
private void LOGIN_BUTTON_Click(object sender, EventArgs e)
{
Network.LoginPacket login = new Network.LoginPacket(true, USERNAME_BOX.Text, PASSWORD_BOX.Text);
Send(login.ToArray());
}
private void Send(Byte[] Buffer)
{
if (Buffer != null)
{
AuthServer.Connection.Send(Buffer);
}
}
all works fine , but now i want to make or change this socket library to make it for client i mean connect and receive incoming bytes , i tried many times but fails ...
here is Server socket [ its related to Conquer 5517+ Server files ] and i wanna make edits to make it Client socket which connect to server ,receive and send bytes .
Socket Files .
Code:
public class WinSocket
{
private Socket Connection;
private bool disconnected = false;
public bool Disabled = false;
public WinSocket()
{
Connection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
public WinSocket(Socket socket)
{
Connection = socket;
}
public void Bind(EndPoint point)
{
if (disconnected) return;
Connection.Bind(point);
}
public void Listen(int backlog)
{
if (disconnected) return;
Connection.Listen(backlog);
}
public void BeginAccept(AsyncCallback async, object state)
{
if (Disabled) return;
try
{
if (disconnected) return;
Connection.BeginAccept(async, state);
}
catch
{
Disabled = true;
}
}
public void BeginReceive(byte[] buffer, int offset, int size, SocketFlags flag, AsyncCallback callback, object state)
{
if (Disabled) return;
try
{
if (disconnected || !Connected) return;
Connection.BeginReceive(buffer, offset, size, flag, callback, state);
}
catch
{
Disabled = true;
}
}
public int EndReceive(IAsyncResult res, out SocketError err)
{
err = SocketError.Disconnecting;
if (Disabled) return 0;
try
{
if (!Usable) return 0;
return Connection.EndReceive(res, out err);
}
catch
{
Disabled = true;
}
return 0;
}
public Socket EndAccept(IAsyncResult async)
{
if (Disabled) return null;
try
{
if (disconnected) return null;
return Connection.EndAccept(async);
}
catch
{
Disabled = true;
}
return null;
}
public Socket Accept()
{
if (Disabled) return null;
try
{
if (disconnected) return null;
return Connection.Accept();
}
catch
{
Disabled = true;
}
return null;
}
public void Close()
{
//Connection.Close();
}
public void Send(byte[] buffer)
{
if (Disabled) return;
try
{
if (disconnected) return;
Connection.Send(buffer);
}
catch
{
Disabled = true;
}
}
public void Disconnect(bool reuse)
{
if (Disabled) return;
try
{
if (!disconnected)
disconnected = true;
else
return;
Connection.Disconnect(reuse);
}
catch
{
Disabled = true;
}
}
public void Shutdown(SocketShutdown type)
{
//Connection.Shutdown(type);
}
public bool Connected
{
get
{
if (Disabled) return false;
try
{
if (disconnected) return false;
return Connection.Connected;
}
catch
{
Disabled = true;
}
return false;
}
}
public int Receive(byte[] buffer)
{
if (disconnected) return 0;
return Connection.Receive(buffer);
}
public EndPoint RemoteEndPoint
{
get
{
if (Disabled) return new IPEndPoint(1, 1);
try
{
return Connection.RemoteEndPoint;
}
catch
{
Disabled = true;
}
return new IPEndPoint(1, 1);
}
}
private bool Usable
{
get
{
return !disconnected;
}
}
public void Disable()
{
try
{
Disabled = true;
Connection.Close();
}
catch
{
Disabled = true;
}
}
}
Code:
public class SyncSocketWrapper : Interfaces.ISocketWrapper
{
public int BufferSize
{
get;
set;
}
public byte[] Buffer
{
get;
set;
}
public WinSocket Socket
{
get;
set;
}
public object Connector
{
get;
set;
}
public Interfaces.ISocketWrapper Create(Socket socket)
{
BufferSize = 8000;
Socket = new WinSocket(socket);
Buffer = new byte[BufferSize];
return this;
}
private Thread thread;
private SyncSocket Server;
public void BeginReceive(SyncSocket server)
{
Server = server;
thread = new Thread(new ThreadStart(Receive));
thread.Start();
}
private void Receive()
{
try
{
while (Socket.Connected)
{
try
{
int RecvSize = Socket.Receive(Buffer);
if (RecvSize > 0)
{
byte[] buffer = new byte[RecvSize];
for (int i = 0; i < RecvSize; i++)
{
buffer[i] = Buffer[i];
}
Server.InvokeOnClientReceive(this, buffer);
}
else
{
Server.InvokeDisconnect(this);
return;
}
}
catch (SocketException)
{
Server.InvokeDisconnect(this);
return;
}
catch (ObjectDisposedException)
{
Server.InvokeDisconnect(this);
return;
}
catch (Exception e) { MessageBox.Show(e.Message); }
}
Server.InvokeDisconnect(this);
return;
}
catch (ThreadAbortException)
{
Server.InvokeDisconnect(this);
return;
}
}
}
Code:
public class SyncSocket
{
private WinSocket Connection = new WinSocket();
private bool enabled;
public event Action<Interfaces.ISocketWrapper> OnClientConnect;
public event Action<Interfaces.ISocketWrapper> OnClientDisconnect;
public event Action<byte[], Interfaces.ISocketWrapper> OnClientReceive;
private ushort port;
private Thread mainThread;
public SyncSocket(ushort port)
{
if (!this.enabled)
{
this.port = port;
this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port));
this.Connection.Listen(10);
this.enabled = true;
mainThread = new Thread(new ThreadStart(this.SyncConnect));
mainThread.Start();
}
}
private void SyncConnect()
{
try
{
while (true)
{
if (Connection.Disabled)
return;
if (!this.enabled)
return;
SyncSocketWrapper sender = null;
try
{
sender = new SyncSocketWrapper();
sender.Create(this.Connection.Accept());
if (this.OnClientConnect != null)
{
this.OnClientConnect(sender);
}
sender.BeginReceive(this);
}
catch (SocketException e)
{
MessageBox.Show(e.Message);
}
catch (ObjectDisposedException e)
{
MessageBox.Show(e.Message);
}
catch (Exception e) { MessageBox.Show(e.Message); }
}
}
catch (ThreadAbortException e)
{
MessageBox.Show(e.Message);
}
}
public void InvokeOnClientConnect(SyncSocketWrapper sender)
{
if (this.OnClientConnect != null)
{
this.OnClientConnect(sender);
}
}
public void InvokeOnClientReceive(SyncSocketWrapper sender, byte[] buffer)
{
if (this.OnClientReceive != null)
{
this.OnClientReceive(buffer, sender);
}
}
public void Disable()
{
if (this.enabled)
{
this.Connection.Disable();
this.enabled = false;
}
}
public void Enable()
{
if (!this.enabled)
{
this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port));
this.Connection.Listen(100);
this.enabled = true;
if (mainThread != null)
{
mainThread.Abort();
mainThread = null;
}
mainThread = new Thread(new ThreadStart(this.SyncConnect));
mainThread.Start();
}
}
private void enabledCheck(string Variable)
{
if (this.enabled)
{
throw new Exception("Cannot modify " + Variable + " while socket is enabled.");
}
}
public void InvokeDisconnect(SyncSocketWrapper Client)
{
if (Client != null)
{
try
{
if (Client.Socket.Connected)
{
Client.Socket.Disconnect(false);
Client.Socket.Shutdown(SocketShutdown.Both);
Client.Socket.Close();
if (this.OnClientDisconnect != null)
this.OnClientDisconnect(Client);
Client.Connector = null;
Client = null;
}
else
{
Client.Socket.Shutdown(SocketShutdown.Both);
Client.Socket.Close();
if (this.OnClientDisconnect != null)
this.OnClientDisconnect(Client);
Client.Connector = null;
Client = null;
}
}
catch (ObjectDisposedException e)
{
MessageBox.Show(e.Message);
}
}
}
public bool Enabled
{
get
{
return this.enabled;
}
}
public ushort Port
{
get
{
return this.port;
}
set
{
this.enabledCheck("Port");
this.port = value;
}
}
}
Code:
public class AsyncSocketWrapper : Interfaces.ISocketWrapper
{
public int BufferSize
{
get;
set;
}
public byte[] Buffer
{
get;
set;
}
public WinSocket Socket
{
get;
set;
}
public object Connector
{
get;
set;
}
public Interfaces.ISocketWrapper Create(Socket socket)
{
BufferSize = 8000;
Socket = new WinSocket(socket);
Buffer = new byte[BufferSize];
return this;
}
}
Code:
public class AsyncSocket
{
private int backlog;
private int clientbuffersize = 0xffff;
private WinSocket Connection = new WinSocket();
private bool enabled;
public bool GameServer = false;
public event Action<Interfaces.ISocketWrapper> OnClientConnect;
public event Action<Interfaces.ISocketWrapper> OnClientDisconnect;
public event Action<byte[], Interfaces.ISocketWrapper> OnClientReceive;
private ushort port;
public AsyncSocket(ushort port)
{
if (!this.enabled)
{
this.port = port;
this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port));
this.Connection.Listen(100);
this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
this.enabled = true;
}
}
private void AsyncConnect(IAsyncResult res)
{
AsyncSocketWrapper sender = null;
try
{
sender = new AsyncSocketWrapper();
sender.Create(this.Connection.EndAccept(res));
if (sender.Socket == null)
{
this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
return;
}
if (this.OnClientConnect != null)
{
this.OnClientConnect(sender);
}
sender.Socket.BeginReceive(sender.Buffer, 0, sender.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), sender);
this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
}
catch (SocketException e)
{
MessageBox.Show(e.Message);
if (this.enabled)
{
this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
}
}
catch (ObjectDisposedException e)
{
MessageBox.Show(e.Message);
}
}
private unsafe void AsyncReceive(IAsyncResult res)
{
bool was = false;
try
{
SocketError error;
AsyncSocketWrapper asyncState = (AsyncSocketWrapper)res.AsyncState;
int RecvSize = asyncState.Socket.EndReceive(res, out error);
if ((error == SocketError.Success) && (RecvSize > 0))
{
was = true;
byte[] buffer = new byte[RecvSize];
for (int i = 0; i < RecvSize; i++)
{
buffer[i] = asyncState.Buffer[i];
}
if (this.OnClientReceive != null)
{
this.OnClientReceive(buffer, asyncState);
}
asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState);
}
else
{
this.InvokeDisconnect(asyncState);
}
}
catch (SocketException e)
{
MessageBox.Show(e.Message);
}
catch (ObjectDisposedException e)
{
MessageBox.Show(e.Message);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
if (was)
{
AsyncSocketWrapper asyncState = (AsyncSocketWrapper)res.AsyncState;
asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState);
}
}
}
public void Disable()
{
if (this.enabled)
{
this.Connection.Disable();
this.enabled = false;
}
}
public void Enable()
{
if (!this.enabled)
{
this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port));
this.Connection.Listen(this.backlog);
this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null);
this.enabled = true;
}
}
private void enabledCheck(string Variable)
{
if (this.enabled)
{
throw new Exception("Cannot modify " + Variable + " while socket is enabled.");
}
}
public void InvokeDisconnect(AsyncSocketWrapper Client)
{
if (Client != null)
{
try
{
if (Client.Socket.Connected)
{
Client.Socket.Shutdown(SocketShutdown.Both);
Client.Socket.Close();
if (this.OnClientDisconnect != null)
{
this.OnClientDisconnect(Client);
}
Client.Connector = null;
Client = null;
}
else
{
if (this.OnClientDisconnect != null)
{
this.OnClientDisconnect(Client);
}
Client.Connector = null;
Client = null;
}
}
catch (ObjectDisposedException e)
{
MessageBox.Show(e.Message);
}
}
}
public int Backlog
{
get
{
return this.backlog;
}
set
{
this.enabledCheck("Backlog");
this.backlog = value;
}
}
public int ClientBufferSize
{
get
{
return this.clientbuffersize;
}
set
{
this.enabledCheck("ClientBufferSize");
this.clientbuffersize = value;
}
}
public bool Enabled
{
get
{
return this.enabled;
}
}
public ushort Port
{
get
{
return this.port;
}
set
{
this.enabledCheck("Port");
this.port = value;
}
}
}
Code:
public interface ISocketWrapper
{
int BufferSize { get; set; }
byte[] Buffer { get; set; }
WinSocket Socket { get; set; }
object Connector { get; set; }
ISocketWrapper Create(System.Net.Sockets.Socket socket);
}
|
|
|
04/17/2014, 17:16
|
#15
|
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
|
check this better

SuperAids 's chat project
|
|
|
 |
|
Similar Threads
|
SBot Password and Username
09/09/2014 - Silkroad Online - 2 Replies
How to find Password for SBot Account after I just purchased it
|
Invalid Username or Password
10/27/2013 - Minecraft - 2 Replies
Hallo Leute,
Unzwar wenn ich mich im Launcher oder in FTB Launcher einloggen will kommt immer Invalid Username or Password. Ich hab mit Email und ohne Email probiert.
AUF DER HOMPAGE KANN ICH MICH EINLOGGEN. Nur im Launcher halt nciht und ich benutze die selben Daten hab auch schon deinstalliert und passwort geändert ._.
Hilfe!!
|
Giving away username/password
08/26/2013 - League of Legends Trading - 11 Replies
Yo guys, one question if someone could help me please. I am trying to sell my account - http://www.elitepvpers.com/forum/league-legends-tr ading/2802907-euw-account-all-champions-skins.html
Some guy added me and made a proposal to me. First i have to give him my username/password, then he will pay me the money and then i will give him the email.
So my question is, can he steal my account if i give him the username/password only? I mean, i know he can, but can i recover it back? Thank you.
|
CO Opener with my username and password
09/29/2012 - CO2 Programming - 11 Replies
Can Some one told me how to Open Conquer At With my Own Username and password
Like >>>
enter my username and my password at application {not at conquer} and just click run and its could run
sorry for my bad english
|
All times are GMT +1. The time now is 13:15.
|
|