X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fcommand%2Fcommon.qc;h=6022b689a57e5a60c37c99897caf64128201bd75;hb=7c2e80951a66d9e8ba368dbdc29d45c3610c316c;hp=e117e5e09eb8319960ab1a90b8ec9e19249a61ea;hpb=a154af392071e37f22326d23eb020f27e54adc79;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index e117e5e09..6022b689a 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -58,32 +58,36 @@ float VerifyClientNumber(float tmp_number) entity GetIndexedEntity(float argc, float start_index) { entity tmp_player, selection; - float tmp_number; + float tmp_number, index; string tmp_string; next_token = -1; + index = start_index; + selection = world; if(argc > start_index) { - if(substring(argv(start_index), 0, 1) == "#") + if(substring(argv(index), 0, 1) == "#") { - tmp_string = substring(argv(start_index), 1, -1); - ++next_token; + tmp_string = substring(argv(index), 1, -1); + ++index; - if(tmp_string) // is it all one token? like #1 + if(tmp_string != "") // is it all one token? like #1 { tmp_number = stof(tmp_string); } - else if(argc > next_token) // no, it's two tokens? # 1 + else if(argc > index) // no, it's two tokens? # 1 { - tmp_number = stof(argv(next_token)); - ++next_token; + tmp_number = stof(argv(index)); + ++index; } + else + tmp_number = 0; } else // maybe it's ONLY a number? { - tmp_number = stof(argv(start_index)); - ++next_token; + tmp_number = stof(argv(index)); + ++index; } if(VerifyClientNumber(tmp_number)) @@ -92,14 +96,16 @@ entity GetIndexedEntity(float argc, float start_index) } else // no, maybe it's a name? { - next_token = (start_index + 1); - 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; } @@ -120,6 +126,7 @@ entity GetFilteredEntity(string input) } else { + selection = world; FOR_EACH_CLIENT(tmp_player) if (strdecolorize(tmp_player.netname) == strdecolorize(input)) selection = tmp_player; @@ -134,12 +141,12 @@ float GetFilteredNumber(string input) entity selection = GetFilteredEntity(input); float output; - if(selection) { output = num_for_edict(selection); } + output = num_for_edict(selection); return output; } -// switch between sprint and print depending on whether the reciever is the server or a player +// switch between sprint and print depending on whether the receiver is the server or a player void print_to(entity to, string input) { if(to) @@ -155,14 +162,9 @@ void print_to(entity to, string input) // used by CommonCommand_timeout() and CommonCommand_timein() to handle game pausing and messaging and such. void timeout_handler_reset() { - entity tmp_player; - timeout_caller = world; timeout_time = 0; timeout_leadtime = 0; - - FOR_EACH_REALPLAYER(tmp_player) - Send_CSQC_Centerprint_Generic_Expire(tmp_player, CPID_TIMEOUT_COUNTDOWN); remove(self); } @@ -177,8 +179,7 @@ void timeout_handler_think() { if(timeout_time > 0) // countdown is still going { - FOR_EACH_REALPLAYER(tmp_player) - Send_CSQC_Centerprint_Generic(tmp_player, CPID_TIMEOUT_COUNTDOWN, "Timeout ends in %d seconds!", 1, timeout_time); + Send_Notification(NOTIF_ANY, world, MSG_CENTER, CENTER_TIMEOUT_ENDING, timeout_time); if(timeout_time == autocvar_sv_timeout_resumetime) // play a warning sound when only seconds are left Announce("prepareforbattle"); @@ -205,11 +206,9 @@ void timeout_handler_think() case TIMEOUT_LEADTIME: { - if (timeout_leadtime > 0) // countdown is still going + if(timeout_leadtime > 0) // countdown is still going { - // centerprint the information to every player - FOR_EACH_REALPLAYER(tmp_player) - Send_CSQC_Centerprint_Generic(tmp_player, CPID_TIMEOUT_COUNTDOWN, "Timeout begins in %d seconds!", 1, timeout_leadtime); + Send_Notification(NOTIF_ANY, world, MSG_CENTER, CENTER_TIMEOUT_BEGINNING, timeout_leadtime); self.nextthink = time + 1; // think again in one second timeout_leadtime -= 1; // decrease the time counter @@ -295,7 +294,7 @@ void CommonCommand_cvar_purechanges(float request, entity caller) } } -void CommonCommand_info(float request, entity caller, float argc) // legacy +void CommonCommand_info(float request, entity caller, float argc) { switch(request) { @@ -381,7 +380,7 @@ void CommonCommand_lsnewmaps(float request, entity caller) } } -void CommonCommand_maplist(float request, entity caller) +void CommonCommand_printmaplist(float request, entity caller) { switch(request) { @@ -394,37 +393,13 @@ void CommonCommand_maplist(float request, entity caller) default: case CMD_REQUEST_USAGE: { - print_to(caller, strcat("\nUsage:^3 ", GetCommandPrefix(caller), " maplist")); + print_to(caller, strcat("\nUsage:^3 ", GetCommandPrefix(caller), " printmaplist")); print_to(caller, " No arguments required."); return; } } } -/* -void GameCommand_rankings(float request) // this is OLD.... jeez. -{ - switch(request) - { - case CMD_REQUEST_COMMAND: - { - strunzone(rankings_reply); - rankings_reply = strzone(getrankings()); - print(rankings_reply); - return; - } - - default: - case CMD_REQUEST_USAGE: - { - print("\nUsage:^3 sv_cmd rankings"); - print(" No arguments required."); - return; - } - } -} -*/ - void CommonCommand_rankings(float request, entity caller) { switch(request) @@ -454,7 +429,8 @@ void CommonCommand_records(float request, entity caller) float i; for(i = 0; i < 10; ++i) - print_to(caller, records_reply[i]); + if(records_reply[i] != "") + print_to(caller, records_reply[i]); return; // never fall through to usage } @@ -521,7 +497,7 @@ void CommonCommand_timein(float request, entity caller) { case CMD_REQUEST_COMMAND: { - if(autocvar_sv_timeout) + if(!caller || 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."); } @@ -535,7 +511,7 @@ void CommonCommand_timein(float request, entity caller) 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")); + bprint(strcat("^7The timeout was aborted by ", GetCallerName(caller), " !\n")); return; } @@ -543,7 +519,7 @@ void CommonCommand_timein(float request, entity caller) { timeout_time = autocvar_sv_timeout_resumetime; timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately - bprint(strcat("^1Attention: ^7", caller.netname, " resumed the game! Prepare for battle!\n")); + bprint(strcat("^1Attention: ^7", GetCallerName(caller), " resumed the game! Prepare for battle!\n")); return; } @@ -551,6 +527,8 @@ void CommonCommand_timein(float request, entity caller) } } } + else { print_to(caller, "^1Timeins are not allowed to be called, enable them with sv_timeout 1.\n"); } + return; // never fall through to usage } @@ -570,7 +548,7 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN { case CMD_REQUEST_COMMAND: { - if(autocvar_sv_timeout) + if(!caller || autocvar_sv_timeout) { float last_possible_timeout = ((autocvar_timelimit * 60) - autocvar_sv_timeout_leadtime - 1); @@ -586,7 +564,7 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN { if(caller) { caller.allowed_timeouts -= 1; } - bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(caller.allowed_timeouts), " timeout(s) left)") : string_null), "!\n"); // write a bprint who started the timeout (and how many they have left) + 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; @@ -600,6 +578,8 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN Announce("timeoutcalled"); } } + else { print_to(caller, "^1Timeouts are not allowed to be called, enable them with sv_timeout 1.\n"); } + return; // never fall through to usage } @@ -619,17 +599,18 @@ void CommonCommand_who(float request, entity caller, float argc) { case CMD_REQUEST_COMMAND: { - float total_listed_players, tmp_hours, tmp_minutes, tmp_seconds, is_bot; + 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)" : string_null), ":")); + 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 "), "ent", "nickname", "ping", "pl", "time", "ip", "crypto_id")); + total_listed_players = 0; FOR_EACH_CLIENT(tmp_player) { is_bot = (clienttype(tmp_player) == CLIENTTYPE_BOT); @@ -649,22 +630,13 @@ void CommonCommand_who(float request, entity caller, float argc) tmp_netaddress = tmp_player.netaddress; tmp_crypto_idfp = tmp_player.crypto_idfp; } - - tmp_hours = tmp_minutes = tmp_seconds = 0; - - tmp_seconds = floor(time - tmp_player.jointime); - tmp_minutes = floor(tmp_seconds / 60); - tmp_hours = floor(tmp_minutes / 60); - - if(tmp_minutes) { tmp_seconds -= (tmp_minutes * 60); } - if(tmp_hours) { tmp_minutes -= (tmp_hours * 60); } 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, - sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds), + process_time("%02d:%02d:%02d", time - tmp_player.jointime), tmp_netaddress, tmp_crypto_idfp)); @@ -722,7 +694,7 @@ void CommonCommand_(float request, entity caller) 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("maplist", CommonCommand_maplist(request, caller), "Display full server maplist reply") \ + 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") \ COMMON_COMMAND("teamstatus", CommonCommand_teamstatus(request, caller), "Show information about player and team scores") \ @@ -775,4 +747,4 @@ void CommonCommand_macro_write_aliases(float fh) #undef COMMON_COMMAND return; -} \ No newline at end of file +}