use qName() for objectp sources

This commit is contained in:
psyc://psyced.org/~lynX 2009-03-04 12:21:53 +01:00
parent 6fd2423ff9
commit b704cedfd1
5 changed files with 89 additions and 50 deletions

View File

@ -10,7 +10,7 @@
#ifdef BRAIN #ifdef BRAIN
//# define ON_ANY if (mayLog(mc)) mymsg(source, mc, data, vars); //# define ON_ANY if (mayLog(mc)) mymsg(source, mc, data, vars);
//# define ALLOW_EXTERNAL_FROM "psyc://fly.symlyn" //# define ALLOW_EXTERNAL_FROM "psyc://fly.symlyn"
//# define ALLOW_EXTERNAL # define ALLOW_EXTERNAL
#else #else
//# define CONNECT_DEFAULT //# define CONNECT_DEFAULT
# define REDIRECT "psyc://psyced.org/@welcome" # define REDIRECT "psyc://psyced.org/@welcome"
@ -18,7 +18,7 @@
#include <place.gen> #include <place.gen>
#ifdef BRAIN #if 0 // def BRAIN
// it was a bad idea anyway.. you don't wanna autorelease thru cvs.. // it was a bad idea anyway.. you don't wanna autorelease thru cvs..
#if 0 #if 0
mymsg(source, mc, data, vars) { mymsg(source, mc, data, vars) {

View File

@ -1,4 +1,12 @@
// vim:syntax=lpc // vim:syntax=lpc
//
// still fails in some unusual cases, like
// "Comments? Suggestions? Submissions? Fire away!"
#define ON_CONVERSE \
if (stringp(data)) data = zwirbel(0, data); \
walk_mapping(vars, #'zwirbel);
#include <place.gen> #include <place.gen>
mixed* randomize(mixed* abs) { mixed* randomize(mixed* abs) {
@ -36,7 +44,8 @@ mixed zwirbel(mixed name, mixed data) {
string* words; string* words;
int c = 0; int c = 0;
if (!stringp(data) || strlen(data) >= 3 || name == "_nick") return data; if (!stringp(data) || strlen(data) < 5
|| name == "_nick" || name == "_color") return data;
words = explode(data, " "); words = explode(data, " ");
foreach (string w : words) { foreach (string w : words) {
// hier nochmal nach irgendwelchen satzzeichen am ende gucken // hier nochmal nach irgendwelchen satzzeichen am ende gucken
@ -47,18 +56,9 @@ mixed zwirbel(mixed name, mixed data) {
} }
c++; c++;
} }
return data = implode(words, " "); data = implode(words, " ");
} //debug_message(sprintf("%O - %O\n", ME, data));
return data;
msg(source, mc, data, mapping vars) {
// normally we would check for _message but we're being nasty here
//if (stringp(data) && abbrev("_message", mc)) {
if (stringp(data)) {
data = zwirbel(0, data);
}
// even worse.. we fuck up the vars as well..
walk_mapping(vars, #'zwirbel);
return ::msg(source, mc, data, vars);
} }
htget(prot, query, headers, qs) { htget(prot, query, headers, qs) {

View File

@ -91,8 +91,8 @@ varargs array(mixed) parse_uniform(string url, vaint tolerant) {
u[UHost] = t; u[UHost] = t;
P4(("parse_uniform %s = %O (tolerant: %O)\n", url, u, tolerant)) P4(("parse_uniform %s = %O (tolerant: %O)\n", url, u, tolerant))
u[UNick] = u[UUser] u[UNick] = u[UUser]
|| (strlen(u[UResource]) && u[UResource][1 ..]) || (strlen(u[UResource]) && u[UResource][1 ..]);
|| u[UBody]; // || u[UBody]; -- not so good
return u; return u;
} }

View File

@ -1078,7 +1078,7 @@ P1(("ident: %O is really %O\n", t, source))
// und nicht bei jeder remote suorce generell? TODO // und nicht bei jeder remote suorce generell? TODO
mixed *u = parse_uniform(source); mixed *u = parse_uniform(source);
if (u) { if (u) {
n = u[UNick]; string n = u[UNick];
unless (n) return 0; // not n? hm... unless (n) return 0; // not n? hm...
unless (vars["_nick"] unless (vars["_nick"]

View File

@ -31,43 +31,61 @@ volatile mixed beQuiet;
// my nickspace. used by psyctext(). could be passed as closure, but then // my nickspace. used by psyctext(). could be passed as closure, but then
// it wouldn't be available for *any* psyctext call in user objects. // it wouldn't be available for *any* psyctext call in user objects.
uni2nick(n, vars) { uni2nick(source, vars) {
P3(("uni2nick(%O) in %O\n", n, ME)) P2(("uni2nick(%O) in %O\n", source, ME))
#ifdef USE_AUTOALIAS #ifdef USE_AUTOALIAS
string ln = lower_case(n); string ni = raliases[source];
string al = raliases[ln]; if (ni) return ni;
if (al) return al; if (member(raliases, source)) return UNIFORM(source); // marked dead
if (member(raliases, ln)) return n; // marked dead // ok let's do an autoalias then
mixed u = parse_uniform(n); string ln;
// unfortunately UNick already comes lowercased.. // currently only net/irc employs objects as psyctext sources
// using qName() for objectp would help here // we should either use them more aggressively or abolish them
// or we start using mixed case uniforms.. TODO // and have mixed case uniforms instead
al = lower_case(u[UNick]); if (objectp(source)) ni = source->qName();
if (aliases[al]) { else {
raliases[ln] = 0; // mark dead mixed u = parse_uniform(source);
P2(("uni2nick: already belongs to %O\n", aliases[al])) // unfortunately UNick already comes lowercased..
w("_failure_unavailable_alias", 0, // we should start using mixed case uniforms..
([ "_uniform_new": n, unless (ni = u[UNick]) {
"_uniform_old": aliases[al], // source is probably a server root
"_nick_old": al ]) ); raliases[source] = 0; // mark dead
return n; return source;
}
} }
aliases[al] = n; ln = lower_case(ni);
raliases[ln] = al = u[UNick]; string al = aliases[ln];
P2(("uni2nick: autoaliased %O to %O\n", n, al)) 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, w("_notice_add_alias_temporary", 0,
([ "_uniform_entity": n, ([ "_uniform_entity": source,
"_nick_entity": al ]) ); "_nick_entity": ni ]) );
return al; return ni;
#else #else
// this enables local nickspace, but it fails on local uniforms, // this enables local nickspace, but it fails on local uniforms,
// it fails when local nick collides with alias, so either you make // it fails when local nick collides with alias, so either you make
// it super complicated here, or you keep it super stupid. // it super complicated here, or you keep it super stupid.
//if (objectp(n)) return n->qName(); //if (objectp(n)) return n->qName();
# ifdef ALIASES # ifdef ALIASES
return raliases[lower_case(n)] || n; return raliases[lower_case(source)] || source;
# else # else
return n; return source;
# endif # endif
#endif #endif
} }
@ -315,9 +333,12 @@ protected leavePlace(where) {
** person:msg() we're here to do the output.. ** person:msg() we're here to do the output..
*/ */
msg(source, mc, data, mapping vars, showingLog) { msg(source, mc, data, mapping vars, showingLog) {
string nick, nick2, family; string family;
mixed pal, t, variant; mixed pal, t, variant;
int glyph; int glyph;
#ifdef USE_THE_NICK
string nick, nick2;
#endif
P3(("%O user:msg(%O,%O,%O,%O)\n", ME, source, mc, data, vars)) P3(("%O user:msg(%O,%O,%O,%O)\n", ME, source, mc, data, vars))
// context checking since ip paranoia is applied to context // context checking since ip paranoia is applied to context
@ -393,7 +414,9 @@ msg(source, mc, data, mapping vars, showingLog) {
P4(("after p:msg(%O,%O,%O,%O) -> %O\n", source,mc,data,vars, variant)) 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", // D2(unless (showingLog) D(S("user:msg(%O,%O,%O..) -> %O\n",
// source, mc, data, variant));) // source, mc, data, variant));)
#ifdef USE_THE_NICK
nick = vars["_nick"]; nick = vars["_nick"];
#endif
#ifdef ALIASES #ifdef ALIASES
# ifdef BRAIN # ifdef BRAIN
@ -600,6 +623,7 @@ case "_message": // sollte schon vorher abgefangen worden sein
case "_message_private": case "_message_private":
// question recognition takes place on sender side // question recognition takes place on sender side
// for public talk, so it should also for private talk.. // for public talk, so it should also for private talk..
#ifdef USE_THE_NICK
#if 0 #if 0
# ifdef BRAIN # ifdef BRAIN
P2(( "this shouldn't happen - the brain aliases bug\n" )) P2(( "this shouldn't happen - the brain aliases bug\n" ))
@ -623,6 +647,7 @@ case "_message_private":
#else #else
nick = nick2; nick = nick2;
#endif #endif
#endif
#ifdef QUESTION_RECOGNITION_ON_RECEPTION #ifdef QUESTION_RECOGNITION_ON_RECEPTION
if (variant == "" && data && index(data, '?') != -1) { if (variant == "" && data && index(data, '?') != -1) {
// mc += "_ask"; // mc += "_ask";
@ -686,18 +711,25 @@ case "_message_public":
: to_string(room)); : to_string(room));
w((data ? "_message_public_other": w((data ? "_message_public_other":
"_message_public_other_action")+variant, "_message_public_other_action")+variant,
data, vars + data, vars + ([
([ "_nick": nick2, "_nick_place": room ]) ); #ifdef USE_THE_NICK
"_nick": nick2,
#endif
"_nick_place": room ]) );
return 1; return 1;
} }
} }
#ifdef USE_THE_NICK
nick = nick2; nick = nick2;
#endif
break; break;
} }
if (vars["_nick_local"] && MYLOWERNICK != lower_case(vars["_nick_local"])) { if (vars["_nick_local"] && MYLOWERNICK != lower_case(vars["_nick_local"])) {
// should we have special templates for this? // should we have special templates for this?
//mc = "_message_echo_public_masquerade"; //mc = "_message_echo_public_masquerade";
#ifdef USE_THE_NICK
nick = vars["_nick_local"]; nick = vars["_nick_local"];
#endif
// or should we rather make sure that all clients // or should we rather make sure that all clients
// learn to detect echo themselves, since future // learn to detect echo themselves, since future
// multicast routing may not give us the possibility // multicast routing may not give us the possibility
@ -715,9 +747,11 @@ case "_message_behaviour_punishment":
case "_message_behaviour": case "_message_behaviour":
unless (stringp(data)) variant = "_default"; unless (stringp(data)) variant = "_default";
else variant = ""; else variant = "";
#ifdef USE_THE_NICK
nick = nick2; nick = nick2;
// fmt = nick ? "%s announces: %s\n" // fmt = nick ? "%s announces: %s\n"
// : "*** Announcement: %s ***\n"; // : "*** Announcement: %s ***\n";
#endif
break; break;
case "_request_message_public_question": case "_request_message_public_question":
case "_request_message": case "_request_message":
@ -1139,6 +1173,7 @@ case "_status":
} }
} }
#endif #endif
#ifdef USE_THE_NICK
// imho macht das hier probleme bei _echo_place_enter // imho macht das hier probleme bei _echo_place_enter
// da ist der raum die source, es ist kein _context dabei // da ist der raum die source, es ist kein _context dabei
// vars["_nick"] ist der nick des joinenden (==qName()) // vars["_nick"] ist der nick des joinenden (==qName())
@ -1160,8 +1195,12 @@ case "_status":
#endif #endif
vars["_nick"] = nick; vars["_nick"] = nick;
// this at least works also for HTTP // this at least works also for HTTP
#endif
unless (wAction(mc, data, vars, source, variant, nick)) { if (! wAction(mc, data, vars, source, variant
#ifdef USE_THE_NICK
, nick
#endif
)) {
if (!data && vars["_action_possessive"]) if (!data && vars["_action_possessive"])
w(mc+"_action_possessive", data, vars, source, showingLog); w(mc+"_action_possessive", data, vars, source, showingLog);
else else