blob: 88b03e4d6d99117186ae016ea03213b8fe0346a2 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// master/network.c - UDP-Handling
4//
5// $Id: network.c 8934 2014-09-10 21:57:12Z Zesstra $
6
7#pragma strict_types
8
9#include "/secure/master.h"
10#define BBMASTER "/secure/bbmaster"
11
12/*
13#undef DEBUG
14#define DEBUG(x) if (call_sefun("find_player","zesstra")) \
15 tell_object(call_sefun("find_player","zesstra"),x);
16*/
17
18//ich will hieraus momentan kein Debug, ist zuviel. Zesstra
19
20#ifdef DEBUG
21#undef DEBUG
22#endif
23#define DEBUG(x)
24
25nosave int mails_last_hour;
26
27static string mail_normalize( string str )
28{
29 str = regreplace( str, "[^<]*<(.*)>[^>]*", "\\1", 0);
30 return regreplace( str, " *([^ ][^ ]*).*", "\\1", 0);
31}
32
33
34static string *mk_rec_list( string str )
35{
36 return map( explode( lower_case(str), "," ) - ({""}),
37 "mail_normalize", this_object() );
38}
39
40
41static int CheckPasswd( string name, string passwd ) {
42 mixed *uinf;
43
44 if (!stringp(passwd) || !sizeof(passwd))
45 return 0;
46 if ( sizeof(uinf = get_full_userinfo(name)) < 2 )
47 return 0;
48
49 string pwhash = uinf[USER_PASSWORD+1];
50 if (sizeof(pwhash) > 13) {
51 // MD5-Hash
52 passwd = md5_crypt(passwd, pwhash);
53 }
54 else if (sizeof(pwhash) > 2) {
55 // Crypt-Hash
56 passwd = crypt(passwd, pwhash[0..1]);
57 }
58 else return 0;
59
60 return (passwd == pwhash);
61}
62
MG Mud User88f12472016-06-24 23:31:02 +020063static void udp_query( string query, string host, int port )
64{
65#if __EFUN_DEFINED__(send_udp)
66 string *mess;
67 mixed *data;
68 int i, j;
69
70 mess = explode( query, " " );
Zesstraac1317a2019-09-27 16:14:44 +020071
MG Mud User88f12472016-06-24 23:31:02 +020072 switch ( mess[1] ){
73 case "wholist":
74 case "who":
75 data = (string *)"/obj/werliste"->QueryWhoListe();
76 break;
77
78 case "uptime":
79 data = ({ call_sefun("uptime") });
80 break;
81
82 case "finger":
83 if ( sizeof(mess) < 3 )
84 data = ({ "Error: Wen soll ich fingern ?" });
85 else
Zesstraac1317a2019-09-27 16:14:44 +020086 data = explode( "/p/daemon/finger"->
MG Mud User88f12472016-06-24 23:31:02 +020087 finger_single( lower_case(mess[2]), 0 ), "\n" );
88 break;
89
MG Mud User88f12472016-06-24 23:31:02 +020090 default:
91 data = ({ "Error: unknown request " + mess[1] + "\n" });
92 }
93
94
Zesstraac1317a2019-09-27 16:14:44 +020095 send_udp( host, port,
96 to_bytes(sprintf( "%s 0 %d", mess[0], sizeof(data)),
97 "ASCII//TRANSLIT"));
MG Mud User88f12472016-06-24 23:31:02 +020098
99 for ( i = 0, j = sizeof(data); i < j; i++ )
Zesstraac1317a2019-09-27 16:14:44 +0200100 send_udp( host, port,
101 to_bytes(sprintf( "%s %d %s", mess[0], i+1, data[i]),
102 "ASCII//TRANSLIT") );
MG Mud User88f12472016-06-24 23:31:02 +0200103#endif
104}
105
106#define UDP_DEBUG(x)
107//#define UDP_DEBUG(x) (write_file("/log/ARCH/udp.log",(x)))
108
109void receive_udp(string host, string message, int port)
110{
111 mixed *tmp;
112 UDP_DEBUG(sprintf("%s %s:%d: %s\n",strftime(),host,port,message));
113
114 if (message[0..6]=="EXTREQ:"
115 || message[0..5]=="IPNAME"
116 || message[0..3]=="AUTH"
117 ) {
118 return;
119 }
120
121 if( message[0..8]=="IPLOOKUP\n" ) {
122 "/p/daemon/iplookup"->update( message );
123 return;
124 }
125
126 if( message[0..9]=="DNSLOOKUP\n" ) {
127 "/p/daemon/dnslookup"->update( message );
128 return;
129 }
130
MG Mud User88f12472016-06-24 23:31:02 +0200131 if (message[0..9]=="udp_query:") {
132 return udp_query(message[10..],host,port);
133 }
134
135 "secure/inetd"->_receive_udp(host, message);
136}
137
138