Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. bool ChatHandler::HandleServerShutDownCommand(const char* args)
  2. {
  3. if(!*args)
  4. return false;
  5.  
  6. char* time_str = strtok ((char*) args, " ");
  7. char* exitcode_str = strtok (NULL, "");
  8.  
  9. int32 time = atoi (time_str);
  10.  
  11. ///- Prevent interpret wrong arg value as 0 secs shutdown time
  12. if (time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
  13. return false;
  14.  
  15. if (exitcode_str)
  16. {
  17. int32 exitcode = atoi (exitcode_str);
  18.  
  19. // Handle atoi() errors
  20. if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
  21. return false;
  22.  
  23. // Exit code should be in range of 0-125, 126-255 is used
  24. // in many shells for their own return codes and code > 255
  25. // is not supported in many others
  26. if (exitcode < 0 || exitcode > 125)
  27. return false;
  28.  
  29. sWorld.ShutdownServ (time, 0, exitcode);
  30. }
  31. else
  32. sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
  33. return true;
  34. }
Add Comment
Please, Sign In to add comment