From c8d4b89b3de0e8db730fbd375c5b4abd38ac6dff Mon Sep 17 00:00:00 2001 From: skotlex Date: Tue, 1 Aug 2006 17:59:34 +0000 Subject: - Cleaned up some more the SC_JAILED code - merged in atcommands jailfor, jailtime, charjailtime. Thanks to Meruru and Coltaro for the code. - Cleaned the code of atcommnds jail and unjail - Be warned that the code MAY contain bugs as I adjusted it to save the character's position before jailing, allowing the automatic unjailing to warp you back to the exact spot you were at before being jailed. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@8038 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 307 +++++++++++++++++++++++++++++++++++++++++++++------- src/map/atcommand.h | 3 + src/map/status.c | 22 ++-- 3 files changed, 287 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 9bbec8c1d..667b89ff1 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -166,6 +166,9 @@ ACMD_FUNC(servertime); // by Yor ACMD_FUNC(chardelitem); // by Yor ACMD_FUNC(jail); // by Yor ACMD_FUNC(unjail); // by Yor +ACMD_FUNC(jailfor); // Alias Meruru +ACMD_FUNC(jailtime); // Coltaro +ACMD_FUNC(charjailtime); // Coltaro ACMD_FUNC(disguise); // [Valaris] ACMD_FUNC(undisguise); // by Yor ACMD_FUNC(chardisguise); // Kalaspuff @@ -482,6 +485,9 @@ static AtCommandInfo atcommand_info[] = { { AtCommand_Jail, "@jail", 60, atcommand_jail }, // by Yor { AtCommand_UnJail, "@unjail", 60, atcommand_unjail }, // by Yor { AtCommand_UnJail, "@discharge", 60, atcommand_unjail }, // by Yor + { AtCommand_JailFor, "@jailfor", 20, atcommand_jailfor }, //Meruru + { AtCommand_JailTime, "@jailtime", 1, atcommand_jailtime }, //Change this to 0 in atcommand_conf.txt if you want it accessible to players (you most likely will ;)) + { AtCommand_CharJailTime, "@charjailtime", 20, atcommand_charjailtime }, { AtCommand_Disguise, "@disguise", 20, atcommand_disguise }, // [Valaris] { AtCommand_UnDisguise, "@undisguise", 20, atcommand_undisguise }, // by Yor { AtCommand_CharDisguise, "@chardisguise", 60, atcommand_chardisguise }, // Kalaspuff @@ -6358,6 +6364,33 @@ int atcommand_chardelitem(const int fd, struct map_session_data* sd, return 0; } +//Added by Coltaro +//We're using this function here instead of using time_t so that it only counts player's jail time when he/she's online (and since the idea is to reduce the amount of minutes one by one in status_change_timer...). +//Well, using time_t could still work but for some reason that looks like more coding x_x +static void get_jail_time(int jailtime, int* year, int* month, int* day, int* hour, int* minute) { + const int factor_year = 518400; //12*30*24*60 = 518400 + const int factor_month = 43200; //30*24*60 = 43200 + const int factor_day = 1440; //24*60 = 1440 + const int factor_hour = 60; + + *year = jailtime/factor_year; + jailtime -= *year*factor_year; + *month = jailtime/factor_month; + jailtime -= *month*factor_month; + *day = jailtime/factor_day; + jailtime -= *day*factor_day; + *hour = jailtime/factor_hour; + jailtime -= *hour*factor_hour; + *minute = jailtime; + + *year = *year > 0? *year : 0; + *month = *month > 0? *month : 0; + *day = *day > 0? *day : 0; + *hour = *hour > 0? *hour : 0; + *minute = *minute > 0? *minute : 0; + return; +} + /*========================================== * @jail by [Yor] * Special warp! No check with nowarp and nowarpto flag @@ -6379,36 +6412,43 @@ int atcommand_jail( return -1; } - if ((pl_sd = map_nick2sd(atcmd_player_name)) != NULL) { - if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can jail only lower or same GM - switch(rand() % 2) { - case 0: - x = 24; - y = 75; - break; - default: - x = 49; - y = 75; - break; - } - m_index = mapindex_name2id(MAP_JAIL); - if (pc_setpos(pl_sd, m_index, x, y, 3) == 0) { - pc_setsavepoint(pl_sd, m_index, x, y); // Save Char Respawn Point in the jail room [Lupus] - clif_displaymessage(pl_sd->fd, msg_table[117]); // GM has send you in jails. - clif_displaymessage(fd, msg_table[118]); // Player warped in jails. - } else { - clif_displaymessage(fd, msg_table[1]); // Map not found. - return -1; - } - } else { - clif_displaymessage(fd, msg_table[81]); // Your GM level don't authorise you to do this action on this player. - return -1; - } - } else { + if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) { clif_displaymessage(fd, msg_table[3]); // Character not found. return -1; } + if (pc_isGM(sd) < pc_isGM(pl_sd)) + { // you can jail only lower or same GM + clif_displaymessage(fd, msg_table[81]); // Your GM level don't authorise you to do this action on this player. + return -1; + } + + if (pl_sd->mapindex == mapindex_name2id(MAP_JAIL)) + { //Already jailed + clif_displaymessage(fd, msg_table[118]); // Player warped in jails. + return -1; + } + + switch(rand() % 2) { //Jail Locations + case 0: + m_index = mapindex_name2id(MAP_JAIL); + x = 24; + y = 75; + break; + default: + m_index = mapindex_name2id(MAP_JAIL); + x = 49; + y = 75; + break; + } + if (pc_setpos(pl_sd, m_index, x, y, 3)) { + clif_displaymessage(fd, msg_table[1]); // Map not found. + return -1; + } + + pc_setsavepoint(pl_sd, m_index, x, y); // Save Char Respawn Point in the jail room [Lupus] + clif_displaymessage(pl_sd->fd, msg_table[117]); // GM has send you in jails. + clif_displaymessage(fd, msg_table[118]); // Player warped in jails. return 0; } @@ -6423,6 +6463,7 @@ int atcommand_unjail( { struct map_session_data *pl_sd; unsigned short m_index; + int x=0, y=0; memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); @@ -6431,26 +6472,218 @@ int atcommand_unjail( return -1; } + if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) { + clif_displaymessage(fd, msg_table[3]); // Character not found. + return -1; + } + + if (pc_isGM(sd) < pc_isGM(pl_sd)) { // you can jail only lower or same GM + + clif_displaymessage(fd, msg_table[81]); // Your GM level don't authorise you to do this action on this player. + return -1; + } + + m_index = mapindex_name2id(MAP_JAIL); + + if (pl_sd->mapindex != m_index) { + clif_displaymessage(fd, msg_table[119]); // This player is not in jails. + return -1; + } + + if (pl_sd->sc.count && pl_sd->sc.data[SC_JAILED].timer != -1) + { //Retrieve return map. + m_index = pl_sd->sc.data[SC_JAILED].val3; + x = pl_sd->sc.data[SC_JAILED].val4&0xFFFF; + y = pl_sd->sc.data[SC_JAILED].val4>>16; + status_change_end(&pl_sd->bl,SC_JAILED,-1); + } + + if (pc_setpos(pl_sd, m_index, x, y, 3) == 0 || + pc_setpos(pl_sd, mapindex_name2id(MAP_PRONTERA), 0, 0, 3) == 0 + ) { //Send to Prontera is saved SC map fails. + pc_setsavepoint(pl_sd, m_index, x, y); + clif_displaymessage(pl_sd->fd, msg_table[120]); // GM has discharge you. + clif_displaymessage(fd, msg_table[121]); // Player unjailed. + } else { + clif_displaymessage(fd, msg_table[1]); // Map not found. + return -1; + } + return 0; +} + +int atcommand_jailfor( + const int fd, struct map_session_data* sd, + const char* command, const char* message) +{ + struct map_session_data *pl_sd = NULL; + int year, month, day, hour, minute, value; + char * modif_p; + int jailtime = 0,x,y; + short m_index = 0; + nullpo_retr(-1, sd); + + if (!message || !*message || sscanf(message, "%s %99[^\n]",atcmd_output,atcmd_player_name) < 2) { + clif_displaymessage(fd, msg_table[400]); //Usage: @jailfor