TeraProxy лет назад: 9
Родитель
Сommit
e21201c256
2 измененных файлов с 41 добавлено и 16 удалено
  1. 16 5
      README.md
  2. 25 11
      index.js

+ 16 - 5
README.md

@@ -1,5 +1,16 @@
-# AFKer
-A tera-proxy module that prevents you from getting back to the character select screen. This has the side effect that the server's AFK check won't have any effect.
-
-## Usage
-Type "!afker" in an ingame whisper chat to enable/disable.
+# AFKer
+A tera-proxy module that prevents you from getting back to the character select screen. 
+This has the side effect that the server's AFK check will not kick you out of the game.  
+  
+## Usage  
+While in game, open a whisper chat session with "!AFKer" by typing "/w !afker" in chat and hitting the space bar.
+This serves as the script's command interface. 
+The following commands are supported:  
+  
+* on - Enables the script  
+* off - Disables the script  
+  
+Any other input returns a summary of above commands in the game.
+  
+## Safety
+Whatever you send to "!AFKer" in game is intercepted client-side. The chat is NOT sent to the server.

+ 25 - 11
index.js

@@ -1,32 +1,46 @@
 module.exports = function AFKer(dispatch) {
 module.exports = function AFKer(dispatch) {
-	let enabled = false
+	let enabled = false,
+		cid = null,
+		player = ''
+		
+	dispatch.hook('S_LOGIN', 1, event => {
+		({cid} = event)
+		player = event.name
+	})
 
 
 	dispatch.hook('C_RETURN_TO_LOBBY', 1, () => {
 	dispatch.hook('C_RETURN_TO_LOBBY', 1, () => {
 		if (enabled) return false // Prevents you from being automatically logged out while AFK
 		if (enabled) return false // Prevents you from being automatically logged out while AFK
 	})
 	})
+  
+	// ################# //
+	// ### Chat Hook ### //
+	// ################# //
 	
 	
 	dispatch.hook('C_WHISPER', 1, (event) => {
 	dispatch.hook('C_WHISPER', 1, (event) => {
-		if (/^<FONT>!afker?<\/FONT>$/i.test(event.message)) {
-			if (!enabled) {
+		if(event.target.toUpperCase() === "!afker".toUpperCase()) {
+			if (/^<FONT>on?<\/FONT>$/i.test(event.message)) {
 				enabled = true
 				enabled = true
-				message('AFKer <font color="#00EE00">enabled</font>. Whisper "!afker" to disable.')
+				message('AFKer <font color="#00EE00">enabled</font>.')
 			}
 			}
-			else {
+			else if (/^<FONT>off?<\/FONT>$/i.test(event.message)) {
 				enabled = false
 				enabled = false
-				message('AFKer <font color="#DC143C">disabled</font>. Whisper "!afker" to enable.')
+				message('AFKer <font color="#DC143C">disabled</font>.')
 			}
 			}
+			else message('Commands: "on" (enable AFKer),'
+								+ ' "off" (disable AFKer)'
+						)
 			return false
 			return false
 		}
 		}
 	})
 	})
-  
+	
 	function message(msg) {
 	function message(msg) {
-		dispatch.toClient('S_CHAT', 1, {
-			channel: 24,
-			authorID: 0,
+		dispatch.toClient('S_WHISPER', 1, {
+			player: cid,
 			unk1: 0,
 			unk1: 0,
 			gm: 0,
 			gm: 0,
 			unk2: 0,
 			unk2: 0,
-			authorName: '',
+			author: '!AFKer',
+			recipient: player,
 			message: msg
 			message: msg
 		})
 		})
 	}
 	}