blob: 10beccb6a40bd05d08cea13d58a75fed0c80c942 [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, " " );
71
72 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
86 data = explode( (string)"p/daemon/finger"->
87 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
95 send_udp( host, port, sprintf( "%s 0 %d", mess[0], sizeof(data) ) );
96
97 for ( i = 0, j = sizeof(data); i < j; i++ )
98 send_udp( host, port, sprintf( "%s %d %s", mess[0], i+1, data[i] ) );
99#endif
100}
101
102#define UDP_DEBUG(x)
103//#define UDP_DEBUG(x) (write_file("/log/ARCH/udp.log",(x)))
104
105void receive_udp(string host, string message, int port)
106{
107 mixed *tmp;
108 UDP_DEBUG(sprintf("%s %s:%d: %s\n",strftime(),host,port,message));
109
110 if (message[0..6]=="EXTREQ:"
111 || message[0..5]=="IPNAME"
112 || message[0..3]=="AUTH"
113 ) {
114 return;
115 }
116
117 if( message[0..8]=="IPLOOKUP\n" ) {
118 "/p/daemon/iplookup"->update( message );
119 return;
120 }
121
122 if( message[0..9]=="DNSLOOKUP\n" ) {
123 "/p/daemon/dnslookup"->update( message );
124 return;
125 }
126
MG Mud User88f12472016-06-24 23:31:02 +0200127 if (message[0..9]=="udp_query:") {
128 return udp_query(message[10..],host,port);
129 }
130
131 "secure/inetd"->_receive_udp(host, message);
132}
133
134