Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <SteamWorks>
- ArrayList g_aMsgs = null;
- char g_szSteamID[MAXPLAYERS][32];
- //int g_iAccount[MAXPLAYERS+1];
- int g_iServerID = 0;
- char g_sZmap[32];
- bool g_bSending = false;
- public void OnPluginStart()
- {
- g_aMsgs = new ArrayList(1024);
- RegConsoleCmd("say", Command_Say);
- RegConsoleCmd("say_team", Command_Say);
- CreateTimer(5.0,TimerSendMessage,_,TIMER_REPEAT);
- }
- public void OnClientConnected(int client)
- {
- //g_iAccount[client] = 0;
- g_szSteamID[client][0]= '\0';
- }
- public Action TimerSendMessage(Handle timer, any data)
- {
- SendNextMsg();
- return Plugin_Continue;
- }
- void SendNextMsg()
- {
- // We are still waiting for a reply from our last msg
- if(g_bSending)
- return;
- // Nothing to send
- if(g_aMsgs.Length < 1)
- return;
- char sMessage[1024];
- g_aMsgs.GetString(0, sMessage, sizeof(sMessage));
- //LogMessage("data %s",sMessage);
- Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, "https://URL/ServerChatInPut.php");
- if(!hRequest || !SteamWorks_SetHTTPCallbacks(hRequest, view_as<SteamWorksHTTPRequestCompleted>(OnRequestComplete))
- || !SteamWorks_SetHTTPRequestRawPostBody(hRequest, "application/json", sMessage, strlen(sMessage))
- || !SteamWorks_SendHTTPRequest(hRequest))
- {
- delete hRequest;
- LogError("SendNextMsg: Failed To Send Message");
- return;
- }
- // Don't Send new messages aslong we wait for a reply from this one
- g_bSending = true;
- }
- public int OnRequestComplete(Handle hRequest, bool bFailed, bool bRequestSuccessful, EHTTPStatusCode eStatusCode)
- {
- // This should not happen!
- if(bFailed || !bRequestSuccessful)
- {
- LogError("[OnRequestComplete] Request failed");
- }
- else if(eStatusCode == k_EHTTPStatusCode200OK || eStatusCode == k_EHTTPStatusCode204NoContent)
- {
- g_aMsgs.Erase(0);
- }
- // Unknown error
- else
- {
- LogError("[OnRequestComplete] Error Code: [%d]", eStatusCode);
- g_aMsgs.Erase(0);
- }
- delete hRequest;
- g_bSending = false;
- }
- public void csgo_HostName_OnServerInfoLoaded(int serverid,const char[] IPPort,const char[] sHostname)
- {
- g_iServerID = serverid;
- }
- public void OnMapStart()
- {
- GetCurrentMap(g_sZmap,32);
- }
- public void OnClientPostAdminCheck(int client)
- {
- if(IsClientConnected(client))
- GetClientAuthId(client,AuthId_SteamID64,g_szSteamID[client],32);
- //g_iAccount[client] = GetSteamAccountID(client,false);
- }
- public Action Command_Say(int client, int args)
- {
- if(client <=0)
- return Plugin_Continue;
- char textBuffer[192], textClean[192];
- GetCmdArgString(textBuffer, sizeof(textBuffer));
- StripQuotes(textBuffer);
- TrimString(textBuffer);
- if(textBuffer[0] == '!' || textBuffer[0] == '/')
- return Plugin_Continue;
- if(StrEqual(textBuffer,"!",false))
- return Plugin_Continue;
- if(strncmp(textBuffer, "rtv", 3, false) == 0 || strncmp(textBuffer, "cheer", 5, false) == 0 || strncmp(textBuffer, "lol", 3, false) == 0 || strncmp(textBuffer, "nominate", 8, false) == 0)
- return Plugin_Continue;
- if(StrContains(textBuffer, "help",false) != -1 || StrContains(textBuffer, "menu",false) != -1 || StrContains(textBuffer, "gun",false) != -1)
- {
- return Plugin_Continue;
- }
- int startidx = 0;
- int len = strlen(textBuffer);
- if(len < 3)
- return Plugin_Continue;
- if ((textBuffer[0] == '"') && (textBuffer[len-1] == '"'))
- {
- startidx = 1;
- textBuffer[len-1] = '\0';
- }
- Format(textClean, sizeof(textClean), "%s", textBuffer[startidx]);
- char sMessage[1024];
- Format(sMessage, sizeof(sMessage), "{\"serverid\": %d,\"content\": \"%s\",\"steamid\": \"%s\",\"map\": \"%s\",\"name\": \"%N\"}",g_iServerID,textClean,g_szSteamID[client],g_sZmap,client);
- StoreMsg(sMessage);
- return Plugin_Continue;
- }
- void StoreMsg(char sMessage[1024])
- {
- g_aMsgs.PushString(sMessage);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement