1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.Net.Sockets;
  7.  
  8. namespace LoginServer
  9. {
  10. public class SessionCmp : ActiveComponent
  11. {
  12. int maxSlots;
  13.  
  14. public class Session
  15. {
  16. public Socket Socket;
  17. public byte[] Buffer;
  18. public Socket sendSocket;
  19. public Socket listensocket;
  20. public SocketInformation info;
  21.  
  22. public Session()
  23. {
  24. Buffer = new byte[Int32.Parse((string)Components.Settings().data["net"]["buffer_size"])];
  25. sendSocket = listensocket;
  26. }
  27.  
  28. public void Send(byte[] buffer)
  29. {
  30. Socket list = new Socket(info); // whatever.
  31. sendSocket = listensocket;
  32. list.Send(buffer);
  33. }
  34. }
  35.  
  36. public Session[] Sessions;
  37. public override void Init()
  38. {
  39. maxSlots = Int32.Parse((string)Components.Settings().data["net"]["max_connections"]);
  40. Sessions = new Session[maxSlots];
  41.  
  42. for (int i = 0; i < maxSlots; i++)
  43. {
  44. Sessions[i] = null;
  45. }
  46. Console.WriteLine("SessionCMP/Init(): Session manager has been created");
  47. }
  48.  
  49. public override void Load()
  50. {
  51. }
  52.  
  53. public override void Start()
  54. {
  55. }
  56.  
  57. public override void Shutdown()
  58. {
  59. }
  60.  
  61. public override void Update()
  62. {
  63. // some continuity checking can go here later.
  64. }
  65.  
  66. public int GetSlot()
  67. {
  68. for (int i = 0; i < maxSlots; i++)
  69. {
  70. if (Sessions[i] == null)
  71. {
  72. return i;
  73. }
  74. }
  75. return -1;
  76. }
  77.  
  78. public void CreateSession(int ID, Socket listensocket)
  79. {
  80. Sessions[ID] = new Session();
  81. }
  82.  
  83. public void MarkForDestroy(int ID)
  84. {
  85. // THIS FUNCTION IS BAD! IT DOESNT HAVE ANY MERCY FOR INTERNET DISCONNECTS. REWRITE URGENTLY.
  86. Sessions[ID] = null;
  87. }
  88. }
  89. }