]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Lots and lots of improvements all around :D
authorSamual <samual@xonotic.org>
Wed, 14 Dec 2011 17:22:12 +0000 (12:22 -0500)
committerSamual <samual@xonotic.org>
Wed, 14 Dec 2011 17:22:12 +0000 (12:22 -0500)
qcsrc/server/command/cmd.qh
qcsrc/server/command/common.qc
qcsrc/server/command/ipban.qh
qcsrc/server/command/sv_cmd.qh
qcsrc/server/command/vote.qc
qcsrc/server/command/vote.qh

index a9695dff2b214c1d0929c8d6a93b2cbd65fc268f..f7693a33b139765deb9320aef80fbb1b59ae877e 100644 (file)
@@ -1,7 +1,7 @@
-// =========================================================
-//  Server side networked commands code, reworked by Samual
-//  Last updated: December 11th, 2011
-// =========================================================
+// =================================================
+//  Declarations for server side networked commands
+//  Last updated: December 14th, 2011
+// =================================================
 
 .float cmd_floodtime;
 .float cmd_floodcount;
index 1b7b34ead2c210bb5aa4d0d206dc16ac2f852efb..d48730b785c55efa4d948dd2fd75bc68805260f7 100644 (file)
@@ -3,6 +3,22 @@
 //  Last updated: December 13th, 2011
 // ====================================================
 
