plane/test.sp

187 lines
4.5 KiB
SourcePawn
Raw Normal View History

#include <sourcemod>
#include <clients>
#include <cstrike>
#include <sdktools>
#include "socket.inc"
#define MY_SOCKET_IP "localhost"
#define MY_SOCKET_PORT 3500
2021-05-16 10:39:31 +00:00
#define STEAMID_LENGTH 128
char teamCT[6][150];
char teamT[6][150];
char authorised[20][128];
char clientId[128];
public Plugin myinfo =
{
name = "InfoLan 2021 Bot",
author = "rick@gnous.eu",
description = "Bot communiquant avec le bot discord \
https://github.com/Lunki51/cs-picker afin dautomatiser \
lInfoLan 2021",
version = "1.3",
url = "https://git.gnous.eu/Rick/infolanBot"
};
2021-05-18 13:43:05 +00:00
public void OnPluginStart()
{
HookEvent("cs_win_panel_match", ServeurLibre);
HookEvent("player_activate", SuperTest);
RegServerCmd("!team", SetTeam);
PrintToServer("Hello world!");
PrintToServer("%d", sizeof(authorised));
}
//public void OnClientAuthorized(int client, const char[] auth)
public void SuperTest(Event event, const char[] name, bool dontBroadcast)
2021-05-16 10:39:31 +00:00
{
int client = GetClientOfUserId(event.GetInt("userid"));
bool allGood = GetClientAuthId(client, AuthId_SteamID64, clientId, sizeof(clientId));
2021-05-18 13:43:05 +00:00
if (allGood)
2021-05-16 10:39:31 +00:00
{
PrintToServer("== ID OK ==");
2021-05-16 10:39:31 +00:00
allGood = false;
int i = 1;
while (!allGood && i < sizeof(teamCT))
{
if (!strcmp(teamCT[i], clientId, false))
2021-05-16 10:39:31 +00:00
{
ChangeClientTeam(client, CS_TEAM_CT);
2021-05-16 10:39:31 +00:00
allGood = true;
}
else if (!strcmp(teamT[i], clientId, false))
2021-05-16 10:39:31 +00:00
{
ChangeClientTeam(client, CS_TEAM_T);
2021-05-16 10:39:31 +00:00
allGood = true;
}
i++;
}
if (!allGood)
{
i = 0;
while (!allGood && i < sizeof(authorised))
{
if (!strcmp(authorised[i], clientId, false))
{
allGood = true;
ChangeClientTeam(client, CS_TEAM_SPECTATOR);
}
i++;
}
if (!allGood)
{
KickClient(client, "Vous nêtes pas autorisé à suivre / jouer \
sur ce serveur");
}
2021-05-16 10:39:31 +00:00
}
}
}
/*
* !team
*
*
*/
public Action SetTeam(int args)
{
char arg[128];
2021-05-16 10:39:31 +00:00
GetCmdArg(1, arg, sizeof(arg));
int team = (!strcmp(arg, "ct", false) ? 1 : 2);
GetCmdArg(2, arg, sizeof(arg));
if (team == 1)
{
ServerCommand("mp_teamname_1 %s", arg)
}
else
{
ServerCommand("mp_teamname_2 %s", arg)
}
2021-05-16 10:39:31 +00:00
if (args == 7)
{
for(int i = 3; i <= args; i++)
2021-05-16 10:39:31 +00:00
{
GetCmdArg(i, arg, sizeof(arg));
if (team == 1)
{
teamCT[i - 3] = arg;
2021-05-16 10:39:31 +00:00
}
else
{
teamT[i - 3] = arg;
2021-05-16 10:39:31 +00:00
}
}
}
else
{
2021-05-16 10:39:31 +00:00
PrintToServer("Erreur, pas assez dargs");
}
return Plugin_Handled;
}
/* envoie information plugin */
public void OnMapEnd()
{
PrintToServer("======= FIN ======");
/* kick tout le monde */
}
2021-05-18 13:43:05 +00:00
public void ServeurLibre(Event event, const char[] name, bool dontBroadcast)
{
// requete post pour match fini et serveur libre
Handle socket = SocketCreate(SOCKET_TCP, OnSocketError);
//SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, MY_SOCKET_IP, MY_SOCKET_PORT);
}
public void SocketUpdateScore(Handle socket, int t, int ct) {}
public void SocketEnvoieVictoire(Handle socket, int t, int ct)
{
char requestStr[512];
FormatEx(
requestStr,
sizeof(requestStr),
"POST /api/csgo/matchend HTTP/1.0\r\n\
Host: Serveur\r\n\
Content-type: text/json\r\n\
{\"serverport\": XXXXXX, \"available\": \"true\"}"
)
}
public void OnSocketConnected(Handle socket, any arg)
{
char requestStr[150];
Format(requestStr, sizeof(requestStr), "%s", "Source Engine Query");
/*
FormatEx(
requestStr,
sizeof(requestStr),
"GET /%s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n",
"prout",
"mario"
);
*/
SocketSend(socket, requestStr, 150);
}
2021-05-18 13:43:05 +00:00
public void OnSocketReceive(Handle socket, const char[] datas, const int data, any arg) {}
public OnSocketDisconnected(Handle socket, any arg)
{
CloseHandle(socket);
}
public void OnSocketError(Handle socket, const int errorType, const int errorNum, any arg)
{
PrintToServer("[ERROR] Le socket a rencontré une erreur !");
CloseHandle(socket);
}