
18.02.2023, 23:54
|
|
Участник форума
Регистрация: 19.01.2017
Сообщений: 130
С нами:
4901705
Репутация:
98
|
|
Simple samp query using imgui server address and socket api
Код:
ImGui::Begin("Server Info");
// Create a socket to communicate with the server
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
// Specify the server's address and port
sockaddr_in addr = { 0 };
addr.sin_family = AF_INET;
addr.sin_port = htons(7777);
inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
// Send a SAMP Query packet to the server
char query[] = { 'S', 'A', 'M', 'P', ' ', '0', 'x', '54', '4F', '4D', '50', '\0' };
sendto(sock, query, sizeof(query), 0, (sockaddr*)&addr, sizeof(addr));
// Wait for a response from the server
char buffer[2048] = { 0 };
int len = sizeof(sockaddr_in);
recvfrom(sock, buffer, sizeof(buffer), 0, (sockaddr*)&addr, &len);
// Parse the response and display the server info
ImGui::Text("Server Name: %s", buffer + 11);
ImGui::Text("Players Online: %d", *(int*)(buffer + 19));
ImGui::Text("Game Mode: %s", buffer + 23);
ImGui::Text("Language: %s", buffer + 39);
ImGui::Text("Weather: %d", *(int*)(buffer + 43));
ImGui::Text("Time: %d:%02d", *(int*)(buffer + 47), *(int*)(buffer + 51));
ImGui::Text("Ping: %d", *(int*)(buffer + 83));
ImGui::End();
|
|
|