Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Client
- {
- SOCKET connections[2];
- DWORD uhid;
- HWND hWnd;
- BYTE *pixels;
- DWORD pixelsWidth, pixelsHeight;
- DWORD screenWidth, screenHeight;
- HDC hDcBmp;
- HANDLE minEvent;
- BOOL fullScreen;
- RECT windowedRect;
- };
- static Client g_clients[256];
- Client *GetClient(void *data, BOOL uhid)
- {
- for(int i = 0; i < 256; ++i)
- {
- if(uhid)
- {
- if(g_clients[i].uhid == (DWORD) data)
- return &g_clients[i];
- }
- else
- {
- if(g_clients[i].hWnd == (HWND) data)
- return &g_clients[i];
- }
- }
- return NULL;
- }
- BOOL recordClient()
- {
- Client *client = NULL;
- BOOL found = FALSE;
- DWORD uhid;
- uhid = 27650; // Some value, only as example here
- memset(g_clients, 0, sizeof(g_clients));
- client = GetClient((void *) uhid, TRUE);
- if(client)
- return FALSE;
- for(int i = 0; i < 256; ++i)
- {
- if(!g_clients[i].hWnd)
- {
- found = TRUE;
- client = &g_clients[i];
- }
- }
- if(!found)
- {
- wprintf(TEXT("User %S kicked max %d usersn"), "185.242.4.203", 256);
- return FALSE;
- }
- return TRUE;
- }
- type
- PClient = ^Client;
- Client = record
- Connections: array [0 .. 1] of TSocket;
- uhId,
- pixelsWidth,
- pixelsHeight,
- screenWidth,
- screenHeight: Cardinal;
- _hWnd: HWND;
- Pixels: PByte;
- hDcBmp: HDC;
- minEvent: THandle;
- fullScreen: Boolean;
- windowRect: TRect;
- end;
- var
- Clients: array [0 .. 255] of Client;
- //...
- function GetClient(Data: Pointer; uhId: Boolean): PClient;
- var
- I: Integer;
- begin
- Result := nil;
- for I := 0 to 255 do
- begin
- if uhId then
- begin
- if Clients[I].uhId = Cardinal(Data) then
- begin
- Result := @Clients[I];
- Break;
- end;
- end
- else
- begin
- if Clients[I]._hWnd = HWND(Data) then
- begin
- Result := @Clients[I];
- Break;
- end;
- end;
- end;
- end;
- function recordClient: Boolean;
- var
- _client: PClient;
- _uhId: Cardinal;
- found: Boolean;
- I: Integer;
- begin
- Result := True;
- FillMemory(@Clients, SizeOf(Clients), 0);
- _uhId := 27650; // Some value, only as example here
- _client := GetClient(@_uhId, True);
- if _client <> nil then
- begin
- Result := False;
- Exit;
- end;
- found := False;
- for I := 0 to 255 do
- begin
- if Clients[I]._hWnd = 0 then
- begin
- found := True;
- _client := @Clients[I];
- end;
- end;
- if not found then
- begin
- Writeln(Format('Client %s rejected, max allowed is %d clients.' + #13,
- ['185.242.4.203', 256])); // Only example values
- Result := False;
- Exit;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement