X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fcommand%2Fcommon.qc;h=c5ae7c7be069798f4cc0eff048f4d50e5633e7ac;hp=132a0af70e31be2fbc97bbc79006ae5b5c1f263c;hb=04ab0ff7c3c5fcfe9780eadccfd5abd03d25b181;hpb=1633673cc6c65bdca0120f2a4fc33e8c2449f06d diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index 132a0af70..c5ae7c7be 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -24,13 +24,13 @@ string GetCallerName(entity caller) // verify that the client provided is acceptable for use float VerifyClientEntity(entity client, float must_be_real, float must_be_bots) { - if not(client.flags & FL_CLIENT) + if (!IS_CLIENT(client)) return CLIENT_DOESNT_EXIST; - else if(must_be_real && (clienttype(client) != CLIENTTYPE_REAL)) + else if(must_be_real && !IS_REAL_CLIENT(client)) return CLIENT_NOT_REAL; - else if(must_be_bots && (clienttype(client) != CLIENTTYPE_BOT)) + else if(must_be_bots && !IS_BOT_CLIENT(client)) return CLIENT_NOT_BOT; - + return CLIENT_ACCEPTABLE; } @@ -60,18 +60,18 @@ entity GetIndexedEntity(float argc, float start_index) entity tmp_player, selection; float tmp_number, index; string tmp_string; - + next_token = -1; index = start_index; selection = world; - + if(argc > start_index) { if(substring(argv(index), 0, 1) == "#") { tmp_string = substring(argv(index), 1, -1); ++index; - + if(tmp_string != "") // is it all one token? like #1 { tmp_number = stof(tmp_string); @@ -89,7 +89,7 @@ entity GetIndexedEntity(float argc, float start_index) tmp_number = stof(argv(index)); ++index; } - + if(VerifyClientNumber(tmp_number)) { selection = edict_num(tmp_number); // yes, it was a number @@ -99,11 +99,11 @@ entity GetIndexedEntity(float argc, float start_index) FOR_EACH_CLIENT(tmp_player) if (strdecolorize(tmp_player.netname) == strdecolorize(argv(start_index))) selection = tmp_player; - + index = (start_index + 1); } } - + next_token = index; //print(strcat("start_index: ", ftos(start_index), ", next_token: ", ftos(next_token), ", edict: ", ftos(num_for_edict(selection)), ".\n")); return selection; @@ -114,12 +114,12 @@ entity GetFilteredEntity(string input) { entity tmp_player, selection; float tmp_number; - + if(substring(input, 0, 1) == "#") tmp_number = stof(substring(input, 1, -1)); else tmp_number = stof(input); - + if(VerifyClientNumber(tmp_number)) { selection = edict_num(tmp_number); @@ -131,7 +131,7 @@ entity GetFilteredEntity(string input) if (strdecolorize(tmp_player.netname) == strdecolorize(input)) selection = tmp_player; } - + return selection; } @@ -140,7 +140,7 @@ float GetFilteredNumber(string input) { entity selection = GetFilteredEntity(input); float output; - + output = num_for_edict(selection); return output; @@ -165,14 +165,14 @@ void timeout_handler_reset() timeout_caller = world; timeout_time = 0; timeout_leadtime = 0; - + remove(self); } -void timeout_handler_think() +void timeout_handler_think() { entity tmp_player; - + switch(timeout_status) { case TIMEOUT_ACTIVE: @@ -190,53 +190,53 @@ void timeout_handler_think() else // time to end the timeout { timeout_status = TIMEOUT_INACTIVE; - + // reset the slowmo value back to normal cvar_set("slowmo", ftos(orig_slowmo)); - + // unlock the view for players so they can move around again - FOR_EACH_REALPLAYER(tmp_player) + FOR_EACH_REALPLAYER(tmp_player) tmp_player.fixangle = FALSE; - + timeout_handler_reset(); } - + return; } - + case TIMEOUT_LEADTIME: { if(timeout_leadtime > 0) // countdown is still going { Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_TIMEOUT_BEGINNING, timeout_leadtime); - + self.nextthink = time + 1; // think again in one second timeout_leadtime -= 1; // decrease the time counter } else // time to begin the timeout { timeout_status = TIMEOUT_ACTIVE; - + // set the slowmo value to the timeout default slowmo value cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE)); - + // reset all the flood variables FOR_EACH_CLIENT(tmp_player) tmp_player.nickspamcount = tmp_player.nickspamtime = tmp_player.floodcontrol_chat = - tmp_player.floodcontrol_chatteam = tmp_player.floodcontrol_chattell = + tmp_player.floodcontrol_chatteam = tmp_player.floodcontrol_chattell = tmp_player.floodcontrol_voice = tmp_player.floodcontrol_voiceteam = 0; - + // copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink) - FOR_EACH_REALPLAYER(tmp_player) + FOR_EACH_REALPLAYER(tmp_player) tmp_player.lastV_angle = tmp_player.v_angle; - + self.nextthink = time; // think again next frame to handle it under TIMEOUT_ACTIVE code } - + return; } - - + + case TIMEOUT_INACTIVE: default: { @@ -261,7 +261,7 @@ void CommonCommand_cvar_changes(float request, entity caller) print_to(caller, cvar_changes); return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -282,7 +282,7 @@ void CommonCommand_cvar_purechanges(float request, entity caller) print_to(caller, cvar_purechanges); return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -294,22 +294,22 @@ void CommonCommand_cvar_purechanges(float request, entity caller) } } -void CommonCommand_info(float request, entity caller, float argc) -{ +void CommonCommand_info(float request, entity caller, float argc) +{ switch(request) { case CMD_REQUEST_COMMAND: { - string command = builtin_cvar_string(strcat("sv_info_", argv(1))); - + string command = builtin_cvar_string(strcat("sv_info_", argv(1))); + if(command) - wordwrap_sprint(command, 1000); + wordwrap_sprint(command, 1000); else print_to(caller, "ERROR: unsupported info command"); - + return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -329,7 +329,7 @@ void CommonCommand_ladder(float request, entity caller) print_to(caller, ladder_reply); return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -349,31 +349,11 @@ void CommonCommand_lsmaps(float request, entity caller) print_to(caller, lsmaps_reply); return; // never fall through to usage } - - default: - case CMD_REQUEST_USAGE: - { - print_to(caller, strcat("\nUsage:^3 ", GetCommandPrefix(caller), " lsmaps")); - print_to(caller, " No arguments required."); - return; - } - } -} -void CommonCommand_lsnewmaps(float request, entity caller) -{ - switch(request) - { - case CMD_REQUEST_COMMAND: - { - print_to(caller, lsnewmaps_reply); - return; // never fall through to usage - } - default: case CMD_REQUEST_USAGE: { - print_to(caller, strcat("\nUsage:^3 ", GetCommandPrefix(caller), " lsnewmaps")); + print_to(caller, strcat("\nUsage:^3 ", GetCommandPrefix(caller), " lsmaps")); print_to(caller, " No arguments required."); return; } @@ -389,7 +369,7 @@ void CommonCommand_printmaplist(float request, entity caller) print_to(caller, maplist_reply); return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -409,7 +389,7 @@ void CommonCommand_rankings(float request, entity caller) print_to(caller, rankings_reply); return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -421,20 +401,20 @@ void CommonCommand_rankings(float request, entity caller) } void CommonCommand_records(float request, entity caller) -{ +{ switch(request) { case CMD_REQUEST_COMMAND: { float i; - + for(i = 0; i < 10; ++i) if(records_reply[i] != "") print_to(caller, records_reply[i]); - + return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -454,7 +434,7 @@ void CommonCommand_teamstatus(float request, entity caller) Score_NicePrint(caller); return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -480,7 +460,7 @@ void CommonCommand_time(float request, entity caller) print_to(caller, strcat("gmtime = ", strftime(FALSE, "%a %b %e %H:%M:%S %Z %Y"))); return; } - + default: case CMD_REQUEST_USAGE: { @@ -499,9 +479,9 @@ void CommonCommand_timein(float request, entity caller) { if(!caller || autocvar_sv_timeout) { - if not(timeout_status) { print_to(caller, "^7Error: There is no active timeout called."); } + if (!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 { switch(timeout_status) @@ -514,7 +494,7 @@ void CommonCommand_timein(float request, entity caller) bprint(strcat("^7The timeout was aborted by ", GetCallerName(caller), " !\n")); return; } - + case TIMEOUT_ACTIVE: { timeout_time = autocvar_sv_timeout_resumetime; @@ -522,16 +502,16 @@ void CommonCommand_timein(float request, entity caller) bprint(strcat("^1Attention: ^7", GetCallerName(caller), " resumed the game! Prepare for battle!\n")); return; } - + default: dprint("timeout status was inactive, but this code was executed anyway?"); return; } } } else { print_to(caller, "^1Timeins are not allowed to be called, enable them with sv_timeout 1.\n"); } - + return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -551,26 +531,26 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN if(!caller || autocvar_sv_timeout) { 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(warmup_stage && !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.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(caller && !IS_PLAYER(caller)) { 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(caller) { caller.allowed_timeouts -= 1; } - + bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(caller.allowed_timeouts), " timeout(s) left)") : ""), "!\n"); // write a bprint who started the timeout (and how many they have left) - + timeout_status = TIMEOUT_LEADTIME; timeout_caller = caller; timeout_time = autocvar_sv_timeout_length; timeout_leadtime = autocvar_sv_timeout_leadtime; - + timeout_handler = spawn(); timeout_handler.think = timeout_handler_think; timeout_handler.nextthink = time; // always let the entity think asap @@ -579,10 +559,10 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN } } else { print_to(caller, "^1Timeouts are not allowed to be called, enable them with sv_timeout 1.\n"); } - + return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -601,20 +581,20 @@ void CommonCommand_who(float request, entity caller, float argc) { float total_listed_players, is_bot; entity tmp_player; - + float privacy = (caller && autocvar_sv_status_privacy); string separator = strreplace("%", " ", strcat((argv(1) ? argv(1) : " "), "^7")); string tmp_netaddress, tmp_crypto_idfp; - + print_to(caller, strcat("List of client information", (privacy ? " (some data is hidden for privacy)" : ""), ":")); - print_to(caller, sprintf(strreplace(" ", separator, " %-4s %-20s %-5s %-3s %-9s %-16s %s "), + print_to(caller, sprintf(strreplace(" ", separator, " %-4s %-20s %-5s %-3s %-9s %-16s %s "), "ent", "nickname", "ping", "pl", "time", "ip", "crypto_id")); - + total_listed_players = 0; FOR_EACH_CLIENT(tmp_player) { - is_bot = (clienttype(tmp_player) == CLIENTTYPE_BOT); - + is_bot = (IS_BOT_CLIENT(tmp_player)); + if(is_bot) { tmp_netaddress = "null/botclient"; @@ -631,23 +611,23 @@ void CommonCommand_who(float request, entity caller, float argc) tmp_crypto_idfp = tmp_player.crypto_idfp; } - print_to(caller, sprintf(strreplace(" ", separator, " #%-3d %-20.20s %-5d %-3d %-9s %-16s %s "), - num_for_edict(tmp_player), + print_to(caller, sprintf(strreplace(" ", separator, " #%-3d %-20.20s %-5d %-3d %-9s %-16s %s "), + num_for_edict(tmp_player), tmp_player.netname, - tmp_player.ping, - tmp_player.ping_packetloss, + tmp_player.ping, + tmp_player.ping_packetloss, process_time(1, time - tmp_player.jointime), tmp_netaddress, tmp_crypto_idfp)); - + ++total_listed_players; } - + print_to(caller, strcat("Finished listing ", ftos(total_listed_players), " client(s) out of ", ftos(maxclients), " slots.")); - + return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -666,10 +646,10 @@ void CommonCommand_(float request, entity caller) { case CMD_REQUEST_COMMAND: { - + return; // never fall through to usage } - + default: case CMD_REQUEST_USAGE: { @@ -693,7 +673,6 @@ void CommonCommand_(float request, entity caller) COMMON_COMMAND("info", CommonCommand_info(request, caller, arguments), "Request for unique server information set up by admin") \ COMMON_COMMAND("ladder", CommonCommand_ladder(request, caller), "Get information about top players if supported") \ COMMON_COMMAND("lsmaps", CommonCommand_lsmaps(request, caller), "List maps which can be used with the current game mode") \ - COMMON_COMMAND("lsnewmaps", CommonCommand_lsnewmaps(request, caller), "List maps which have no records or are seemingly unplayed yet") \ COMMON_COMMAND("printmaplist", CommonCommand_printmaplist(request, caller), "Display full server maplist reply") \ COMMON_COMMAND("rankings", CommonCommand_rankings(request, caller), "Print information about rankings") \ COMMON_COMMAND("records", CommonCommand_records(request, caller), "List top 10 records for the current map") \ @@ -709,10 +688,10 @@ void CommonCommand_macro_help(entity caller) { #define COMMON_COMMAND(name,function,description) \ { print_to(caller, strcat(" ^2", name, "^7: ", description)); } - + COMMON_COMMANDS(0, caller, 0, "") #undef COMMON_COMMAND - + return; } @@ -720,10 +699,10 @@ float CommonCommand_macro_command(float argc, entity caller, string command) { #define COMMON_COMMAND(name,function,description) \ { if(name == strtolower(argv(0))) { function; return TRUE; } } - + COMMON_COMMANDS(CMD_REQUEST_COMMAND, caller, argc, command) #undef COMMON_COMMAND - + return FALSE; } @@ -731,10 +710,10 @@ float CommonCommand_macro_usage(float argc, entity caller) { #define COMMON_COMMAND(name,function,description) \ { if(name == strtolower(argv(1))) { function; return TRUE; } } - + COMMON_COMMANDS(CMD_REQUEST_USAGE, caller, argc, "") #undef COMMON_COMMAND - + return FALSE; } @@ -742,9 +721,9 @@ void CommonCommand_macro_write_aliases(float fh) { #define COMMON_COMMAND(name,function,description) \ { CMD_Write_Alias("qc_cmd_svcmd", name, description); } - + COMMON_COMMANDS(0, world, 0, "") #undef COMMON_COMMAND - + return; }