forked from jomat/psyced
/
user.c
2111 lines (2025 loc) · 67 KB
/
user.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// $Id: user.c,v 1.547 2008/12/22 11:11:36 lynx Exp $ // vim:syntax=lpc
//
// common subclass for PSYC clients, whatever the user interface
// local debug messages - turn them on by using psyclpc -DDuser=<level>
#ifdef Duser
# undef DEBUG
# define DEBUG Duser
#endif
#include <net.h>
#include <person.h>
#include <psyc.h>
#include <uniform.h>
inherit NET_PATH "person";
inherit NET_PATH "common";
inherit NET_PATH "sockets";
#include <text.h>
//virtual inherit NET_PATH "output";
#define NO_INHERIT
#include <user.h>
#undef NO_INHERIT
volatile mixed query;
volatile mapping tags;
volatile int showEcho;
volatile mixed beQuiet;
// my nickspace. used by psyctext(). could be passed as closure, but then
// it wouldn't be available for *any* psyctext call in user objects.
uni2nick(source, vars) {
P2(("uni2nick(%O) in %O\n", source, ME))
#ifdef USE_AUTOALIAS
string ni = raliases[source];
if (ni) return ni;
if (member(raliases, source)) return UNIFORM(source); // marked dead
// ok let's do an autoalias then
string ln;
// currently only net/irc employs objects as psyctext sources
// we should either use them more aggressively or abolish them
// and have mixed case uniforms instead
if (objectp(source)) ni = source->qName();
else {
mixed u = parse_uniform(source);
// unfortunately UNick already comes lowercased..
// we should start using mixed case uniforms..
unless (u && ni = u[UNick]) {
// source is probably a server root
raliases[source] = 0; // mark dead
return source;
}
}
ln = lower_case(ni);
string al = aliases[ln];
if (al) {
if (UNIFORM(source) == UNIFORM(al)) {
// just the object of a known uniform or vice versa
raliases[source] = ni;
P2(("uni2nick: re-aliased %O to %O\n", source, al))
return ni;
}
raliases[source] = 0; // mark dead
P2(("uni2nick: already belongs to %O\n", al))
w("_failure_unavailable_alias", 0,
([ "_uniform_new": source,
"_uniform_old": al,
"_nick_old": ni ]) );
return UNIFORM(source);
}
aliases[ln] = source;
raliases[source] = ni;
P2(("uni2nick: autoaliased %O to %O\n", source, ni))
w("_notice_add_alias_temporary", 0,
([ "_uniform_entity": source,
"_nick_entity": ni ]) );
return ni;
#else
// this enables local nickspace, but it fails on local uniforms,
// it fails when local nick collides with alias, so either you make
// it super complicated here, or you keep it super stupid.
//if (objectp(n)) return n->qName();
# ifdef ALIASES
return raliases[lower_case(source)] || source;
# else
return source;
# endif
#endif
}
// jabber needs no private echo but plenty of public echo..
// net/jabber takes care of that, we just give it echo here.
// in psyc echoes are essential, so they are on.
// on irc it's better to turn them on, but you first need a
// client like irssi. for telnets and webchats you usually
// want echoes, but you can turn them off
#define ASSIGN_SHOWECHO(setting, scheme) switch(scheme) { \
case "psyc": \
case "jabber": \
showEcho = 1; \
break; \
case "irc": \
showEcho = setting == "on"; \
break; \
default: \
showEcho = setting != "off"; \
}
#include "usercmd.i"
sName(a) {
// currently this sName gets called more than once
//ASSERT("user:sName called again", !MYNICK, MYNICK)
// i don't know if this should get cleaned up TODO
unless (places) {
places = ([ ]);
tags = ([ ]); // this doesn't need an extra if, does it?
cmdchar = '/';
}
return ::sName(a);
}
qHasCurrentPlace() {
return 1;
}
qResource() {
return v("scheme");
}
#ifdef HTTP_PATH
makeToken() {
string token = sprintf("%x", random(time() ^ 98987));
P2(("%O's new %O and old %O token\n", ME, token, v("token")))
vSet("token", token);
return token;
}
validToken(token) {
P2(("token %O == given %O?\n", v("token"), token))
if (is_localhost(query_ip_number())) return 1;
if (v("token") && token != v("token")) return 0;
return 1;
}
volatile mapping descvars;
#ifndef DEFAULT_FILE_STYLE_EXAMINE
//# define DEFAULT_FILE_STYLE_EXAMINE "http://www.psyced.org/examine.css"
# define DEFAULT_FILE_STYLE_EXAMINE "/static/examine.css"
#endif
htDescription(anonymous, query, headers, qs, variant, vars) {
string k, t, page, foto, buttons, profile, nick, type;
#ifndef HTTP_PATH
int doTalk = 1;
#else
int doTalk = 0;
P3(("htDescription in %O for %O showing %O or %O\n", ME, qs, vars, descvars))
if (query) sTextPath(query["layout"] || v("layout"),
query["lang"] || v("language"), "html");
else sTextPath(v("layout"), v("language"), "html");
#endif
unless (vars) {
unless (descvars) return 0;
// vars = descvars; descvars = 0;
vars = copy(descvars); // will be modded later
// right now we do not htquote the descvars.
// seen how much creativity not quoting html can
// produce we should probably at least allow friends
// to send us html code in profiles.. whatcha think?
// then again, maybe only certain fields should be
// htmlized, otherwise psyc profiles end up heavily
// polluted by html code.. extreme solution: let
// every var have an _HTML trailed variant?!?
// or go the other way: accept html code in psyc
// profiles, but remove it when outputting to plain
// devices? that's a smart thing to say. (buy the record!)
}
// store this before we delete some vars
//doTalk = vars["_language"] || vars["_color"];
// adventurous guess.. what if a user provides this? hmm
// well it looks funny, that's all
if (stringp(nick = vars["_nick_place"])) {
type = "_place";
// used by exa() in _PAGES_start_description
vars["_nick"] = nick;
} else {
type = "_person";
nick = vars["_nick"];
}
// we could also try _identification here, or even apply inheritance
if (vars["_source"]) profile = ppl[ vars["_source"] ];
if (!profile && stringp(nick)) profile = ppl[ lower_case(nick) ];
page = listDescription(vars, 0, variant
? "<a href=\"javascript:exa('%s')\">%s</a>"
: "<a href=\"%s\">%s</a>"); // direct psyc: links!
if (anonymous) {
// anonymous profile inspection from the web
// we are rendering ourselves for somebody else
// not the other way around
} else if (type == "_place") {
// new meaning of _context used here.. ay ay ay
// we should only show one of these
buttons = T("_HTML_examine_context_enter", "")
+ T("_HTML_examine_context_leave", "");
} else {
string display = "_normal";
switch (profile && profile[PPL_DISPLAY]) {
case PPL_DISPLAY_NONE:
// this, of course, needs to happen before we use
// the "doTalk" variable
doTalk = 0;
display = "_none";
break;
case PPL_DISPLAY_SMALL:
display = "_reduce";
break;
case PPL_DISPLAY_BIG:
display = "_magnify";
break;
}
vars["_display_none"] = "";
vars["_display_reduce"] = "";
vars["_display_magnify"] = "";
vars["_display_normal"] = "";
vars["_display"+display] = "selected";
if (profile && profile[PPL_NOTIFY] >= PPL_NOTIFY_PENDING) {
buttons = T("_HTML_examine_friend_delete", "");
if (doTalk) buttons += T("_HTML_examine_talk", "");
} else {
buttons = T("_HTML_examine_friend_new", "");
if (doTalk && !FILTERED(vars["_source"]))
buttons += T("_HTML_examine_talk", "");
}
#ifdef TELEPHONY_SECRET
buttons += T("_HTML_examine_button_call", "");
#endif
buttons += T("_HTML_examine_display", "");
}
#ifndef _flag_enable_profile_table
page = T("_list_description_on", "")
+ page
+ T("_list_description_off", "");
#else
page = T("_list_description_on_table", "")
+ page
+ T("_list_description_off_table", "");
#endif
if (buttons) page = T("_HTML_examine_buttons_start", "")
+ buttons + T("_HTML_examine_buttons_end", "") + page;
if (t = vars["_uniform_photo"] || vars["_uniform_photo_small"]) {
foto = "<img class=\"Peup\" src=\""+ t +"\">";
if (vars["_page_photo"])
foto = "<a target=\"_blank\" href=\""
+ vars["_page_photo"] +"\">"+ foto +"</a>";
// foto = "<span class=\"Peup\">"+ foto +"</span>\n";
} else foto = "";
if (variant) page = "<link rel=\"stylesheet\" href=\""+
(vars["_uniform_style"] || DEFAULT_FILE_STYLE_EXAMINE)
+"\">\n"+ T("_PAGES_start_description"+ variant, "") + page
+ T("_PAGES_end_description"+ variant, "");
else {
// we send only the "body" of the page to psyc clients.
// psyczilla doesn't really need a form,
// but the formatting goes wrong if there isn't one
page = foto +"\n<form class='Pef'>\n"+ page +"</form>";
}
P4(("EXAMINE psyctext %O with %O\n", page, vars))
// <form target=cout_" CHATNAME " name=f" HTFORMOPTS "
#ifdef HTTP_PATH
sTextPath(v("layout"), v("language"), v("scheme"));
#endif
// <input type=hidden name=user value=\""+qName()+"\">\n\
// <input type=hidden name=token value=\""+v("token")+"\">\n\
// <input type=hidden name=lang value=\""+v("language")+"\">\n\
//
# ifdef _flag_enable_module_microblogging
string htchannels;
mapping channels;
if (mappingp(vars["_channels"])) channels = vars["_channels"];
else channels = parse_json(vars["_channels"]);
if (channels) {
P3((">>> channels: %O\n", channels))
htchannels =
"<script type='text/javascript'>\n"
"function selectTab(parent, id) {"
"var tabs = document.getElementById(parent);"
"var tab = tabs.firstChild;"
"while (tab) {"
"tab.className = (tab.id == parent+'-'+id) ? 'selected' : '';"
"tab = tab.nextSibling;"
"}"
"}\n"
"function switchTab(id) {"
"selectTab('tabs', id);"
"selectTab('tab-contents', id);"
"}\n"
"</script>\n";
string tabs = "";
string contents = "";
int first = 1;
object threads = clone_object(NET_PATH "place/threads");
foreach (string channel, array(mapping) entries : channels) {
unless (sizeof(entries) > 0) continue;
tabs +=
"<a id='tabs-" + channel + "' onclick=\"switchTab('" + channel + "')\" "
+ (first ? "class='selected'" : "") + ">#" + channel + "</a>\n";
contents +=
"<div id='tab-contents-" + channel + "' "
+ (first ? "class='selected'" : "") + ">" + threads->htmlEntries(entries, 1, 1, !first, channel, anonymous ? "" : vars["_identification"] + "#" + channel, vars["_profile_url"] + "/" + channel) + "</div>\n";
first = 0;
}
if (first) htchannels = "";
else htchannels +=
"<div id='tabs' class='tabs'>\n" + tabs + "</div>\n"
"<div id='tab-contents' class='tab-contents'>\n" + contents + "</div>\n";
}
# endif
return psyctext(page, vars + ([
"_FORM_start" : "\
<form class=\"Pef\" name=\"Pef\" action=\"\">\n\
<input type=\"hidden\" name=\"cmd\" value=\"\">\n\
<input type=\"hidden\" name=\"dest\" value=\"\">\n",
"_QUERY_STRING" : qs || "",
"_HTML_photo" : foto,
"_nick_me" : MYNICK,
"_FORM_end" : "</form>\n",
])
)
# ifdef _flag_enable_module_microblogging
+ htchannels
# endif
;
}
#endif
// leavePlace: extracted from _echo_place_leave handling so we can
// do it without depending on the place's answer
//
// "impatient leave" is an apparently necessary strategy:
// _ when servers crash, the UNI would not reissue a join request because
// it still sees the context in its places. this also helps with remote MUCs.
// _ the /cycle feature of some IRC clients expects no delays between direct
// subsequent PART and JOIN commands, but if psyced hasn't received leave
// confirmation yet, it used to simply ignore the JOIN.
//
// both issues could probably also be solved with glue around
// "polite leave", but it's a lot more complicated and maybe it's
// the wrong strategy anyhow.
//
protected leavePlace(where) {
P2(("%O leavePlace's %O\n", ME, where))
if (place == where) {
// current place.. psyced specific thing
place = 0;
// vDel("place"); // wrong! dann kommen die
// leute nich mehr in ihren
// letzten raum rein!
}
// leave the context slave, so we immediately stop getting
// the context's traffic even before it knows about us leaving
deregister_context(ME, where);
// after this step any castmsg from 'where' will be considered spam.
// luckily we're not in the context slave anymore.
m_delete(places, where);
}
/** PSYC-conformant message receiving function
**
** after doing basic PSYC, ppl and lastlog processing in
** person:msg() we're here to do the output..
*/
msg(source, mc, data, mapping vars, showingLog) {
string family;
mixed pal, t, variant;
int glyph;
#ifdef USE_THE_NICK
string nick, nick2;
#endif
P3(("%O user:msg(%O,%O,%O,%O)\n", ME, source, mc, data, vars))
// context checking since ip paranoia is applied to context
// not source whenever context is available..
//
// this should probably also apply for objectp sources since
// one day even they might be spoofed by a smart context..
// but right now sources are not resolved to objects
//
// also.. this belongs into person.c if it werent for the
// rplaces ... hmmm!
// Note: with context mcast we dont need this any more as we
// will only get valid contexts
if (vars["_context"]) {
if (showingLog) {
// sometimes lastlog comes with a _context which i
// need to rename here as an indicator for the final
// renderer that this is a retransmission
vars["_INTERNAL_context"] = vars["_context"];
m_delete(vars, "_context");
// unless (source) source = vars["_source_relay"];
#if DEBUG > 3
} else if (!objectp(vars["_context"]) &&
!places[vars["_context"]] &&
// !psyc_object(vars["_context"]) &&
!abbrev("_notice_place", mc)) { // just _notice_place? TODO
string ctx, chan;
// monitor_report("_warning_abuse_invalid_context",
// S("%O: Invalid context %O in %O from %O (%O)",
// ME, vars["_context"], mc, source, data));
if ((sscanf(vars["_context"], "%s#%s", ctx, chan) == 2)
&& places[ctx]) {
P2(("got valid place context %O with channel %O\n",
ctx, chan))
// a friendcast or status update
} else if (member(ppl, ctx) &&
ppl[ctx][PPL_NOTIFY] >= PPL_NOTIFY_FRIEND) {
P2(("got friendcast from %O with channel %O\n",
ctx, chan))
} else {
P1(("Invalid context %O from source %O:\n\
\t%s(%O) with %O ... stack %O ... places %O\n",
ctx, source, to_string(mc), data, vars,
caller_stack(1), places))
return 0;
}
#endif
}
unless (source) source = vars["_source_relay"] || vars["_context"];
}
// before? after?
unless (source) source = vars["_INTERNAL_source"];
// call the psyc handler in person.c
// it returns some extra info concerning display
t = source; // keep the real source before entity.c puts the UNI into it
// and here we call person::msg() without ensuring that local sources
// are objectp. this may cause problems. shouldn't we have all the
// location resolution happen BEFORE we let person act on things?
// this looks like a big TODO here.
// <fippo>: if _INTERNAL_target_resource is set, calling person::msg
// is INAPPROPRIATE. This is the current terminology of
// net/jabber, but we will have to do something similar in net/psyc
//
// Rationale: if this variable is set, we dont want the uni to
// handle this.
#ifdef PRO_PATH
unless (variant = ::msg(&source, &mc, &data, &vars, showingLog))
return 0;
if (member(vars, "_authenticated")) variant = "_important";
#else
unless (::msg(&source, &mc, &data, &vars, showingLog)) {
P3(("%O ::msg no display for %O's %O\n", ME, source, mc))
return 0;
}
variant = "";
#endif
P4(("after p:msg(%O,%O,%O,%O) -> %O\n", source,mc,data,vars, variant))
// D2(unless (showingLog) D(S("user:msg(%O,%O,%O..) -> %O\n",
// source, mc, data, variant));)
#ifdef USE_THE_NICK
nick = vars["_nick"];
#endif
#ifdef ALIASES
# ifdef BRAIN
unless (mappingp(v("aliases"))) vSet("aliases", ([]));
# endif
#endif
if (stringp(t)
#ifdef SLAVE
// we trust user if he got relayed from local room object
&&! objectp(vars["_context"])
#endif
#ifndef UNSAFE_LASTLOG
// evil scary rewrite to support changed lastlog behaviour ,)
// TODO:: watch for _source_relay||(source resp. t)
&&! (stringp(source)
&& abbrev(SERVER_UNIFORM +"~", source))
#endif
) {
#ifdef PRO_PATH
if (data && index(data, '\n') != -1)
data = replace(data, "\n", " ");
#endif
#ifdef USE_THE_NICK
if (t != source) {
if (objectp(source)) {
# ifdef ALIASES
string t2;
if (t2 = raliases[nick = source->qNameLower()]) {
nick = t2;
} else if (aliases[lower_case(nick)]) {
nick = t;
}
# else
nick = source->qName();
# endif
} else {
# ifdef ALIASES
nick = raliases[source] || source;
# else
nick = source;
# endif
}
# ifndef TRUST_PSYC_HACK
# ifdef ALIASES
} else if (raliases[source]) {
nick = raliases[source];
# endif
} else {
// short term solution (nick manager to follow)
//if (nick) nick = "("+ source + ") "+ nick;
// middle term solution
if (nick && nick != source) {
// this ensures we always escape the
// original nick, not an already escaped one
// other solution would probably be not
// to send the same vars to all users..
// eeeeh.. probably the better solution
unless (vars["_nick_verbatim"])
vars["_nick_verbatim"] = nick;
vars["_INTERNAL_nick_plain"] = nick;
// sometimes we get here with source being
// a context - that of course looks very
// stupid - how does it happen? TODO
// beQuiet is -1 exactly with those schemes
// where this nick patching habit is completely
// inappropriate. we may want to change the
// var name.
if (beQuiet != -1)
nick = psyctext(
T("_MISC_identification_remote",
"«[_source]» [_nick]"), ([
"_source":source,
"_nick":vars["_nick_verbatim"] ]));
}
else nick = stringp(source) ? source : to_string(source);
# if 0 //DEBUG > 1
// checking for validity of messages should
// happen at psyc-parsing level.. maybe? YEEEES!!
// and.. vars["_context"] is zero when showing log!
// member might help.
if (abbrev("_message", mc)) {
D("patching remote mc\n");
mc = member(vars, "_context") ?
"_message_public" : "_message_private";
}
// this just wont work.. it even breaks
// remote _message_echo_private's
# endif
# endif
}
nick2 = nick;
#endif // USE_THE_NICK
// belongs into person.c?
if (mc == "_message") mc = vars["_context"] ?
"_message_public" : "_message_private";
P3(("%O got msg(%O,%O,%O,%O)\n", ME,source,mc,data,vars))
}
#ifdef USE_THE_NICK
else if (nick && nick != MYNICK) {
# ifdef ALIASES
string tn;
// ein kleines bisschen hilflosigkeit (&&! showingLog)
//
// why are summoned_persons incarnated as users, not net/person??
// any reason? don't want to think over it, but it kinda sucks for
// aliases.. says tobij. lynX adds: well in fact with some clean
// up summoned persons could be reverted to NOT be users again.
// so please go ahead! TODO
if (raliases[tn = lower_case(nick)] &&! showingLog) {
nick2 = nick = raliases[tn];
} else if (aliases[tn] &&! showingLog) {
nick2 = nick = UNIFORM(source);
} else
# endif
nick2 = vars["_nick_stylish"] || vars["_nick_local"] || nick;
} else nick2 = nick = MYNICK;
P3(("q/n/n2: %O,%O,%O\n", MYNICK,nick,nick2))
#endif // USE_THE_NICK
t = vars && vars["_context"] || source;
#ifdef SANDBOX
unless (objectp(t) && stringp(geteuid(t)) && geteuid(t)[0] == '/') {
#else // duh. we cannot combine this, ldmud complains, might be a preprocessor
// bug or just my very own stupidity.
unless (objectp(t)) {
#endif
string rnick;
array(mixed) u;
#ifdef SANDBOX
if (objectp(t)) {
rnick = object_name(t);
rnick = rnick[rmember(rnick, '/')+1..];
if (!vars["_nick_place"]
|| stricmp(rnick, vars["_nick_place"])) {
// TODO: we shouldn't raise_error here, as we shouldn't
// allow unprivileged places to annoy users.
// what to do? enforce rnick? drop msg?
raise_error(sprintf("INVALID _nick_place in msg by %O(%O)\n",
t, rnick));
}
} else
#endif
if (stringp(t) && (rnick = (u = parse_uniform(t, 1))[UResource])
&& strlen(rnick)
&& rnick[0] == '@') {
string hnick = rnick[1..];
rnick = vars["_nick_place"];
if (!rnick || stricmp(hnick, rnick)) {
rnick = hnick;
}
vars["_nick_place"] = u[URoot] + "/@" + rnick;
}
}
// verrry similar code in psyctext()
// didn't we want to eliminate these?
// also we have the textdb with inheritance, so we could deal with
// these things in a proper way!
t = vars["_time_place"];
if (!t && showingLog) {
// _time_log is just for psyc clients: since we had to
// delete _time_INTERNAL from the psyc out, we need a
// variable for the case when this _really_ is a /log output
unless (t = vars["_time_log"]) {
if (t = vars["_time_INTERNAL"]) {
//m_delete(vars, "_time_INTERNAL");
vars["_time_log"] = t;
} else {
// sort-of impossible condition
P0(("%O got showingLog w/out _time in %O\n",
ME, vars))
}
}
P3(("%O time %O data %O from %O\n", ME, t, data, vars))
}
PSYC_TRY(mc) {
#ifndef ALPHA
case "_jabber_iq_error": // DONT reply
P2(("%O got %O", ME, mc))
break;
// TODO: add the xmlns to unsupported method format
// technisch gesehen sollten wir auch die resource
// wieder zurueckgeben an die das gesendet wurde...
// aber kriegen wir das hier?
case "_jabber_iq_get":
case "_jabber_iq_set":
sendmsg(source, "_error_unsupported_method", 0,
([ "_tag_reply" : vars["_tag"] ]));
break;
#endif
case "_jabber":
P1(("%O got %O", ME, mc))
break;
case "_notice_composing_media":
if (v("scheme") != "psyc") return 1;
break;
case "_message_video":
case "_message_audio":
// not being displayed to users other than psyc clients
if (v("scheme") != "psyc") return 1;
data = ""; // temporary for @welcome history
break;
case "_message_private_question":
variant = "_ask" + variant;
m_delete(vars, "_action");
// fall thru
case "_message": // sollte schon vorher abgefangen worden sein
mc = "_message_private";
// fall thru
case "_message_private":
// question recognition takes place on sender side
// for public talk, so it should also for private talk..
#ifdef USE_THE_NICK
#if 0
# ifdef BRAIN
P2(( "this shouldn't happen - the brain aliases bug\n" ))
unless (v("aliases")) vSet("aliases", ([]));
// for some reason v("aliases") can be undefined here
// but it never happens on my test server
# endif
if (objectp(source)) {
if (v("aliases")[nick]) { // nick collision detected!
nick = psyc_name(source);
} else {
nick = raliases[lower_case(nick)] || nick2;
// patchen in den vars.. vorsicht!
vars["_nick_long"] = vars["_nick"];
}
} else if (stringp(source)) {
nick = raliases[source] || nick2;
} else {
nick = nick2;
}
#else
nick = nick2;
#endif
#endif
#ifdef QUESTION_RECOGNITION_ON_RECEPTION
if (variant == "" && data && index(data, '?') != -1) {
// mc += "_ask";
variant = "_ask";
m_delete(vars, "_action");
break;
}
#endif
break;
case "_message_echo_private_question":
variant = "_ask" + variant;
m_delete(vars, "_action");
mc = mc[..<10];
case "_message_echo":
case "_message_echo_private":
unless (showingLog || showEcho) return 1;
#if 0 //def CAN_WE_DARE_THIS // why do we have this block at all!?
// this is the wrong way and the wrong place to create _source_relay
pal = vars["_nick_target"];
if (pal) {
if (wAction(mc, data, vars, source, variant, nick))
return 1;
#ifdef QUESTION_RECOGNITION_ON_RECEPTION
if (variant == "" && index(data, '?') != -1) {
w(mc+"_ask", data,
([ "_nick_target" : pal,
"_time_log" : vars["_time_log"],
"_source_relay" : source ]));
return 1;
}
#endif
// should have been "vars + ([" as below for public?
w(mc, data, ([ "_nick_target" : pal,
"_time_log" : vars["_time_log"],
"_source_relay" : source ]));
return 1;
}
return 0; // dont walk into _message_public if !pal
#else
break;
#endif
case "_message_public_question":
#ifndef NO_PUBLIC_QUESTIONS
variant = "_ask" + variant;
m_delete(vars, "_action");
#endif
mc = "_message_public";
// fall thru
case "_message_public":
// could theoretically move into the if, but the devil etc.
//unless (ONLINE) vInc("new");
if (source != ME) {
if (qHasCurrentPlace()) {
mixed room;
room = vars["_context"] || vars["_INTERNAL_context"];
if (room && room != place) { // && place ..not!
vSet("otherplace", room);
// rplaces will normally do the job
room = places[room] ||
(objectp(room) ? room->qName()
: to_string(room));
w((data ? "_message_public_other":
"_message_public_other_action")+variant,
data, vars + ([
#ifdef USE_THE_NICK
"_nick": nick2,
#endif
"_nick_place": room ]) );
return 1;
}
}
#ifdef USE_THE_NICK
nick = nick2;
#endif
break;
}
if (vars["_nick_local"] && MYLOWERNICK != lower_case(vars["_nick_local"])) {
// should we have special templates for this?
//mc = "_message_echo_public_masquerade";
#ifdef USE_THE_NICK
nick = vars["_nick_local"];
#endif
// or should we rather make sure that all clients
// learn to detect echo themselves, since future
// multicast routing may not give us the possibility
// to patch methods on the way to the client
// like we do here:
} else mc = "_message_echo_public";
// fall through for echoes coming from rooms
case "_message_echo_public":
unless (showingLog || showEcho || vars["_INTERNAL_force_echo"])
return 1;
break;
case "_message_announcement":
case "_message_behaviour_warning":
case "_message_behaviour_punishment":
case "_message_behaviour":
case "_message_twitter":
unless (stringp(data)) variant = "_default";
else variant = "";
#ifdef USE_THE_NICK
nick = nick2;
// fmt = nick ? "%s announces: %s\n"
// : "*** Announcement: %s ***\n";
#endif
break;
case "_request_message_public_question":
case "_request_message":
mc = "_request_message_public";
case "_request_message_public":
break;
case "_request_description":
// if (source == ME) return 1;
return 1;
case "_status_description":
case "_status_description_person":
case "_status_description_place":
P4(("x-ret %O\n", vars))
if (vars["_tag_reply"]) {
sscanf(vars["_tag_reply"], "%s %s", variant, t);
//PT(("format %O tag %O\n", variant, t))
descvars = vars;
descvars["_source"] = source;
switch (variant) {
default:
// client doesn't want HTML
if (sizeof(v("locations")[0])) sendmsg(m_indices(v("locations")[0])[0],
mc, data, ([
"_tag_reply": t,
"_source_relay": source,
"_uniform_style": vars["_uniform_style"]
]) + vars);
return 1;
case "_HTML":
// client wants HTML
if (sizeof(v("locations")[0])) sendmsg(m_indices(v("locations")[0])[0],
mc+"_HTML", htDescription(), ([
"_type_data": "text/html",
"_tag_reply": t,
"_source_relay": source,
"_uniform_style": vars["_uniform_style"]
]));
return 1;
case "_surf":
// we're doing a /surf, so stop here
return 1;
case "0":
case 0:
// fall thru to manual examine
}
}
// internal transformation of a single msg into a list of msgs
// hmmm.. well, that's how psyc to client happens here
mc = "_list"+ mc[7..];
w(mc+"_on", data, ([ // used by irc whois..
"_source_relay": source, "_tag_reply": t,
"_nick" : vars["_nick"] || vars["_nick_place"],
"_name_public" : vars["_name_public"] || "",
"_action_motto" : vars["_action_motto"] || "",
"_description_motto" : vars["_description_motto"] || ""
]));
listDescription(vars, 1);
w(mc+"_off", 0, ([
"_source_relay": source, "_tag_reply": t,
"_nick" : vars["_nick"] ]));
return 1;
case "_status_place_members_none_automatic":
if (beQuiet != -1) {
PT(("%O skipping %O from %O\n", ME, mc, source))
return 1;
}
break;
case "_status_place_members_automatic":
if (beQuiet != -1) {
PT(("%O skipping %O from %O\n", ME, mc, source))
return 1;
}
// fall thru
case "_status_place_members":
#ifdef PARANOID
//unless (pointerp(vars["_list_members"])) break;
// t = implode(renderMembers(vars["_list_members"],
// vars["_list_members_nicks"], objectp(source)), ", ");
if (stringp(t = vars["_list_members"])) { // _tab
vars["_list_members"] = ({ t });
} else unless (pointerp(vars["_list_members"])) break;
if (stringp(t = vars["_list_members_nicks"])) {
vars["_list_members_nicks"] = ({ t });
} // no else break here by intention, renderMembers() won't be
// scared by that.
#endif
// same code in _echo_place_enter etc.
// renderMembers is also useful for psyc clients
vars["_list_members_nicks"] =
renderMembers(vars["_list_members"],
vars["_list_members_nicks"], objectp(source));
break;
// if (v("verbatimuniform") == "on")
// t = replace(t, "@", "%");
// w(mc, "In [_nick_place]: [_list_members_nicks]", ([
// "_nick_place" : vars["_nick_place"],
// "_list_members_nicks" : t ]) );
// irc-thang: w(mc + "_end", 0, vars);
// return 1;
#ifdef TELEPHONY_SECRET
# include <sys/tls.h>
case "_notice_answer_call_click":
case "_notice_answer_call":
t = vars["_time_expire"];
if (to_int(t) < time()) {
P1(("Expired phone call for %O from %O: %O\n",
ME, source, t))
return 1; // call expired
}
string t2, t3;
t2 = "?thats=me&user="+ MYNICK +"&expiry="+ t +"&jack="+
(t3 = hmac(TLS_HASH_SHA256, TELEPHONY_SECRET,
"I"+ t +":"+ MYNICK));
P1(("hmac/call %O for %O\n", t3, "I"+t+":"+MYNICK))
t3 = NET_PATH "http/call"->make_session(MYNICK, to_int(t), t3);
w("_notice_answer_call_link", 0, ([
"_page_call": (
#ifdef __TLS__
(tls_available() && HTTPS_URL) ||
#endif
HTTP_URL) + NET_PATH +"http/call?thats=me&sid=" +t3,
# ifdef TELEPHONY_SERVER
"_uniform_call": TELEPHONY_SERVER + t2,
# endif
]));
return 1;
#endif
case "_notice_received_email":
case "_notice_email_received":
if (stringp(vars["_origin"])) vars["_origin"] =
decode_embedded_charset(vars["_origin"]);
if (stringp(vars["_subject"])) vars["_subject"] =
decode_embedded_charset(vars["_subject"]);
break;
case "_notice_presence_here_quiet":
mc = mc[..<7]; // _quiet is just internal
// humm.. not since i started using it for CACHE_PRESENCE
// problem? should i use _request_friend_present instead?
// fall thru
case "_notice_presence":
case "_status_presence":
break;
case "_notice_person_absent_netburp":
if (vars["_context"] != place) return 1;
break;
case "_failure_unsuccessful_delivery":
case "_failure_network_connect_invalid_port":
// is this the right place to do this? i have seen a recursion where
// person.c was never asked for opinion, so i'm putting this into user.c
#if 0 //def ALPHA
string loc;
foreach (t, loc : v("locations")) {
if (member(loc, vars["_source_relay"])) {
P1(("%O in %O talking to its %O location at %O.",
mc, ME, t, loc))
sLocation(t, 0);
}
}
#else
foreach (string type, mapping locs : v("locations")) {
if (member(locs, vars["_source_relay"])) {
P0(("%O got %O, deleting %O from %O\n", ME, mc, vars["_source_relay"], v("locations")))
m_delete(locs, vars["_source_relay"]);
unless (sizeof(locs)) m_delete(v("locations"), type);
}
}
P4(("locations left: %O\n", v("locations")))
#endif
// fall thru - not strictly necessary but adds a feature
case "_failure_redirect_permanent":
// we currently have no implementation for permanent changes
case "_failure_redirect_temporary":
case "_failure_redirect":
// current policy: we trust local senders to do this