[DGD] Terminal Detect

pete at ana.sk pete at ana.sk
Tue Apr 2 09:26:35 CEST 2002


On 29 Mar 2002, at 21:51, bkennedyjr at mindspring.com wrote:

> Is there a way for DGD to detect what terminal type a  user is using?  I would
> like to be able to automatically set certain events according to the terminal
> type of the player.

This is something very similar, it handles telnet NAWS, and it looks to be 
working well for me. If you need to detect termnal type just look into telnet 
control codes docs and modify, should not be any problem.

(See attachment)

Pete


-------------- next part --------------
diff -urN dgd/mud/kernel/lib/connection.c dgd-my/mud/kernel/lib/connection.c
--- dgd/mud/kernel/lib/connection.c	Wed Nov  1 00:44:53 2000
+++ dgd-my/mud/kernel/lib/connection.c	Sat Jul 21 10:58:14 2001
@@ -7,6 +7,7 @@
 private int mode;		/* connection mode */
 private int blocked;		/* connection blocked? */
 private string buffer;		/* buffered output string */
+private int window_size;	/* telnet window size, low word is width, high word is heigh */

 /*
  * NAME:	create()
@@ -17,6 +18,7 @@
     userd = find_object(USERD);
     conntype = type;
     mode = MODE_ECHO;	/* same as MODE_LINE for binary connection */
+    window_size = 80 + 25 * 0x10000;	/* default window is 80x25 */
 }


@@ -287,3 +289,23 @@
     }
 }
 # endif
+
+/*
+ * NAME:	set_window()
+ * DESCRIPTION:	set size of telnet window
+ */
+static void set_window(mixed *tls, int width, int height)
+{
+    if(width > 0 && height > 0) {
+	window_size = height * 0x10000 + width % 0x10000;
+    }
+}
+
+/*
+ * NAME:	query_window()
+ * DESCRIPTION:	return size of telnet window as int, low word is width, high word is heigh
+ */
+int query_window()
+{
+    return window_size;
+}
diff -urN dgd/mud/kernel/obj/telnet.c dgd-my/mud/kernel/obj/telnet.c
--- dgd/mud/kernel/obj/telnet.c	Tue Nov 16 15:56:46 1999
+++ dgd-my/mud/kernel/obj/telnet.c	Sat Jul 21 10:24:41 2001
@@ -72,3 +72,12 @@
 {
     ::message_done(allocate(driver->query_tls_size()));
 }
+
+/*
+ * NAME:	set_window()
+ * DESCRIPTION:	set telnet window size
+ */
+static void set_window(int width, int height)
+{
+    ::set_window(allocate(driver->query_tls_size()), width, height);
+}
diff -urN dgd/src/comm.c dgd-my/src/comm.c
--- dgd/src/comm.c	Sat Jul 21 11:20:39 2001
+++ dgd-my/src/comm.c	Sat Jul 21 10:17:49 2001
@@ -138,7 +138,8 @@
 bool telnet;
 {
     static char init[] = { (char) IAC, (char) WONT, (char) TELOPT_ECHO,
-			   (char) IAC, (char) DO,   (char) TELOPT_LINEMODE };
+			   (char) IAC, (char) DO,   (char) TELOPT_LINEMODE,
+			   (char) IAC, (char) DO,   (char) TELOPT_NAWS };
     register user *usr;
     dataspace *data;
     array *arr;
@@ -914,6 +915,18 @@
 			break;

 		    case TS_SB:
+			if (UCHAR(*p) == TELOPT_NAWS && n >= 5) {
+			    PUSH_INTVAL(f, p[1] * 256 + p[2]);
+			    PUSH_INTVAL(f, p[3] * 256 + p[4]);
+			    this_user = obj->index;
+			    if (i_call(f, obj, (array *) NULL, "set_window", 10, TRUE, 2)) {
+				i_del_value(f->sp++);
+				endthread();
+			    }
+			    this_user = OBJ_NONE;
+			    p += 5;
+			    n -= 5;
+			}
 			/* skip to the end */
 			if (UCHAR(*p) == IAC) {
 			    state = TS_SE;
diff -urN dgd/src/host/telnet.h dgd-my/src/host/telnet.h
--- dgd/src/host/telnet.h	Mon Nov 13 04:44:48 1995
+++ dgd-my/src/host/telnet.h	Fri Jul 20 18:30:31 2001
@@ -18,3 +18,4 @@
 # define TELOPT_ECHO	1	/* echo */
 # define TELOPT_SGA	3	/* suppress go ahead */
 # define TELOPT_TM	6	/* timing mark */
+# define TELOPT_NAWS	31	/* window size */
  


More information about the DGD mailing list