Advertisement
Guest User

Untitled

a guest
May 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. //process the client connection.
  2. public static void DoAcceptTcpClientCallback(IAsyncResult ar)
  3. {
  4. try
  5. {
  6. //get the listener that handles the client request
  7. TcpListener Listener = (TcpListener)ar.AsyncState;
  8.  
  9. //end the operation and display the received data on the console
  10. TcpClient Client = Listener.EndAcceptTcpClient(ar);
  11.  
  12. //process the connection here. (Add the client to a server table, read data, etc
  13. Console.WriteLine("Client connected completed, listen for new connection.");
  14.  
  15. //get newly connected clients network stream
  16. NetworkStream Stream = Client.GetStream();
  17.  
  18. //create a packethandler object from fiefdom library which handles reading operations of
  19. //data being sent from the client
  20. Fiefdom_Data.PacketHandler PacketHandler = new Fiefdom_Data.PacketHandler(Stream);
  21.  
  22. //identify incoming packet header
  23. byte Header = PacketHandler.Reader.ReadByte();
  24.  
  25. //if packet header is not a login packet then disconnect client
  26. if (Header == 0)
  27. {
  28. //get username first
  29. string UserName = PacketHandler.Reader.ReadString();
  30. //get password second
  31. string Password = PacketHandler.Reader.ReadString();
  32.  
  33. //through a sql statement attempt to retrieve a session key by checking the username and password against the accounts table
  34. int UserID = (int)FiefdomDatabases.AccountDatabase.SPQuery("select id FROM accounts WHERE username='{0}' and password='{1}'", UserName, Password);
  35.  
  36. //if a session key has been returned and the variable is not null
  37. if (UserID != null)
  38. {
  39. //notify client that we are returning the session key
  40. PacketHandler.Writer.Write((byte)Fiefdom_Data.ServerPacketCodes.LoginOK);
  41. //return session key to client
  42. //PacketHandler.Writer.Write((int)UserID);
  43. }
  44. //disconnect tcpclient connection
  45. Client.Close();
  46. }
  47. else
  48. {
  49. //disconnect tcpclient connection
  50. Client.Close();
  51. }
  52. }
  53. catch { return; }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement