Requete fonctionnelle pour la fin de match

This commit is contained in:
rick 2021-05-20 01:08:11 +02:00
parent d8ce63a440
commit 1c093e3c39
Signed by: Rick
GPG key ID: 2B593F087240EE99

24
test.sp
View file

@ -138,7 +138,6 @@ public void ServeurLibre(Event event, const char[] name, bool dontBroadcast)
public void UpdateScoreBoard(Event event, const char[] name, bool dontBroadcast) public void UpdateScoreBoard(Event event, const char[] name, bool dontBroadcast)
{ {
// request post avec les scores des 2 équipes // request post avec les scores des 2 équipes
PrintToServer("Coucou, je souis là");
Handle socket = SocketCreate(SOCKET_TCP, OnSocketError); Handle socket = SocketCreate(SOCKET_TCP, OnSocketError);
SocketConnect(socket, SocketUpdateScore, OnSocketReceive, OnSocketDisconnected, MY_SOCKET_IP, MY_SOCKET_PORT); SocketConnect(socket, SocketUpdateScore, OnSocketReceive, OnSocketDisconnected, MY_SOCKET_IP, MY_SOCKET_PORT);
} }
@ -162,32 +161,35 @@ public Action TestSocketA(int args)
public void SocketUpdateScore(Handle socket, any arg) public void SocketUpdateScore(Handle socket, any arg)
{ {
char requestStr[2048]; char requestStr[1024];
char json[64];
FormatEx(json, sizeof(json), "{\"port\": %d, \"ct\": %d, \"t\": %d}",
port, CS_GetTeamScore(CS_TEAM_CT), CS_GetTeamScore(CS_TEAM_T));
FormatEx( FormatEx(
requestStr, requestStr,
sizeof(requestStr), sizeof(requestStr),
"POST /api/csgo/updatescore HTTP/1.1\r\n\ "POST /api/csgo/updatescore HTTP/1.1\r\n\
Content-Type: application/json\r\n\ Content-Type: application/json\r\n\
Content-Length: 32\r\n\r\n\ Content-Length: %d\r\n\r\n%s", strlen(json), json
{\"port\": %d, \"ct\": %d, \"t\": %d}",
port, CS_GetTeamScore(CS_TEAM_CT), CS_GetTeamScore(CS_TEAM_T)
); );
SocketSend(socket, requestStr, 2048); SocketSend(socket, requestStr, sizeof(requestStr));
SocketDisconnect(socket); SocketDisconnect(socket);
CloseHandle(socket); CloseHandle(socket);
} }
public void SocketEnvoieVictoire(Handle socket, any arg) public void SocketEnvoieVictoire(Handle socket, any arg)
{ {
char requestStr[512]; char requestStr[1024];
char json[64];
FormatEx(json, sizeof(json), "{\"serverport\": %d, \"available\": true}", port);
FormatEx( FormatEx(
requestStr, requestStr,
sizeof(requestStr), sizeof(requestStr),
"POST /api/csgo/matchend HTTP/1.0\r\n\ "POST /api/csgo/matchend HTTP/1.1\r\n\
Content-type: text/json\r\n\ Content-Type: application/json\r\n\
{\"serverport\": 512, \"available\": true}", port Content-Length: %d\r\n\r\n%s", strlen(json), json
); );
SocketSend(socket, requestStr, 512); SocketSend(socket, requestStr, sizeof(requestStr));
SocketDisconnect(socket); SocketDisconnect(socket);
CloseHandle(socket); CloseHandle(socket);
} }