blob: b7490724ae023e23558371a604b4e331879b0dd2 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001/* rumatas twitter client, sendet text
2 * an einen twitterproxyprozess, der sie dann an twitter
3 * weiterschickt.
4 *
5 * version 2
6 * mit persistenter verbindung zum proxy und input-channel
7 *
8 * 25.5.2016 rumata@mg.mud.de
9 */
Zesstracc470b22020-01-08 20:33:12 +010010#pragma no_clone
MG Mud User88f12472016-06-24 23:31:02 +020011
12#include <wizlevels.h>
13#include <daemon/channel.h>
14
15#define HOST "127.0.0.1"
16#define PORT 4911
17
18#define DEBUG(x) tell_object(find_player("rumata"),x+"\n")
19
Zesstra39d1d2b2020-09-28 23:53:04 +020020nosave variables inherit "/std/channel_supervisor";
21
22protected void create() {
23 ::create();
24 ch_read_init_file();
25 seteuid(getuid());
Zesstraf126b342020-01-09 20:43:42 +010026 CHMASTER->join("twitter",this_object());
MG Mud User88f12472016-06-24 23:31:02 +020027}
28
29object caller;
30string msgbuf;
31
Zesstracc470b22020-01-08 20:33:12 +010032// Explizit erlaubte Personen/UIDs mit ihren Kuerzeln
MG Mud User88f12472016-06-24 23:31:02 +020033mapping registered = ([
34 "rumata": "ru",
35 "arathorn": "ara",
36 "ark": "ark",
37 "zesstra": "ze",
38 "zook": "zo",
39 "humni": "hu",
40 "miril": "mi",
Rumata20088402019-12-06 10:59:22 +010041 "gloinson": "gl",
Zesstracc470b22020-01-08 20:33:12 +010042 "amaryllis": "ama",
Zesstra754bb3b2020-01-08 21:27:33 +010043 "zaphob": "zap",
MG Mud User88f12472016-06-24 23:31:02 +020044]);
45
Zesstra3a62b412020-01-08 20:11:27 +010046// Erlaubt sind EM+ und ausgewaehlte weitere Personen
Zesstracc470b22020-01-08 20:33:12 +010047// geprueft wird anhand der UID des Interactives und weiterhin, dass alle
48// Objekte in der Aufrufkette mindestens ein gleich grosses Level haben wie
49// der Interactive.
MG Mud User88f12472016-06-24 23:31:02 +020050int allowed() {
Zesstra3a62b412020-01-08 20:11:27 +010051 return ARCH_SECURITY
Zesstra6af05952020-01-08 22:10:38 +010052 || ( this_interactive()
53 && member(registered, getuid(this_interactive()))
Zesstra439355e2020-01-08 21:17:16 +010054 && secure_level() >= (query_wiz_level(geteuid(this_interactive())))
Zesstracc470b22020-01-08 20:33:12 +010055 ) ;
56}
Zesstracc470b22020-01-08 20:33:12 +010057// Wer darf das Tool bekommen/nutzen?
58// Alle oben eingetragenen UIDs.
59public int tool_allowed(object pl)
60{
61 return IS_ARCH(pl) || member(registered, getuid(pl));
MG Mud User88f12472016-06-24 23:31:02 +020062}
63
64string sig( object pl ) {
65 string uid = getuid(pl);
66 if( !uid ) return "??";
67 string abbr = registered[uid];
68 if( !abbr ) return uid;
69 return abbr;
70}
71
72void emit( string msg ) {
73 CHMASTER->send("twitter",this_object(),msg,MSG_SAY);
74 /*
75 foreach( string uid: m_indices(registered) ) {
76 object pl = find_player(uid);
77 if( pl ) tell_object(pl,msg);
78 }*/
79}
80
81/* Offizielle API funktion
82 * xeval "/secure/misc/twitter"->twitter("@_zesstra_ welcome back")
83 */
84void twitter(string msg) {
85 int err = 0;
86 if( !allowed() ) {
Zesstra997a31d2020-01-08 20:17:40 +010087 write( "Twitter ist ARCH+Berechtigte only.\n" );
MG Mud User88f12472016-06-24 23:31:02 +020088 return;
89 }
Zesstra997a31d2020-01-08 20:17:40 +010090 msg = msg + "^" + sig(this_interactive()) + "\n";
Zesstra81610f12020-04-04 15:21:58 +020091 if (sizeof(msg) > 279)
92 write("Tweet ist zu lang.\n");
93 if(interactive(this_object())) {
MG Mud User88f12472016-06-24 23:31:02 +020094 tell_object(this_object(),msg);
95 } else {
96 msgbuf = msg;
Zesstra997a31d2020-01-08 20:17:40 +010097 caller = this_interactive();
MG Mud User88f12472016-06-24 23:31:02 +020098 if( (err=net_connect(HOST,PORT))!=0 ) {
99 write( "Konnte Tweet nicht senden. err="+err+"\n" );
100 }
101 }
102}
103
104// sonderfunktion fuer den fall, dass man die verbindung
105// aufbauen will, ohne dass etwas auf twitter erscheint
106void connect() {
107 int err = 0;
108 if( interactive(this_object()) ) return;
109 msgbuf = "";
Zesstra997a31d2020-01-08 20:17:40 +0100110 caller = this_interactive();
MG Mud User88f12472016-06-24 23:31:02 +0200111 if( (err=net_connect(HOST,PORT))!=0 ) {
112 write( "Konnte Tweet nicht connected. err="+err+"\n" );
113 }
114}
115
116varargs void logon(int flag) {
117 if( flag<0 ) {
118 tell_object(caller,"Twitterproxy antwortet nicht?\n");
119 } else {
120 enable_commands();
121 add_action("input","",1);
122 write(msgbuf);
123 if( msgbuf!="" ) emit( msgbuf );
124 //"/secure/master"->disconnect(this_object());
125 }
126}
127
128void NetDead() {
129 disable_commands();
130}
131
132string query_real_name() {
133 return "(Twitter)";
134}
135
Zesstra39d1d2b2020-09-28 23:53:04 +0200136varargs string name( int casus, int demon ) {
137 return "twitter";
138}
139
MG Mud User88f12472016-06-24 23:31:02 +0200140varargs string Name( int casus, int demon ) {
141 return "Twitter";
142}
143
144// daten werden via tell_object an dieses objekt gesendet
145// und dann nach aussen weitergeben
146void catch_tell( string msg ) {
147 if( allowed() && interactive(this_object()) ) {
148 write( msg );
149 }
150}
151
152// hier landen daten von aussen
153int input( string s ) {
154 string msg = query_verb();
155 if( s ) msg = msg + " " + s;
156 emit( msg ); //"Twitter teilt dir mit: "+msg+"\n" );
157 return 1;
158}
159