89 lines
2.1 KiB
SourcePawn
89 lines
2.1 KiB
SourcePawn
#include <sourcemod>
|
||
#include "socket.inc"
|
||
|
||
#define MY_SOCKET_IP "localhost"
|
||
#define MY_SOCKET_PORT 3500
|
||
|
||
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 d’automatiser \
|
||
l’InfoLan 2021",
|
||
version = "1.0",
|
||
url = "https://git.gnous.eu/Rick/infolanBot"
|
||
};
|
||
|
||
public Action TestCommand(int args)
|
||
{
|
||
char arg[128];
|
||
char full[256];
|
||
GetCmdArgString(full, sizeof(full));
|
||
PrintToServer("Je reçois %d arguments qui sont : %s", args, full);
|
||
for(int i = 1; i < args; i++)
|
||
{
|
||
GetCmdArg(i, arg, sizeof(arg));
|
||
PrintToServer("%d c’est la demande %s", i, arg);
|
||
}
|
||
|
||
return Plugin_Handled;
|
||
}
|
||
|
||
public void OnSocketReceive(Handle socket, const char[] datas, const int data, any arg) {}
|
||
|
||
/* envoie information plugin */
|
||
|
||
public void OnMapEnd()
|
||
{
|
||
/* kick tout le monde */
|
||
PrintToServer("This is zi end ================");
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
public void EnvoiInfo(Event event, const char[] name, bool dontBroadcast)
|
||
{
|
||
Handle socket = SocketCreate(SOCKET_TCP, OnSocketError);
|
||
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, MY_SOCKET_IP, MY_SOCKET_PORT);
|
||
|
||
}
|
||
|
||
public void OnPluginStart()
|
||
{
|
||
/*cs_win_panel_match*/
|
||
|
||
HookEvent("cs_win_panel_match", EnvoiInfo);
|
||
|
||
RegServerCmd("!test", TestCommand);
|
||
|
||
PrintToServer("Hello world!");
|
||
PrintToServer("==== REQUETE ENVOYÉE ====");
|
||
}
|