4653 | | if(std::string(args)=="cancel") |
4654 | | { |
4655 | | sWorld.ShutdownCancel(); |
| 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')) |
| 4684 | return false; |
| 4685 | |
| 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) |
| 4690 | return false; |
| 4691 | |
| 4692 | sWorld.ShutdownServ (time, 0, exitcode); |
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) |
| 4695 | sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE); |
| 4696 | return true; |
| 4697 | } |
| 4698 | |
| 4699 | bool ChatHandler::HandleServerRestartCommand(const char* args) |
| 4700 | { |
| 4701 | if(!*args) |
| 4702 | return false; |
| 4703 | |
| 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')) |
4665 | | sWorld.ShutdownServ(time); |
4666 | | } |
4667 | | return true; |
4668 | | } |
4669 | | |
4670 | | bool ChatHandler::HandleRestartCommand(const char* args) |
| 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) |
4675 | | if(std::string(args)=="cancel") |
4676 | | { |
4677 | | sWorld.ShutdownCancel(); |
| 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); |
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) |
| 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')) |
4687 | | sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART); |
4688 | | } |
4689 | | return true; |
4690 | | } |
4691 | | |
4692 | | bool ChatHandler::HandleIdleRestartCommand(const char* args) |
4693 | | { |
4694 | | if(!*args) |
4695 | | return false; |
4696 | | |
4697 | | if(std::string(args)=="cancel") |
4698 | | { |
4699 | | sWorld.ShutdownCancel(); |
| 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); |
4702 | | { |
4703 | | int32 time = atoi(args); |
4704 | | |
4705 | | ///- Prevent interpret wrong arg value as 0 secs shutdown time |
4706 | | if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0) |
4707 | | return false; |
4708 | | |
4709 | | sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE); |
4710 | | } |
4711 | | return true; |
4712 | | } |
4713 | | |
4714 | | bool ChatHandler::HandleIdleShutDownCommand(const char* args) |
4715 | | { |
4716 | | if(!*args) |
4717 | | return false; |
4718 | | |
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) |
4729 | | return false; |
4730 | | |
4731 | | sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE); |
4732 | | } |
| 4800 | sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE); |