SAMP Gitlab CI Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.5 KiB

5 years ago
  1. //
  2. // Admin player netstats display
  3. // Using NetStats_* functions.
  4. //
  5. // -Rcon login admin then:
  6. // /pnetstats2 (playerid)
  7. //
  8. #include <a_samp>
  9. #include "../include/gl_common.inc"
  10. #define ADMINFS_MESSAGE_COLOR 0xFF444499
  11. #define ADMIN_NETSTATS_DIALOGID 12899
  12. new gNetStatsPlayerId = INVALID_PLAYER_ID;
  13. new gNetStatsDisplayId = INVALID_PLAYER_ID;
  14. new gNetStatsTimerId = 0;
  15. forward NetStatsDisplay();
  16. //------------------------------------------------
  17. public OnFilterScriptInit()
  18. {
  19. print("\n--Admin Netstats FS loaded.\n");
  20. return 1;
  21. }
  22. //------------------------------------------------
  23. BuildPlayerNetstatString(playerid, ret_str[], ret_str_len)
  24. {
  25. new szPlayerIpPort[64+1];
  26. NetStats_GetIpPort(playerid, szPlayerIpPort, 64);
  27. format(ret_str, ret_str_len, "IP_Port: %s\nConnected Time (ms): %d\nConnection Status: %d\nPacket Loss: %.2f\nMessages Recv: %d\nMessages Sent: %d\nMessages/sec: %d",
  28. szPlayerIpPort,
  29. NetStats_GetConnectedTime(playerid),
  30. NetStats_ConnectionStatus(playerid),
  31. NetStats_PacketLossPercent(playerid),
  32. NetStats_MessagesReceived(playerid),
  33. NetStats_MessagesSent(playerid),
  34. NetStats_MessagesRecvPerSecond(playerid));
  35. }
  36. //------------------------------------------------
  37. public NetStatsDisplay()
  38. {
  39. new netstats_str[1024+1];
  40. BuildPlayerNetstatString(gNetStatsDisplayId, netstats_str, 1024);
  41. ShowPlayerDialog(gNetStatsPlayerId, ADMIN_NETSTATS_DIALOGID, DIALOG_STYLE_MSGBOX, "Player NetStats", netstats_str, "Ok", "");
  42. }
  43. //------------------------------------------------
  44. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  45. {
  46. if(!IsPlayerAdmin(playerid)) return 0; // this is an admin only script
  47. if(dialogid == ADMIN_NETSTATS_DIALOGID) {
  48. KillTimer(gNetStatsTimerId);
  49. gNetStatsPlayerId = INVALID_PLAYER_ID;
  50. return 1;
  51. }
  52. return 0;
  53. }
  54. //------------------------------------------------
  55. public OnPlayerCommandText(playerid, cmdtext[])
  56. {
  57. new cmd[256+1];
  58. new idx;
  59. if(!IsPlayerAdmin(playerid)) return 0;
  60. cmd = strtok(cmdtext, idx);
  61. // netstats command
  62. if(strcmp("/pnetstats2", cmd, true) == 0)
  63. {
  64. new tmp[128];
  65. tmp = strtok(cmdtext, idx);
  66. if(!strlen(tmp)) { return 1; }
  67. gNetStatsPlayerId = playerid;
  68. gNetStatsDisplayId = strval(tmp);
  69. NetStatsDisplay();
  70. gNetStatsTimerId = SetTimer("NetStatsDisplay", 3000, true); // this will refresh the display every 3 seconds
  71. return 1;
  72. }
  73. return 0;
  74. }
  75. //------------------------------------------------