just for context, im trying to start my server at 12am (noon) and end it at 3am every day. its realistically only a server for friends and a few other people in the grapevine, and there wont be anybody on from 3am-12am(noon), so i dont want the server running during that time.
a friend and i just spent the last 4-5 hours trying to program a c++ script in visual studio to basically start the server one inital time, then once it meets that value it will trigger the rest of the commands (i.e. server.loadcfg, and then the shutdown warnings, then one final save and the server.stop. it will do the "quit" commands, which just stops the server but it immediately starts the server again after that.
the problem we're having with the code though, which i will post below, is once it runs the initial command at 11:50 to start the server bootup, it will not trigger any other commands after that (i.e. the 11:58 command to server.loadcfg), or any others after that. on the contrary, all of the other commands will display in the cfg only if you dont do the 11:50 command to start the server first. it makes no sense.
so i guess this is kind of a double topic thread. 1), is there a better way or already existing way to do this, and 2), why isnt the coding working (for anyone that has C++ experience)
thanks in advance.
here is the code, and sorry in advance. there was no C++ option so i went with C#:
// Rust Server Times.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <windows.h>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <array>
#include <stdio.h>
#include <ctime>
#include <fstream>
#include <tchar.h>
#define WIN32_LEAN_AND_MEAN
using namespace std;
int main() {
do
{
time_t now = time(0);
tm* ltm = localtime(&now);
int x = 0;
if (ltm->tm_hour == 11 && ltm->tm_min == 50 && x == 0)
{
system("RUST_SERVER_START.bat");
}
if (ltm->tm_hour == 11 && ltm->tm_min == 58)
{
cout << "server.loadcfg";
}
if (ltm->tm_hour == 11 && ltm->tm_min == 50 && x == 1)
{
cout << "quit";
}
if (ltm->tm_hour == 2 && ltm->tm_min == 30)
{
cout << "say Server restarting in 30 minutes!";
}
if (ltm->tm_hour == 2 && ltm->tm_min == 45)
{
cout << "say Server restarting in 15 minutes!";
}
if (ltm->tm_hour == 2 && ltm->tm_min == 55)
{
cout << "say Server restarting in 5 minutes!";
}
if (ltm->tm_hour == 2 && ltm->tm_min == 59)
{
cout << "say Server is restarting in 1 minute!";
}
if (ltm->tm_hour == 2 && ltm->tm_min == 59 && ltm->tm_sec == 55)
{
cout << "save";
}
if (ltm->tm_hour == 3)
{
cout << "say Server is now shutting down until noon(12pm). Thanks for playing!";
cout << "server.stop";
x = 1;
}
}
while (1);
}