+string GetCommandPrefix(entity caller)
+{
+       if(caller)
+               return "cmd";
+       else
+               return "sv_cmd";
+}
+
+string GetCallerName(entity caller)
+{
+       if(caller)
+               return caller.netname;
+       else
+               return ((autocvar_sv_adminnick != "") ? autocvar_sv_adminnick : autocvar_hostname);
+}
+
 // find a player which matches the input string, and return their entity number
 float GetFilteredNumber(string input)
 {
@@ -339,7 +355,7 @@ void CommonCommand_timeout(float request) // DEAR GOD THIS COMMAND IS TERRIBLE.
                                {
                                        if(self.classname == "player") 
                                        {
-                                               if(votecalled)
+                                               if(vote_called)
                                                        print_to(self, "^7Error: you can not call a timeout while a vote is active!\n");
                                                else
                                                {
index 58e7b405c422bd04a3b6507189bae6362d2469e9..056d5ca6d2acbb0266cb15322e05bd6ce1f67748 100644 (file)
@@ -1,4 +1,9 @@
+// ====================================
+//  Declarations for kick/ban commands
+//  Last updated: December 14th, 2011
+// =====================================
+
 void Ban_KickBanClient(entity client, float bantime, float masksize, string reason);
-float Ban_Insert(string ip, float bantime, string reason, float dosync);
 void Ban_View();
+float Ban_Insert(string ip, float bantime, string reason, float dosync);
 float Ban_Delete(float i);
\ No newline at end of file
index c2b3a046c171a200be4cf9104652b2d32187851b..633f4068060885fba4d66b61bfde271fe920606f 100644 (file)
@@ -1,7 +1,7 @@
-// =====================================================
-//  Server side game commands code, reworked by Samual
-//  Last updated: December 6th, 2011
-// =====================================================
+// =================================================
+//  Declarations for server side game commands
+//  Last updated: December 14th, 2011
+// =================================================
 
 float RadarMap_Make(float argc);
 
index 6d0db51017b1f148be2a02fdf56a04ee1599f3a8..671e97625ae560c73056d951440b7cee2946aef2 100644 (file)
@@ -27,7 +27,7 @@ float Nagger_SendEntity(entity to, float sendflags)
                if(to.ready == 0)
                        nags |= 2;
        }
-       if(votecalled)
+       if(vote_called)
        {
                nags |= 4;
                if(to.vote_selection == 0)
@@ -56,7 +56,7 @@ float Nagger_SendEntity(entity to, float sendflags)
        }
 
        if(nags & 128)
-               WriteString(MSG_ENTITY, votecalledvote_display);
+               WriteString(MSG_ENTITY, vote_called_display);
 
        if(nags & 1)
        {
@@ -106,17 +106,16 @@ void VoteReset()
 
        FOR_EACH_CLIENT(tmp_player) { tmp_player.vote_selection = 0; }
 
-       if(votecalled)
+       if(vote_called)
        {
-               strunzone(votecalledvote);
-               strunzone(votecalledvote_display);
+               strunzone(vote_called_command);
+               strunzone(vote_called_display);
        }
 
-       votecalled = FALSE;
-       votecalledmaster = FALSE;
-       votefinished = 0;
-       votecalledvote = string_null;
-       votecalledvote_display = string_null;
+       vote_called = VOTE_NULL;
+       vote_endtime = 0;
+       vote_called_command = string_null;
+       vote_called_display = string_null;
        
        vote_parsed_command = string_null;
        vote_parsed_display = string_null;
@@ -126,36 +125,25 @@ void VoteReset()
 
 void VoteStop(entity stopper) 
 {
-       bprint("\{1}^2* ^3", VoteCommand_getname(stopper), "^2 stopped ^3", VoteCommand_getname(votecaller), "^2's vote\n");
+       bprint("\{1}^2* ^3", GetCallerName(stopper), "^2 stopped ^3", GetCallerName(vote_caller), "^2's vote\n");
        if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vstop:", ftos(stopper.playerid))); }
        
        // Don't force them to wait for next vote, this way they can e.g. correct their vote.
-       if((votecaller) && (stopper == votecaller)) { votecaller.vote_next = time + autocvar_sv_vote_stop; }
+       if((vote_caller) && (stopper == vote_caller)) { vote_caller.vote_waittime = time + autocvar_sv_vote_stop; }
 
        VoteReset();
 }
 
-void VoteThink() 
-{
-       if(votefinished > 0) // a vote was called
-       if(time > votefinished) // time is up
-       {
-               VoteCount();
-       }
-       
-       return;
-}
-
 void VoteAccept() 
 {
-       bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2's vote for ^1", votecalledvote_display, "^2 was accepted\n");
+       bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2's vote for ^1", vote_called_display, "^2 was accepted\n");
        
-       if(votecalledmaster && votecaller)
-               votecaller.vote_master = 1;
+       if((vote_called == VOTE_MASTER) && vote_caller)
+               vote_caller.vote_master = 1;
        else
-               localcmd(strcat(votecalledvote, "\n"));
+               localcmd(strcat(vote_called_command, "\n"));
        
-       if(votecaller) { votecaller.vote_next = 0; } // people like your votes, you don't need to wait to vote again // todo separate anti-spam even for succeeded votes
+       if(vote_caller) { vote_caller.vote_waittime = 0; } // people like your votes, you don't need to wait to vote again // todo separate anti-spam even for succeeded votes
 
        VoteReset();
        Announce("voteaccept");
@@ -163,14 +151,14 @@ void VoteAccept()
 
 void VoteReject() 
 {
-       bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2's vote for ", votecalledvote_display, "^2 was rejected\n");
+       bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2's vote for ", vote_called_display, "^2 was rejected\n");
        VoteReset();
        Announce("votefail");
 }
 
 void VoteTimeout() 
 {
-       bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2's vote for ", votecalledvote_display, "^2 timed out\n");
+       bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2's vote for ", vote_called_display, "^2 timed out\n");
        VoteReset();
        Announce("votefail");
 }
@@ -232,10 +220,10 @@ void VoteCount()
        }
        
        // Check to see if there are enough players on the server to allow master voting... otherwise, vote master could be used for evil.
-       if(votecalledmaster && autocvar_sv_vote_master_playerlimit > vote_player_count) 
+       if((vote_called == VOTE_MASTER) && autocvar_sv_vote_master_playerlimit > vote_player_count) 
        {
-               if(votecaller) { votecaller.vote_next = 0; }
-               print_to(votecaller, "^1There are not enough players on this server to allow you to become vote master.");
+               if(vote_caller) { vote_caller.vote_waittime = 0; }
+               print_to(vote_caller, "^1There are not enough players on this server to allow you to become vote master.");
                VoteReset();
                return;
        }
@@ -277,7 +265,7 @@ void VoteCount()
        }
        
        // there is not enough votes in either direction, now lets just calculate what the voters have said
-       if(time > votefinished)
+       if(time > vote_endtime)
        {
                final_needed_votes = vote_needed_overall;
                
@@ -306,6 +294,17 @@ void VoteCount()
        }
 }
 
+void VoteThink() 
+{
+       if(vote_endtime > 0) // a vote was called
+       if(time > vote_endtime) // time is up
+       {
+               VoteCount();
+       }
+       
+       return;
+}
+
 
 // =======================
 //  Game logic for warmup
@@ -438,22 +437,6 @@ float Votecommand_check_assignment(entity caller, float assignment)
        return FALSE;
 }
 
-string VoteCommand_getprefix(entity caller)
-{
-       if(caller)
-               return "cmd";
-       else
-               return "sv_cmd";
-}
-
-string VoteCommand_getname(entity caller)
-{
-       if(caller)
-               return caller.netname;
-       else
-               return ((autocvar_sv_adminnick != "") ? autocvar_sv_adminnick : autocvar_hostname);
-}
-
 string VoteCommand_extractcommand(string input, float startpos, float argc) 
 {
        string output;
@@ -599,7 +582,7 @@ void VoteCommand_abstain(float request, entity caller) // CLIENT ONLY
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if not(votecalled) { print_to(caller, "^1No vote called."); }
+                       if not(vote_called) { print_to(caller, "^1No vote called."); }
                        else if not(caller.vote_selection == VOTE_SELECT_NULL || autocvar_sv_vote_change) { print_to(caller, "^1You have already voted."); }
                        
                        else // everything went okay, continue changing vote
@@ -639,34 +622,33 @@ void VoteCommand_call(float request, entity caller, float argc, string vote_comm
                        vote_command = VoteCommand_extractcommand(vote_command, 2, argc);
                        
                        if not(autocvar_sv_vote_call || !caller) { print_to(caller, "^1Vote calling is not allowed."); }
-                       else if(votecalled) { print_to(caller, "^1There is already a vote called."); }
+                       else if(vote_called) { print_to(caller, "^1There is already a vote called."); }
                        else if(!spectators_allowed && (caller && (caller.classname != "player"))) { print_to(caller, "^1Only players can call a vote."); }
                        else if(timeoutStatus) { print_to(caller, "^1You can not call a vote while a timeout is active."); }
-                       else if(caller && (time < caller.vote_next)) { print_to(caller, strcat("^1You have to wait ^2", ftos(ceil(caller.vote_next - time)), "^1 seconds before you can again call a vote.")); }
+                       else if(caller && (time < caller.vote_waittime)) { print_to(caller, strcat("^1You have to wait ^2", ftos(ceil(caller.vote_waittime - time)), "^1 seconds before you can again call a vote.")); }
                        else if not(VoteCommand_checknasty(vote_command)) { print_to(caller, "^1Syntax error in command, see 'vhelp' for more info."); }
                        else if not(VoteCommand_parse(caller, vote_command, autocvar_sv_vote_commands, 2, argc)) { print_to(caller, "^1This command is not acceptable, see 'vhelp' for more info."); }
 
                        else // everything went okay, continue with calling the vote // TODO: fixes to make this more compatible with sv_cmd
                        {
-                               votecalled = TRUE;
-                               votecalledmaster = FALSE;
-                               votecalledvote = strzone(vote_parsed_command);
-                               votecalledvote_display = strzone(vote_parsed_display);
-                               votefinished = time + autocvar_sv_vote_timeout;
-                               votecaller = caller; // remember who called the vote
+                               vote_called = VOTE_NORMAL;
+                               vote_called_command = strzone(vote_parsed_command);
+                               vote_called_display = strzone(vote_parsed_display);
+                               vote_endtime = time + autocvar_sv_vote_timeout;
+                               vote_caller = caller; // remember who called the vote
                                
                                if(caller)
                                {
                                        caller.vote_selection = VOTE_SELECT_ACCEPT;
-                                       caller.vote_next = time + autocvar_sv_vote_wait;
+                                       caller.vote_waittime = time + autocvar_sv_vote_wait;
                                        msg_entity = caller; // todo: what is this for?
                                }
                                
                                FOR_EACH_REALCLIENT(tmp_player) { ++tmp_playercount; }
                                if(tmp_playercount > 1) { Announce("votecall"); } // don't announce a "vote now" sound if player is alone
                                
-                               bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2 calls a vote for ", votecalledvote_display, "\n");
-                               if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(votecaller.playerid), ":", votecalledvote_display)); }
+                               bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2 calls a vote for ", vote_called_display, "\n");
+                               if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display)); }
                                Nagger_VoteChanged();
                                VoteCount(); // needed if you are the only one
                        }
