Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <SteamWorks>
  3. ArrayList g_aMsgs = null;
  4. char g_szSteamID[MAXPLAYERS][32];
  5. //int g_iAccount[MAXPLAYERS+1];
  6.  
  7. int g_iServerID = 0;
  8.  
  9. char g_sZmap[32];
  10.  
  11. bool g_bSending = false;
  12.  
  13.  
  14.  
  15. public void OnPluginStart()
  16. {
  17.  
  18. g_aMsgs = new ArrayList(1024);
  19.  
  20. RegConsoleCmd("say", Command_Say);
  21. RegConsoleCmd("say_team", Command_Say);
  22.  
  23. CreateTimer(5.0,TimerSendMessage,_,TIMER_REPEAT);
  24. }
  25.  
  26. public void OnClientConnected(int client)
  27. {
  28. //g_iAccount[client] = 0;
  29. g_szSteamID[client][0]= '\0';
  30. }
  31.  
  32. public Action TimerSendMessage(Handle timer, any data)
  33. {
  34. SendNextMsg();
  35. return Plugin_Continue;
  36. }
  37.  
  38. void SendNextMsg()
  39. {
  40. // We are still waiting for a reply from our last msg
  41. if(g_bSending)
  42. return;
  43.  
  44. // Nothing to send
  45. if(g_aMsgs.Length < 1)
  46. return;
  47.  
  48. char sMessage[1024];
  49. g_aMsgs.GetString(0, sMessage, sizeof(sMessage));
  50.  
  51. //LogMessage("data %s",sMessage);
  52.  
  53. Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST, "https://URL/ServerChatInPut.php");
  54. if(!hRequest || !SteamWorks_SetHTTPCallbacks(hRequest, view_as<SteamWorksHTTPRequestCompleted>(OnRequestComplete))
  55. || !SteamWorks_SetHTTPRequestRawPostBody(hRequest, "application/json", sMessage, strlen(sMessage))
  56. || !SteamWorks_SendHTTPRequest(hRequest))
  57. {
  58. delete hRequest;
  59. LogError("SendNextMsg: Failed To Send Message");
  60. return;
  61. }
  62. // Don't Send new messages aslong we wait for a reply from this one
  63. g_bSending = true;
  64. }
  65.  
  66.  
  67. public int OnRequestComplete(Handle hRequest, bool bFailed, bool bRequestSuccessful, EHTTPStatusCode eStatusCode)
  68. {
  69. // This should not happen!
  70. if(bFailed || !bRequestSuccessful)
  71. {
  72. LogError("[OnRequestComplete] Request failed");
  73. }
  74. else if(eStatusCode == k_EHTTPStatusCode200OK || eStatusCode == k_EHTTPStatusCode204NoContent)
  75. {
  76. g_aMsgs.Erase(0);
  77. }
  78. // Unknown error
  79. else
  80. {
  81. LogError("[OnRequestComplete] Error Code: [%d]", eStatusCode);
  82. g_aMsgs.Erase(0);
  83. }
  84.  
  85. delete hRequest;
  86. g_bSending = false;
  87. }
  88.  
  89.  
  90. public void csgo_HostName_OnServerInfoLoaded(int serverid,const char[] IPPort,const char[] sHostname)
  91. {
  92. g_iServerID = serverid;
  93. }
  94.  
  95. public void OnMapStart()
  96. {
  97. GetCurrentMap(g_sZmap,32);
  98. }
  99.  
  100. public void OnClientPostAdminCheck(int client)
  101. {
  102. if(IsClientConnected(client))
  103. GetClientAuthId(client,AuthId_SteamID64,g_szSteamID[client],32);
  104. //g_iAccount[client] = GetSteamAccountID(client,false);
  105. }
  106.  
  107. public Action Command_Say(int client, int args)
  108. {
  109. if(client <=0)
  110. return Plugin_Continue;
  111.  
  112. char textBuffer[192], textClean[192];
  113.  
  114. GetCmdArgString(textBuffer, sizeof(textBuffer));
  115.  
  116. StripQuotes(textBuffer);
  117. TrimString(textBuffer);
  118.  
  119. if(textBuffer[0] == '!' || textBuffer[0] == '/')
  120. return Plugin_Continue;
  121.  
  122. if(StrEqual(textBuffer,"!",false))
  123. return Plugin_Continue;
  124.  
  125. 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)
  126. return Plugin_Continue;
  127.  
  128. if(StrContains(textBuffer, "help",false) != -1 || StrContains(textBuffer, "menu",false) != -1 || StrContains(textBuffer, "gun",false) != -1)
  129. {
  130. return Plugin_Continue;
  131. }
  132.  
  133. int startidx = 0;
  134. int len = strlen(textBuffer);
  135. if(len < 3)
  136. return Plugin_Continue;
  137.  
  138. if ((textBuffer[0] == '"') && (textBuffer[len-1] == '"'))
  139. {
  140. startidx = 1;
  141. textBuffer[len-1] = '\0';
  142. }
  143.  
  144. Format(textClean, sizeof(textClean), "%s", textBuffer[startidx]);
  145.  
  146. char sMessage[1024];
  147.  
  148. Format(sMessage, sizeof(sMessage), "{\"serverid\": %d,\"content\": \"%s\",\"steamid\": \"%s\",\"map\": \"%s\",\"name\": \"%N\"}",g_iServerID,textClean,g_szSteamID[client],g_sZmap,client);
  149. StoreMsg(sMessage);
  150.  
  151.  
  152. return Plugin_Continue;
  153. }
  154.  
  155. void StoreMsg(char sMessage[1024])
  156. {
  157. g_aMsgs.PushString(sMessage);
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement