// ====================================================
// Shared code for server commands, written by Samual
-// Last updated: December 25th, 2011
+// Last updated: December 27th, 2011
// ====================================================
// select the proper prefix for usage and other messages
print(input, "\n");
}
+// ==========================================
+// Supporting functions for common commands
+// ==========================================
+
+
// ===================================================
// Common commands used in both sv_cmd.qc and cmd.qc
}
}
-void CommonCommand_timein(float request, entity caller) // todo entirely re-write this
+void CommonCommand_timein(float request, entity caller)
{
switch(request)
{
case CMD_REQUEST_COMMAND:
{
- if(caller.flags & FL_CLIENT)
+ if(autocvar_sv_timeout)
{
- if(autocvar_sv_timeout)
+ if not(timeout_status) { print_to(caller, "^7Error: There is no active timeout called."); }
+ else if(caller && (caller != timeout_caller)) { print_to(caller, "^7Error: You are not allowed to stop the active timeout."); }
+
+ else // everything should be okay, continue aborting timeout
{
- if (!timeoutStatus)
- return print_to(caller, "^7Error: There is no active timeout which could be aborted!");
- if (caller != timeoutInitiator)
- return print_to(caller, "^7Error: You may not abort the active timeout. Only the player who called it can do that!");
-
- if (timeoutStatus == 1)
- {
- remainingTimeoutTime = timeoutStatus = 0;
- timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
- bprint(strcat("^7The timeout was aborted by ", caller.netname, " !\n"));
- }
- else if (timeoutStatus == 2)
+ switch(timeout_status)
{
- //only shorten the remainingTimeoutTime if it makes sense
- if( remainingTimeoutTime > (autocvar_sv_timeout_resumetime + 1) )
+ case TIMEOUT_LEADTIME:
{
+ timeout_status = TIMEOUT_INACTIVE;
+ timeout_time = 0;
+ timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately
+ bprint(strcat("^7The timeout was aborted by ", caller.netname, " !\n"));
+ return;
+ }
+
+ case TIMEOUT_ACTIVE:
+ {
+ timeout_time = autocvar_sv_timeout_resumetime;
+ timeoutHandler.nextthink = time; // timeout_handler has to take care of it immediately
bprint(strcat("^1Attention: ^7", caller.netname, " resumed the game! Prepare for battle!\n"));
- remainingTimeoutTime = autocvar_sv_timeout_resumetime;
- timeoutHandler.nextthink = time; //timeoutHandler has to take care of it immediately
+ return;
}
- else
- print_to(caller, "^7Error: Your resumegame call was discarded!");
+
+ default: dprint("timeout status was inactive, but this code was executed anyway?"); return;
}
}
}
{
if(autocvar_sv_timeout)
{
- if(vote_called) { print_to(caller, "^7Error: You can not call a timeout while a vote is active."); }
+ float last_possible_timeout = ((autocvar_timelimit * 60) - autocvar_sv_timeout_leadtime - 1);
+
+ if(timeout_status) { print_to(caller, "^7Error: A timeout is already active."); }
+ else if(vote_called) { print_to(caller, "^7Error: You can not call a timeout while a vote is active."); }
else if(inWarmupStage && !g_warmup_allow_timeout) { print_to(caller, "^7Error: You can not call a timeout in warmup-stage."); }
else if(time < game_starttime) { print_to(caller, "^7Error: You can not call a timeout while the map is being restarted."); }
- else if(caller && (caller.allowedTimeouts < 1)) { print_to(caller, "^7Error: You already used all your timeout calls for this map."); }
+ else if(caller && (caller.allowed_timeouts < 1)) { print_to(caller, "^7Error: You already used all your timeout calls for this map."); }
else if(caller && (caller.classname != "player")) { print_to(caller, "^7Error: You must be a player to call a timeout."); }
+ else if((autocvar_timelimit) && (last_possible_timeout < time - game_starttime)) { print_to(caller, "^7Error: It is too late to call a timeout now!"); }
else // everything should be okay, proceed with starting the timeout
- {
- if (timeoutStatus != 2) {
- //if the map uses a timelimit make sure that timeout cannot be called right before the map ends
- if (autocvar_timelimit) {
- //a timelimit was used
- float myTl;
- myTl = autocvar_timelimit;
-
- float lastPossibleTimeout;
- lastPossibleTimeout = (myTl*60) - autocvar_sv_timeout_leadtime - 1;
-
- if (lastPossibleTimeout < time - game_starttime)
- return print_to(caller, "^7Error: It is too late to call a timeout now!");
- }
- }
-
- if(caller) { caller.allowedTimeouts -= 1; }
+ {
+ if(caller) { caller.allowed_timeouts -= 1; }
bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(caller.allowedTimeouts), " timeouts left)") : string_null), "!\n"); // write a bprint who started the timeout (and how many they have left)
- remainingTimeoutTime = autocvar_sv_timeout_length;
- remainingLeadTime = autocvar_sv_timeout_leadtime;
-
- timeoutInitiator = caller;
-
- // if another timeout was already active, don't change its status (which was 1 or 2) to 1
- if (timeoutStatus == 0)
- {
- timeoutStatus = 1;
- timeoutHandler = spawn();
- timeoutHandler.think = timeoutHandler_Think;
- }
+ timeout_status = TIMEOUT_LEADTIME;
+ timeout_caller = caller;
+ timeout_time = autocvar_sv_timeout_length;
+ timeout_leadtime = autocvar_sv_timeout_leadtime;
- timeoutHandler.nextthink = time; //always let the entity think asap
+ timeout_handler = spawn();
+ timeout_handler.think = timeout_handler_think;
+ timeout_handler.nextthink = time; // always let the entity think asap
Announce("timeoutcalled");
}
// ============================================================
// Shared declarations for server commands, written by Samual
-// Last updated: December 13th, 2011
+// Last updated: December 27th, 2011
// ============================================================
+// client verification results
#define CLIENT_ACCEPTABLE 1
#define CLIENT_DOESNT_EXIST -1
#define CLIENT_NOT_REAL -2
-#define CLIENT_NOT_BOT -3
\ No newline at end of file
+#define CLIENT_NOT_BOT -3
+
+// definitions for timeouts
+#define TIMEOUT_INACTIVE 0
+#define TIMEOUT_LEADTIME 1
+#define TIMEOUT_ACTIVE 2
+
+// timeout which pauses the game by setting the slowmo value extremely low.
+#define TIMEOUT_SLOWMO_VALUE 0.0001
+
+// global timeout information declarations
+entity timeout_caller; // contains the entity of the player who started the last timeout
+entity timeout_handler; // responsible for centerprinting the timeout countdowns and playing sounds
+float sys_frametime; // gets initialised in worldspawn, saves the value from autocvar_sys_ticrate
+float orig_slowmo; // contains the value of autocvar_slowmo so that, after timeout finished, it isn't set to slowmo 1 necessarily
+float timeout_time; // contains the time in seconds that the active timeout has left
+float timeout_leadtime; // contains the number of seconds left of the leadtime (before the timeout starts)
+float timeout_status; // (values: 0, 1, 2) contains whether a timeout is not active (0), was called but still at leadtime (1) or is active (2)
+.float allowed_timeouts; // contains the number of allowed timeouts for each player
+.vector lastV_angle; //used when pausing the game in order to force the player to keep his old view angle fixed
+
+// allow functions to be used in other code like g_world.qc and teamplay.qc
+void timeout_handler_think();
\ No newline at end of file
float nJoinAllowed(float includeMe);
#define PREVENT_JOIN_TEXT "^1You may not join the game at this time.\n\nThe player limit reached maximum capacity."
-//sv_timeout: pauses the game by setting the gamespeed to a really low value (see TIMEOUT_SLOWMO_VALUE)
-#define TIMEOUT_SLOWMO_VALUE 0.0001
-float sys_frametime; // gets initialised in worlspawn, saves the value from autocvar_sys_ticrate
-float remainingTimeoutTime; // contains the time in seconds that the active timeout has left
-float remainingLeadTime; // contains the number of seconds left of the leadtime (before the timeout starts)
-float timeoutStatus; // (values: 0, 1, 2) contains whether a timeout is not active (0), was called but still at leadtime (1) or is active (2)
-.float allowedTimeouts; // contains the number of allowed timeouts for each player
-entity timeoutInitiator; // contains the entity of the player who started the last timeout
-float orig_slowmo; // contains the value of autocvar_slowmo so that, after timeout finished, it isn't set to slowmo 1 necessarily
-.vector lastV_angle; //used when pausing the game in order to force the player to keep his old view angle fixed
-entity timeoutHandler; //responsible for centerprinting the timeout countdowns and playing sounds
-void timeoutHandler_Think();
-
.float spawnshieldtime;
.float lms_nextcheck;