Browse Source

* Applied suggestion in tid:76925. Added script command checkidle.
- Idle timer now resets when player sits/stands.
- Idle timer resets when sending a chat message (global, main, guild, party, or battleground).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@17126 54d463be-8e91-2dee-dedb-b68131a5f0ec

aleos 12 years ago
parent
commit
634ba6516a
2 changed files with 36 additions and 0 deletions
  1. 18 0
      src/map/clif.c
  2. 18 0
      src/map/script.c

+ 18 - 0
src/map/clif.c

@@ -9695,6 +9695,9 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
 	map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
 #endif
 
+	// Reset idle time when using normal chat.
+	sd->idletime = last_tick;
+
 	// Chat logging type 'O' / Global Chat
 	log_chat(LOG_CHAT_GLOBAL, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
 }
@@ -9887,6 +9890,7 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type,
 		)) //No sitting during these states either.
 			break;
 
+		sd->idletime = last_tick;
 		pc_setsit(sd);
 		skill_sit(sd,1);
 		clif_sitting(&sd->bl);
@@ -9897,6 +9901,8 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type,
 			clif_standing(&sd->bl);
 			return;
 		}
+
+		sd->idletime = last_tick;
 		pc_setstand(sd);
 		skill_sit(sd,0);
 		clif_standing(&sd->bl);
@@ -9978,6 +9984,9 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
 		sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
 	}
 
+	// Reset idle time when using whisper/main chat.
+	sd->idletime = last_tick;
+
 	// Chat logging type 'W' / Whisper
 	log_chat(LOG_CHAT_WHISPER, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
 
@@ -11642,6 +11651,9 @@ void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
 		sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
 	}
 
+	// Reset idle time when using party chat.
+	sd->idletime = last_tick;
+
 	party_send_message(sd, text, textlen);
 }
 
@@ -12177,6 +12189,9 @@ void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
 		sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
 	}
 
+	// Reset idle time when using guild chat.
+	sd->idletime = last_tick;
+
 	if( sd->bg_id )
 		bg_send_message(sd, text, textlen);
 	else
@@ -15097,6 +15112,9 @@ void clif_parse_BattleChat(int fd, struct map_session_data* sd)
 		sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
 	}
 
+	// Reset idle time when using battleground chat.
+	sd->idletime = last_tick;
+
 	bg_send_message(sd, text, textlen);
 }
 

+ 18 - 0
src/map/script.c

@@ -14965,6 +14965,23 @@ BUILDIN_FUNC(checkchatting) // check chatting [Marka]
 	return 0;
 }
 
+BUILDIN_FUNC(checkidle)
+{
+	TBL_PC *sd = NULL;
+
+	if (script_hasdata(st, 2))
+		sd = map_nick2sd(script_getstr(st, 2));
+	else
+		sd = script_rid2sd(st);
+
+	if (sd)
+		script_pushint(st, DIFF_TICK(last_tick, sd->idletime));
+	else
+		script_pushint(st, 0);
+
+	return 0;
+}
+
 BUILDIN_FUNC(searchitem)
 {
 	struct script_data* data = script_getdata(st, 2);
@@ -17686,6 +17703,7 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(roclass,"i?"),	//[Skotlex]
 	BUILDIN_DEF(checkvending,"?"),
 	BUILDIN_DEF(checkchatting,"?"),
+	BUILDIN_DEF(checkidle,"?"),
 	BUILDIN_DEF(openmail,""),
 	BUILDIN_DEF(openauction,""),
 	BUILDIN_DEF(checkcell,"siii"),