@@ -706,7 +688,7 @@ void VoteCommand_master(float request, entity caller, float argc, string vote_co
                                                {
                                                        localcmd(strcat(vote_parsed_command, "\n"));
                                                        print_to(caller, strcat("Executing command '", vote_parsed_display, "' on server."));
-                                                       bprint("\{1}^2* ^3", VoteCommand_getname(caller), "^2 used their ^3master^2 status to do \"^2", vote_parsed_display, "^2\".\n");
+                                                       bprint("\{1}^2* ^3", GetCallerName(caller), "^2 used their ^3master^2 status to do \"^2", vote_parsed_display, "^2\".\n");
                                                        if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vdo:", ftos(caller.playerid), ":", vote_parsed_display)); }
                                                }
                                                
@@ -717,13 +699,13 @@ void VoteCommand_master(float request, entity caller, float argc, string vote_co
                                        {
                                                if not(autocvar_sv_vote_master_password != "") { print_to(caller, "^1Login to vote master is not allowed."); }
                                                else if(caller.vote_master) { print_to(caller, "^1You are already logged in as vote master."); }
-                                               else if not(autocvar_sv_vote_master_password == argv(3)) { print_to(caller, strcat("Rejected vote master login from ", VoteCommand_getname(caller))); }
+                                               else if not(autocvar_sv_vote_master_password == argv(3)) { print_to(caller, strcat("Rejected vote master login from ", GetCallerName(caller))); }
 
                                                else // everything went okay, proceed with giving this player master privilages
                                                {
                                                        caller.vote_master = TRUE;
-                                                       print_to(caller, strcat("Accepted vote master login from ", VoteCommand_getname(caller)));
-                                                       bprint("\{1}^2* ^3", VoteCommand_getname(caller), "^2 logged in as ^3master^2\n");
+                                                       print_to(caller, strcat("Accepted vote master login from ", GetCallerName(caller)));
+                                                       bprint("\{1}^2* ^3", GetCallerName(caller), "^2 logged in as ^3master^2\n");
                                                        if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vlogin:", ftos(caller.playerid))); }
                                                }
                                                
@@ -733,22 +715,21 @@ void VoteCommand_master(float request, entity caller, float argc, string vote_co
                                        default: // calling a vote for master
                                        {
                                                if not(autocvar_sv_vote_master_callable) { print_to(caller, "^1Vote to become vote master is not allowed."); }
-                                               else if(votecalled) { print_to(caller, "^1There is already a vote called."); }
+                                               else if(vote_called) { print_to(caller, "^1There is already a vote called."); }
                                                
                                                else // everything went okay, continue with creating vote
                                                {
-                                                       votecalled = TRUE;
-                                                       votecalledmaster = TRUE;
-                                                       votecalledvote = strzone("XXX");
-                                                       votecalledvote_display = strzone("^3master");
-                                                       votefinished = time + autocvar_sv_vote_timeout;
-                                                       votecaller = caller;
+                                                       vote_called = VOTE_MASTER;
+                                                       vote_called_command = strzone("XXX");
+                                                       vote_called_display = strzone("^3master");
+                                                       vote_endtime = time + autocvar_sv_vote_timeout;
+                                                       vote_caller = caller;
                                                        
                                                        caller.vote_selection = VOTE_SELECT_ACCEPT;
-                                                       caller.vote_next = time + autocvar_sv_vote_wait;
+                                                       caller.vote_waittime = time + autocvar_sv_vote_wait;
                                                        
-                                                       bprint("\{1}^2* ^3", VoteCommand_getname(votecaller), "^2 calls a vote to become ^3master^2.\n");
-                                                       if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(votecaller.playerid), ":", votecalledvote_display)); }
+                                                       bprint("\{1}^2* ^3", GetCallerName(vote_caller), "^2 calls a vote to become ^3master^2.\n");
+                                                       if(autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:vcall:", ftos(vote_caller.playerid), ":", vote_called_display)); }
                                                        Nagger_VoteChanged();
                                                        VoteCount(); // needed if you are the only one
                                                }
@@ -778,7 +759,7 @@ void VoteCommand_no(float request, entity caller) // CLIENT ONLY
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if not(votecalled) { print_to(caller, "^1No vote called."); }
+                       if not(vote_called) { print_to(caller, "^1No vote called."); }
                        else if not(caller.vote_selection == VOTE_SELECT_NULL || autocvar_sv_vote_change) { print_to(caller, "^1You have already voted."); }
                        
                        else // everything went okay, continue changing vote
@@ -808,8 +789,8 @@ void VoteCommand_status(float request, entity caller) // BOTH
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if(votecalled)
-                               print_to(caller, strcat("^7Vote for ", votecalledvote_display, "^7 called by ^7", VoteCommand_getname(votecaller), "^7."));
+                       if(vote_called)
+                               print_to(caller, strcat("^7Vote for ", vote_called_display, "^7 called by ^7", GetCallerName(vote_caller), "^7."));
                        else
                                print_to(caller, "^1No vote called.");
                                
@@ -832,8 +813,8 @@ void VoteCommand_stop(float request, entity caller) // BOTH
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if not(votecalled) { print_to(caller, "^1No vote called."); }
-                       else if((caller == votecaller) || !caller || caller.vote_master) { VoteStop(caller); }
+                       if not(vote_called) { print_to(caller, "^1No vote called."); }
+                       else if((caller == vote_caller) || !caller || caller.vote_master) { VoteStop(caller); }
                        else { print_to(caller, "^1You are not allowed to stop that vote."); }
                        
                        return;
@@ -855,7 +836,7 @@ void VoteCommand_yes(float request, entity caller) // CLIENT ONLY
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if not(votecalled) { print_to(caller, "^1No vote called."); }
+                       if not(vote_called) { print_to(caller, "^1No vote called."); }
                        if not(caller.vote_selection == VOTE_SELECT_NULL || autocvar_sv_vote_change) { print_to(caller, "^1You have already voted."); }
                        
                        else // everything went okay, continue changing vote
@@ -920,7 +901,7 @@ void VoteCommand_(float request)
 
 void VoteCommand_macro_help(entity caller, float argc)
 {
-       string command_origin = VoteCommand_getprefix(caller);
+       string command_origin = GetCommandPrefix(caller);
        
        if(argc == 2) // help display listing all commands
        {
@@ -978,7 +959,7 @@ void VoteCommand(float request, entity caller, float argc, string vote_command)
                }
                        
                default:
-                       print_to(caller, strcat("Unknown vote command", ((argv(1) != "") ? strcat(" \"", argv(1), "\"") : ""), ". For a list of supported commands, try ", VoteCommand_getprefix(caller), " help.\n"));
+                       print_to(caller, strcat("Unknown vote command", ((argv(1) != "") ? strcat(" \"", argv(1), "\"") : ""), ". For a list of supported commands, try ", GetCommandPrefix(caller), " help.\n"));
                case CMD_REQUEST_USAGE:
                {
                        VoteCommand_macro_help(caller, argc);
index bf88e652bc7604de337634d81e2fa173c70f8785..691407706a819a79039a79622940812094462ec7 100644 (file)
@@ -1,49 +1,49 @@
+// ================================================
+//  Declarations for the vote system/vote commands
+//  Last updated: December 14th, 2011
+// ================================================
+
+// definitions for command selection between progs
 #define VC_ASGNMNT_BOTH 1
 #define VC_ASGNMNT_CLIENTONLY 2
 #define VC_ASGNMNT_SERVERONLY 3
 
+// vote selection definitions
 #define VOTE_SELECT_ABSTAIN -2
 #define VOTE_SELECT_REJECT -1
 #define VOTE_SELECT_NULL 0
 #define VOTE_SELECT_ACCEPT 1
 
-string vote_parsed_command;
-string vote_parsed_display;
+// different statuses of the current vote
+#define VOTE_NULL 0
+#define VOTE_NORMAL 1
+#define VOTE_MASTER 2
 
-float votecalled;
-string votecalledvote;
-string votecalledvote_display;
-float votecalledmaster;
-entity votecaller;
-float votefinished;
-.float vote_master;
-.float vote_next;
-.float vote_selection;
-float vote_accept_count;
-float vote_reject_count;
-float vote_abstain_count;
-float vote_needed_overall;
+// global vote information declarations
+entity vote_caller; // original caller of the current vote
+float vote_called; // stores status of current vote (See VOTE_*)
+float vote_endtime; // time when the vote is finished
+float vote_accept_count; // total amount of players who accept the vote (counted by VoteCount() function)
+float vote_reject_count; // same as above, but rejected
+float vote_abstain_count; // same as above, but abstained
+float vote_needed_overall; // total amount of players NEEDED for a vote to pass (based on sv_vote_majority_factor)
+.float vote_master; // flag for if the player has vote master privelages 
+.float vote_waittime; // flag for how long the player must wait before they can vote again
+.float vote_selection; // flag for which vote selection the player has made (See VOTE_SELECT_*)
+string vote_called_command; // command sent by client
+string vote_called_display; // visual string of command sent by client
+string vote_parsed_command; // command which is fixed after being parsed
+string vote_parsed_display; // visual string which is fixed after being parsed
 
-string VoteCommand_getname(entity caller);
-void VoteCommand(float request, entity caller, float argc, string vote_command);
-void VoteHelp(entity e);
+// allow functions to be used in other code like g_world.qc and teamplay.qc
 void VoteThink();
 void VoteReset();
-void VoteAccept();
-void VoteReject();
-void VoteTimeout();
-void VoteStop(entity stopper);
-void VoteSpam(float notvoters, float mincount, string result);
-void VoteCount();
-
-// =========================
-//  warmup and nagger stuff
-// =========================
 
+// warmup and nagger stuff
 #define RESTART_COUNTDOWN 10
 entity nagger;
-.float ready;
-float readycount;
-float readyrestart_happened;
+float readycount; // amount of players who are ready
+float readyrestart_happened; // keeps track of whether a restart has already happened
 float restart_mapalreadyrestarted; // bool, indicates whether reset_map() was already executed
+.float ready; // flag for if a player is ready
 void ReadyCount();
\ No newline at end of file