4669 | | char* time_str = strtok ((char*) args, " "); |
4670 | | char* exitcode_str = strtok (NULL, ""); |
4671 | | |
4672 | | int32 time = atoi (time_str); |
4673 | | |
4674 | | ///- Prevent interpret wrong arg value as 0 secs shutdown time |
4675 | | if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0) |
4676 | | return false; |
4677 | | |
4678 | | if (exitcode_str) |
4679 | | { |
4680 | | int32 exitcode = atoi (exitcode_str); |
4681 | | |
4682 | | // Handle atoi() errors |
4683 | | if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0')) |
| 4653 | if(std::string(args)=="cancel") |
| 4654 | { |
| 4655 | sWorld.ShutdownCancel(); |
| 4656 | } |
| 4657 | else |
| 4658 | { |
| 4659 | int32 time = atoi(args); |
| 4660 | |
| 4661 | ///- Prevent interpret wrong arg value as 0 secs shutdown time |
| 4662 | if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0) |
4686 | | // Exit code should be in range of 0-125, 126-255 is used |
4687 | | // in many shells for their own return codes and code > 255 |
4688 | | // is not supported in many others |
4689 | | if (exitcode < 0 || exitcode > 125) |
| 4665 | sWorld.ShutdownServ(time); |
| 4666 | } |
| 4667 | return true; |
| 4668 | } |
| 4669 | |
| 4670 | bool ChatHandler::HandleRestartCommand(const char* args) |
| 4671 | { |
| 4672 | if(!*args) |
| 4673 | return false; |
| 4674 | |
| 4675 | if(std::string(args)=="cancel") |
| 4676 | { |
| 4677 | sWorld.ShutdownCancel(); |
| 4678 | } |
| 4679 | else |
| 4680 | { |
| 4681 | int32 time = atoi(args); |
| 4682 | |
| 4683 | ///- Prevent interpret wrong arg value as 0 secs shutdown time |
| 4684 | if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0) |
4704 | | char* time_str = strtok ((char*) args, " "); |
4705 | | char* exitcode_str = strtok (NULL, ""); |
4706 | | |
4707 | | int32 time = atoi (time_str); |
4708 | | |
4709 | | ///- Prevent interpret wrong arg value as 0 secs shutdown time |
4710 | | if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0) |
4711 | | return false; |
4712 | | |
4713 | | if (exitcode_str) |
4714 | | { |
4715 | | int32 exitcode = atoi (exitcode_str); |
4716 | | |
4717 | | // Handle atoi() errors |
4718 | | if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0')) |
| 4719 | if(std::string(args)=="cancel") |
| 4720 | { |
| 4721 | sWorld.ShutdownCancel(); |
| 4722 | } |
| 4723 | else |
| 4724 | { |
| 4725 | int32 time = atoi(args); |
| 4726 | |
| 4727 | ///- Prevent interpret wrong arg value as 0 secs shutdown time |
| 4728 | if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0) |
4721 | | // Exit code should be in range of 0-125, 126-255 is used |
4722 | | // in many shells for their own return codes and code > 255 |
4723 | | // is not supported in many others |
4724 | | if (exitcode < 0 || exitcode > 125) |
4725 | | return false; |
4726 | | |
4727 | | sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode); |
4728 | | } |
4729 | | else |
4730 | | sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE); |
4731 | | return true; |
4732 | | } |
4733 | | |
4734 | | bool ChatHandler::HandleServerIdleRestartCommand(const char* args) |
4735 | | { |
4736 | | if(!*args) |
4737 | | return false; |
4738 | | |
4739 | | char* time_str = strtok ((char*) args, " "); |
4740 | | char* exitcode_str = strtok (NULL, ""); |
4741 | | |
4742 | | int32 time = atoi (time_str); |
4743 | | |
4744 | | ///- Prevent interpret wrong arg value as 0 secs shutdown time |
4745 | | if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0) |
4746 | | return false; |
4747 | | |
4748 | | if (exitcode_str) |
4749 | | { |
4750 | | int32 exitcode = atoi (exitcode_str); |
4751 | | |
4752 | | // Handle atoi() errors |
4753 | | if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0')) |
4754 | | return false; |
4755 | | |
4756 | | // Exit code should be in range of 0-125, 126-255 is used |
4757 | | // in many shells for their own return codes and code > 255 |
4758 | | // is not supported in many others |
4759 | | if (exitcode < 0 || exitcode > 125) |
4760 | | return false; |
4761 | | |
4762 | | sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode); |
4763 | | } |
4764 | | else |
4765 | | sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE); |
4766 | | return true; |
4767 | | } |
4768 | | |
4769 | | bool ChatHandler::HandleServerIdleShutDownCommand(const char* args) |
4770 | | { |
4771 | | if(!*args) |
4772 | | return false; |
4773 | | |
4774 | | char* time_str = strtok ((char*) args, " "); |
4775 | | char* exitcode_str = strtok (NULL, ""); |
4776 | | |
4777 | | int32 time = atoi (time_str); |
4778 | | |
4779 | | ///- Prevent interpret wrong arg value as 0 secs shutdown time |
4780 | | if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0) |
4781 | | return false; |
4782 | | |
4783 | | if (exitcode_str) |
4784 | | { |
4785 | | int32 exitcode = atoi (exitcode_str); |
4786 | | |
4787 | | // Handle atoi() errors |
4788 | | if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0')) |
4789 | | return false; |
4790 | | |
4791 | | // Exit code should be in range of 0-125, 126-255 is used |
4792 | | // in many shells for their own return codes and code > 255 |
4793 | | // is not supported in many others |
4794 | | if (exitcode < 0 || exitcode > 125) |
4795 | | return false; |
4796 | | |
4797 | | sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode); |
4798 | | } |
4799 | | else |
4800 | | sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE); |
| 4731 | sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE); |
| 4732 | } |