Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //process the client connection.
- public static void DoAcceptTcpClientCallback(IAsyncResult ar)
- {
- try
- {
- //get the listener that handles the client request
- TcpListener Listener = (TcpListener)ar.AsyncState;
- //end the operation and display the received data on the console
- TcpClient Client = Listener.EndAcceptTcpClient(ar);
- //process the connection here. (Add the client to a server table, read data, etc
- Console.WriteLine("Client connected completed, listen for new connection.");
- //get newly connected clients network stream
- NetworkStream Stream = Client.GetStream();
- //create a packethandler object from fiefdom library which handles reading operations of
- //data being sent from the client
- Fiefdom_Data.PacketHandler PacketHandler = new Fiefdom_Data.PacketHandler(Stream);
- //identify incoming packet header
- byte Header = PacketHandler.Reader.ReadByte();
- //if packet header is not a login packet then disconnect client
- if (Header == 0)
- {
- //get username first
- string UserName = PacketHandler.Reader.ReadString();
- //get password second
- string Password = PacketHandler.Reader.ReadString();
- //through a sql statement attempt to retrieve a session key by checking the username and password against the accounts table
- int UserID = (int)FiefdomDatabases.AccountDatabase.SPQuery("select id FROM accounts WHERE username='{0}' and password='{1}'", UserName, Password);
- //if a session key has been returned and the variable is not null
- if (UserID != null)
- {
- //notify client that we are returning the session key
- PacketHandler.Writer.Write((byte)Fiefdom_Data.ServerPacketCodes.LoginOK);
- //return session key to client
- //PacketHandler.Writer.Write((int)UserID);
- }
- //disconnect tcpclient connection
- Client.Close();
- }
- else
- {
- //disconnect tcpclient connection
- Client.Close();
- }
- }
- catch { return; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement