Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. struct Client
  2. {
  3. SOCKET connections[2];
  4. DWORD uhid;
  5. HWND hWnd;
  6. BYTE *pixels;
  7. DWORD pixelsWidth, pixelsHeight;
  8. DWORD screenWidth, screenHeight;
  9. HDC hDcBmp;
  10. HANDLE minEvent;
  11. BOOL fullScreen;
  12. RECT windowedRect;
  13. };
  14.  
  15. static Client g_clients[256];
  16.  
  17.  
  18. Client *GetClient(void *data, BOOL uhid)
  19. {
  20. for(int i = 0; i < 256; ++i)
  21. {
  22. if(uhid)
  23. {
  24. if(g_clients[i].uhid == (DWORD) data)
  25. return &g_clients[i];
  26. }
  27. else
  28. {
  29. if(g_clients[i].hWnd == (HWND) data)
  30. return &g_clients[i];
  31. }
  32. }
  33. return NULL;
  34. }
  35.  
  36. BOOL recordClient()
  37. {
  38. Client *client = NULL;
  39. BOOL found = FALSE;
  40. DWORD uhid;
  41.  
  42.  
  43. uhid = 27650; // Some value, only as example here
  44. memset(g_clients, 0, sizeof(g_clients));
  45.  
  46. client = GetClient((void *) uhid, TRUE);
  47.  
  48. if(client)
  49. return FALSE;
  50.  
  51. for(int i = 0; i < 256; ++i)
  52. {
  53. if(!g_clients[i].hWnd)
  54. {
  55. found = TRUE;
  56. client = &g_clients[i];
  57. }
  58. }
  59.  
  60. if(!found)
  61. {
  62. wprintf(TEXT("User %S kicked max %d usersn"), "185.242.4.203", 256);
  63. return FALSE;
  64. }
  65.  
  66. return TRUE;
  67. }
  68.  
  69. type
  70. PClient = ^Client;
  71.  
  72. Client = record
  73. Connections: array [0 .. 1] of TSocket;
  74. uhId,
  75. pixelsWidth,
  76. pixelsHeight,
  77. screenWidth,
  78. screenHeight: Cardinal;
  79. _hWnd: HWND;
  80. Pixels: PByte;
  81. hDcBmp: HDC;
  82. minEvent: THandle;
  83. fullScreen: Boolean;
  84. windowRect: TRect;
  85. end;
  86.  
  87.  
  88. var
  89. Clients: array [0 .. 255] of Client;
  90.  
  91. //...
  92.  
  93. function GetClient(Data: Pointer; uhId: Boolean): PClient;
  94. var
  95. I: Integer;
  96. begin
  97. Result := nil;
  98. for I := 0 to 255 do
  99. begin
  100. if uhId then
  101. begin
  102. if Clients[I].uhId = Cardinal(Data) then
  103. begin
  104. Result := @Clients[I];
  105. Break;
  106. end;
  107. end
  108. else
  109. begin
  110. if Clients[I]._hWnd = HWND(Data) then
  111. begin
  112. Result := @Clients[I];
  113. Break;
  114. end;
  115. end;
  116. end;
  117. end;
  118.  
  119. function recordClient: Boolean;
  120. var
  121. _client: PClient;
  122. _uhId: Cardinal;
  123. found: Boolean;
  124. I: Integer;
  125. begin
  126. Result := True;
  127.  
  128. FillMemory(@Clients, SizeOf(Clients), 0);
  129.  
  130. _uhId := 27650; // Some value, only as example here
  131. _client := GetClient(@_uhId, True);
  132.  
  133. if _client <> nil then
  134. begin
  135. Result := False;
  136. Exit;
  137. end;
  138.  
  139. found := False;
  140.  
  141. for I := 0 to 255 do
  142. begin
  143. if Clients[I]._hWnd = 0 then
  144. begin
  145. found := True;
  146. _client := @Clients[I];
  147. end;
  148. end;
  149.  
  150. if not found then
  151. begin
  152. Writeln(Format('Client %s rejected, max allowed is %d clients.' + #13,
  153. ['185.242.4.203', 256])); // Only example values
  154. Result := False;
  155. Exit;
  156. end;
  157. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement