mirror of
git://git.psyced.org/git/psyced
synced 2024-08-15 03:25:10 +00:00
let the past begone in cvs land. welcome to igit igit!
This commit is contained in:
commit
4e601cf1c7
509 changed files with 77963 additions and 0 deletions
119
world/net/gateway/aim.c
Normal file
119
world/net/gateway/aim.c
Normal file
|
@ -0,0 +1,119 @@
|
|||
// $Id: aim.c,v 1.35 2007/09/18 08:37:57 lynx Exp $ // vim:syntax=lpc
|
||||
//
|
||||
#if 0
|
||||
//
|
||||
// this gateway uses an external python script called AIMgate.py
|
||||
// or something like that. should be in the pypsyc dist somewhere.
|
||||
// we tried to use jabber transports instead, so look into config.c
|
||||
// and aim2.c
|
||||
//
|
||||
// in fact both methods aren't functional right now, not in the
|
||||
// gatebot style... but we keep it in case there is a chance or
|
||||
// necessity to recover.
|
||||
//
|
||||
#include <net.h>
|
||||
#include <url.h>
|
||||
//#include <text.h>
|
||||
|
||||
inherit NET_PATH "gateway/generic";
|
||||
inherit PSYC_PATH "active";
|
||||
|
||||
volatile string buf;
|
||||
|
||||
#ifdef AIM_GATEWAY
|
||||
void create() {
|
||||
array(string) u = URL(AIM_GATEWAY);
|
||||
// for a gateway that only supports tcp, append "c"
|
||||
// #define AIM_GATEWAY "psyc://aim.symlynX.com:49152c"
|
||||
// for a gateway that only supports udp, append "d"
|
||||
// #define AIM_GATEWAY "psyc://aim.symlynX.com:49152d"
|
||||
//
|
||||
// we prefer using udp, but if the gateway cannot handle that
|
||||
// we'll have to open up a tcp connection..
|
||||
//
|
||||
// if (u && u[UTransport] == "c") {
|
||||
register_target(lower_case(AIM_GATEWAY));
|
||||
// ahost = u[UHost];
|
||||
// aport = u[UPort];
|
||||
connect(u[UHost], u[UPort]);
|
||||
// }
|
||||
// else ahost = 0;
|
||||
joe = "nobody";
|
||||
sTextPath("default", "en", "aim");
|
||||
register_scheme("aim");
|
||||
::create();
|
||||
}
|
||||
|
||||
msg(source, mc, data, mapping vars, showingLog, target) {
|
||||
P1(("aim:msg %O » %O (%s, %O, %O)\n",
|
||||
source, target, mc, data, vars))
|
||||
unless (mappingp(vars)) vars = ([]);
|
||||
if (target && stringp(target) && abbrev("aim:", target)) {
|
||||
vars["_source_relay"] = source;
|
||||
vars["_target_relay"] = target;
|
||||
|
||||
P1(("aim:outgoing %s\n", mc))
|
||||
if (interactive(ME))
|
||||
//delivermsg(target, mc, data, vars, ME);
|
||||
::msg(target, mc, data, vars, ME);
|
||||
else
|
||||
sendmsg(AIM_GATEWAY, mc, data, vars);
|
||||
|
||||
// REPLY mode by default
|
||||
unless (talk[target]) {
|
||||
// talk[target] = source;
|
||||
bot(target, 0, source);
|
||||
}
|
||||
} else if (source && stringp(source)) {
|
||||
// && abbrev(AIM_GATEWAY, source)) { needs a trustworthy check
|
||||
source = vars["_source_relay"];
|
||||
P1(("aim:incoming from %O\n", source))
|
||||
if (abbrev("_request_input", mc)) {
|
||||
bot(source, data, 0);
|
||||
} else {
|
||||
#if 1
|
||||
// es gibt ab sofort eine funktion in der library die dasselbe tut..
|
||||
// bitte einbauen TODO ... oder sendmsg tuts? sendmsg sollte das tun
|
||||
string *u;
|
||||
target = vars["_target_relay"];
|
||||
unless (target) return;
|
||||
// bis sendmsg() lokale stringp's erkennen kann... TODO
|
||||
u = parse_uniform(target);
|
||||
// if (u[UPort] && u[UPort] == query_imp_port()) {
|
||||
// vergleichen mit bisheriger logik in parse.i TODO
|
||||
if (u[UResource][0] == '~')
|
||||
target = find_person(u[UResource][1..]);
|
||||
else if (u[UUser]) target = find_person(u[UUser]);
|
||||
else target = find_object(u[UResource]);
|
||||
// }
|
||||
#else
|
||||
target = vars["_target_relay"];
|
||||
#endif
|
||||
m_delete(vars, "_source_relay");
|
||||
m_delete(vars, "_target_relay");
|
||||
sendmsg(target, mc, data, vars, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bot(aimer, data, psycer) {
|
||||
// joe_nick =
|
||||
joe = joe_unl = aimer;
|
||||
buf = 0;
|
||||
if (data) input(data);
|
||||
else talkto(psycer);
|
||||
if (buf) msg(ME, "_notice_reply",
|
||||
"<font size=2 color=\"#006600\">"+ buf + "</font>", 0,0, joe);
|
||||
// "<html><body bgcolor=black text=green padding=9>"+
|
||||
// buf + "</body></html>", 0,0, joe);
|
||||
}
|
||||
|
||||
reply(text) {
|
||||
// if (buf) buf+="<br>\n"+text; // bug in pypsyc, should be \n
|
||||
if (buf) buf+="<br>"+text;
|
||||
else buf=text;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
5
world/net/gateway/aim2.c
Normal file
5
world/net/gateway/aim2.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
// component logic for jabber aim-t transports (icq, aim)
|
||||
#include <net.h>
|
||||
|
||||
// simply copy what the icq thing does :)
|
||||
inherit NET_PATH "gateway/icq";
|
194
world/net/gateway/generic.c
Normal file
194
world/net/gateway/generic.c
Normal file
|
@ -0,0 +1,194 @@
|
|||
// $Id: generic.c,v 1.36 2008/02/08 12:53:25 lynx Exp $ // vim:syntax=lpc
|
||||
//
|
||||
// this is a generic robot that provides a few commands to interface
|
||||
// a centralistic messaging system to the PSYC. since the commercial
|
||||
// system have a political interest not to support this, this is only
|
||||
// available as an IRC gatebot these days. See net/irc/gatebot.c
|
||||
|
||||
#include <net.h>
|
||||
#include <text.h>
|
||||
#include <closures.h>
|
||||
|
||||
#define URL_DOC "http://www.psyc.eu/gatebot"
|
||||
#define INFO "\
|
||||
Gateway to the Protocol for SYnchronous Conferencing.\n\
|
||||
Find more information at " URL_DOC
|
||||
|
||||
virtual inherit NET_PATH "output";
|
||||
|
||||
#ifndef SERVER_UNL
|
||||
# define SERVER_UNL query_server_unl()
|
||||
#endif
|
||||
|
||||
volatile object psycer;
|
||||
volatile string joe, joe_nick;
|
||||
volatile mixed joe_unl;
|
||||
volatile mapping talk = ([]);
|
||||
volatile closure sort_by_name;
|
||||
|
||||
queryLastServed() { return joe; }
|
||||
|
||||
static input(text) {
|
||||
string com, rest;
|
||||
|
||||
if (!sscanf(text, "%s %s", com, rest)) com=text;
|
||||
unless (talk[joe]) com = upper_case(com);
|
||||
switch(com) {
|
||||
// we grant no administrative functions from the legacy system as we
|
||||
// don't have proper authentication there..
|
||||
//
|
||||
#if 0 //def GATEWAY_COMMAND_DISCONNECT
|
||||
case GATEWAY_COMMAND_DISCONNECT:
|
||||
reply("Bye bye..");
|
||||
return disc();
|
||||
#endif
|
||||
#if 0 //def GATEWAY_COMMAND_DONATE
|
||||
case GATEWAY_COMMAND_DONATE:
|
||||
reply("Cool man.");
|
||||
return chop(joe);
|
||||
#endif
|
||||
case "M":
|
||||
case "MSG":
|
||||
case "T":
|
||||
case "TALK":
|
||||
case "QUERY":
|
||||
case "Q":
|
||||
case ".":
|
||||
case "QUIT":
|
||||
case "TELL": return tell(rest);
|
||||
case "H":
|
||||
case "HELP": return help();
|
||||
case "S":
|
||||
case "ST":
|
||||
case "STATUS":
|
||||
case "N":
|
||||
case "NA":
|
||||
case "NAMES": return stat();
|
||||
case "W":
|
||||
case "WHO": return who();
|
||||
}
|
||||
if (talk[joe]) {
|
||||
// i want regular echoes back.. hmmm
|
||||
// reply("You tell "+ talk[joe]+": "+text);
|
||||
sendmsg(talk[joe], "_message_private", text,
|
||||
([ "_nick" : joe_nick ]), joe_unl);
|
||||
} else unknownmsg(text);
|
||||
}
|
||||
|
||||
static help() {
|
||||
#ifdef INFO
|
||||
string t;
|
||||
foreach(t : explode(INFO, "\n")) reply(t);
|
||||
#endif
|
||||
#ifdef WEBMASTER_EMAIL
|
||||
reply("This gateway is operated by " WEBMASTER_EMAIL);
|
||||
// " on "+ SERVER_UNL);
|
||||
#endif
|
||||
// reply("Can you imagine this is the new version of the first ever IRC bot written in LPC?");
|
||||
reply("Available commands: WHO, STATUS, TELL/MSG, TALK/QUERY, HELP");
|
||||
}
|
||||
|
||||
static tell(a) {
|
||||
string whom, text;
|
||||
mixed p;
|
||||
|
||||
if (!a || !sscanf(a, "%s %s", whom, text)) {
|
||||
whom = a;
|
||||
text = 0;
|
||||
}
|
||||
unless (whom) {
|
||||
if (talk[joe]) {
|
||||
reply("Okay. Query terminated.");
|
||||
talk[joe] = 0;
|
||||
} else {
|
||||
reply("Usage: T(ELL) or MSG <psycer> <textmessage>");
|
||||
reply("Usage: T(ALK) or QUERY <psycer>");
|
||||
reply("<psycer> may either be a nickname on "+ SERVER_UNL +
|
||||
" or a uniform network identification anywhere"
|
||||
" in PSYCspace.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
unless (is_formal(p = whom)) {
|
||||
p = summon_person(whom);
|
||||
if (!p) return reply(whom+" ain't here on "+ SERVER_UNL);
|
||||
}
|
||||
if (text) {
|
||||
reply("You tell "+ UNIFORM(p) +": "+text);
|
||||
sendmsg(p, "_message_private", text,
|
||||
([ "_nick" : joe_nick ]), joe_unl);
|
||||
}
|
||||
else talkto(p);
|
||||
// log_file("IRCTELL", ctime(time())+" IN : "+joe+" talks to "+whom);
|
||||
}
|
||||
|
||||
static stat() {
|
||||
reply("Gateway "+ psyc_name(ME) +" is connected to "+ query_ip_number());
|
||||
}
|
||||
|
||||
// hi there möchtegernhacker, the WHO function has no serious purpose
|
||||
// as it only lists the local users anyway, so the real intention is to
|
||||
// give you a very easy means to disconnect the gateway from your IRC
|
||||
// network. if you don't like PSYC, simply issue a few WHOs and the
|
||||
// gatebot will get killed by excess flood. if the gateway is alive and
|
||||
// functioning properly, it's a sign that your IRC network isn't so rude
|
||||
// after all.
|
||||
static who() {
|
||||
mapping uv;
|
||||
mixed *u;
|
||||
int all;
|
||||
mixed idle;
|
||||
string desc;
|
||||
|
||||
unless (closurep(sort_by_name))
|
||||
sort_by_name = lambda(({ 'a, 'b}),
|
||||
({ (#',),
|
||||
({ CL_NIF, ({ #'mappingp, 'a }), ({ #'return, 0 }) }),
|
||||
({ CL_NIF, ({ #'mappingp, 'b }), ({ #'return, 1 }) }),
|
||||
({ #'return, ({ (#'>),
|
||||
({ CL_LOWER_CASE, ({ (#'||), ({ CL_INDEX, 'a, "name" }), "" }) }),
|
||||
({ CL_LOWER_CASE, ({ (#'||), ({ CL_INDEX, 'b, "name" }), "" }) }),
|
||||
}) })
|
||||
}));
|
||||
|
||||
reply("--- /who of local users of "+ SERVER_UNL);
|
||||
u = objects_people();
|
||||
all = sizeof(u) < 23;
|
||||
u = sort_array(u->qPublicInfo(all), sort_by_name);
|
||||
foreach (uv : u) if (mappingp(uv)) {
|
||||
desc = uv["me"];
|
||||
if (desc || all) {
|
||||
// if (idle = uv["aliveTime"]) {
|
||||
// idle = hhmm(ctime(time() - idle - 60*60));
|
||||
// if (idle == "00:00") idle = "--:--";
|
||||
// }
|
||||
// idle = uv["aliveTime"] ?
|
||||
// timedelta( time()-uv["aliveTime"] ) : "??:??";
|
||||
idle = intp(uv["idleTime"]) ?
|
||||
timedelta( uv["idleTime"] ) : "??:??";
|
||||
if (desc)
|
||||
reply( S("[%s] %s %s.",
|
||||
idle, uv["nick"], desc) );
|
||||
else
|
||||
reply( S("[%s] %s is online.",
|
||||
idle, uv["nick"]) );
|
||||
}
|
||||
}
|
||||
reply("--- end of /who");
|
||||
return 1;
|
||||
}
|
||||
|
||||
unknownmsg(text) {
|
||||
reply("No target set for your message. Please use 'TALK <<psyc:address>>' to define one. Try HELP for more help.");
|
||||
// D0( D(joe+" tells gatebot: "+text); )
|
||||
monitor_report("_warning_unexpected_gateway_message", "Gateway: "+
|
||||
joe_unl+" says: "+text);
|
||||
}
|
||||
|
||||
talkto(p) {
|
||||
reply("Query with "+ UNIFORM(p)+ " begun. Send '.' to stop.");
|
||||
reply("Try HELP (uppercase) for more help.");
|
||||
talk[joe] = p;
|
||||
P4(("talk is %O\n", talk))
|
||||
}
|
||||
|
181
world/net/gateway/icq.c
Normal file
181
world/net/gateway/icq.c
Normal file
|
@ -0,0 +1,181 @@
|
|||
// $Id: icq.c,v 1.47 2007/08/27 16:54:12 lynx Exp $ // vim:syntax=lpc
|
||||
//
|
||||
// this code is no longer in use. component.c has changed.
|
||||
// and the gatebot principle isn't politically well accepted
|
||||
// with the centralistic providers. but there may be others,
|
||||
// or politics may change, so this code may return into action
|
||||
// one day. alright, maybe not exactly the code as it is in
|
||||
// this file, but after some correction. it's better to start
|
||||
// from something that needs to be updated than to spend days
|
||||
// writing something from scratch. or maybe it isn't, but at
|
||||
// least i had the option.
|
||||
//
|
||||
#if 0
|
||||
//
|
||||
// component logic for jabber aim-t transports (icq, aim)
|
||||
//
|
||||
// this registers a gateway bot implemented by an external jabber server.
|
||||
// unfortunately this plan has not proven any better than doing an aim
|
||||
// gateway in python (see aim.c)
|
||||
//
|
||||
#include <net.h>
|
||||
#include <url.h>
|
||||
//#include <text.h>
|
||||
#include <xml.h>
|
||||
|
||||
inherit JABBER_PATH "component";
|
||||
inherit GATEWAY_PATH "generic";
|
||||
|
||||
volatile string buf;
|
||||
|
||||
void create() {
|
||||
object o = find_object(CONFIG_PATH "config");
|
||||
|
||||
if (o) config = o->qConfig();
|
||||
if (!config) return;
|
||||
P2(("\n%O loads config %O\n", ME, config))
|
||||
|
||||
joe = "nobody";
|
||||
sTextPath(0, 0, "jabber");
|
||||
// init();
|
||||
connect();
|
||||
}
|
||||
|
||||
msg(source, mc, data, mapping vars, showingLog, target) {
|
||||
P1(("%s:msg %O » %O (%s, %O, %O)\n",
|
||||
config["scheme"], source, target, mc, data, vars))
|
||||
|
||||
unless (mappingp(vars)) vars = ([]);
|
||||
if (abbrev("_message", mc)) data = xmlquote(data);
|
||||
if (target && stringp(target) && abbrev(config["scheme"] + ":",
|
||||
target)) {
|
||||
string uin;
|
||||
sscanf(target, config["scheme"] + ":%s", uin);
|
||||
vars["_source_relay"] = source;
|
||||
vars["_INTERNAL_source_jabber"] = "PSYCgate@" + SERVER_HOST;
|
||||
vars["_INTERNAL_target_jabber"] = uin + "@" + config["name"];
|
||||
w(mc, data, vars, source);
|
||||
// REPLY mode by default
|
||||
unless (talk[target]) {
|
||||
// talk[target] = source;
|
||||
bot(target, 0, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bot(icqer, data, psycer) {
|
||||
// joe_nick =
|
||||
joe = joe_unl = icqer;
|
||||
buf = 0;
|
||||
if (data) input(data);
|
||||
else talkto(psycer);
|
||||
if (buf) msg(ME, "_notice_reply",
|
||||
"<message from='[_source_jabber]' to='[_target_jabber]' type='chat'><body>"+ buf + "</body></message>", 0,0, joe);
|
||||
}
|
||||
|
||||
reply(text) {
|
||||
text = xmlquote(text);
|
||||
if (buf) buf+="\n"+text;
|
||||
else buf=text;
|
||||
}
|
||||
|
||||
onHandshake() {
|
||||
// do not use a standard method here, or the template will be replaced
|
||||
// by textdb into something incompatible
|
||||
w("_notice_presence_here_gateway",
|
||||
"<presence to='[_INTERNAL_target_jabber]'"
|
||||
" from='[_INTERNAL_source_jabber]'/>",
|
||||
([ "_INTERNAL_target_jabber" : config["name"] + "/registered",
|
||||
"_INTERNAL_source_jabber" : "PSYCgate@" + SERVER_HOST,
|
||||
"_INTERNAL_mood_jabber" : "neutral" ]));
|
||||
|
||||
}
|
||||
|
||||
jabberMsg(XMLNode node) {
|
||||
string uin;
|
||||
|
||||
P2(("%s gateway jabberMsg \n", config["scheme"]))
|
||||
switch(node[Tag]) {
|
||||
case "xdb":
|
||||
xdb(node);
|
||||
break;
|
||||
case "presence":
|
||||
switch(node["@type"]) {
|
||||
case "error":
|
||||
P2(("gateway/%s error %O\n", config["scheme"],
|
||||
node["/error"][Cdata]))
|
||||
break;
|
||||
case "unavailable":
|
||||
P2(("gateway/%s unavailable %O\n", config["scheme"],
|
||||
node["/status"][Cdata]))
|
||||
break;
|
||||
case 0:
|
||||
unless(node["/status"]) return -1;
|
||||
if (node["/status"][Cdata] == "Connected" ||
|
||||
node["/status"][Cdata] == "Online") {
|
||||
P2(("registering scheme %O\n", config["scheme"]))
|
||||
register_scheme(config["scheme"]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
P2(("gateway/%s presence default: %O\n", config["scheme"],
|
||||
node["@type"]))
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "message":
|
||||
// message
|
||||
// if(node["@from"] == "PSYCgate@" + SERVER_HOST) return;
|
||||
P2(("talk %O, joe %O\n", talk, node["@from"]))
|
||||
sscanf(node["@from"], "%s@", uin);
|
||||
P1(("config %O\nnode %O\n", config, node))
|
||||
bot(config["scheme"]+":" + uin, node["/body"][Cdata], 0);
|
||||
break;
|
||||
default:
|
||||
return ::jabberMsg(node);
|
||||
}
|
||||
}
|
||||
|
||||
xdb(node) {
|
||||
switch(node["@type"]) {
|
||||
case "get":
|
||||
switch(node["@ns"]) {
|
||||
case "aimtrans:data":
|
||||
emit(sprintf("<xdb type='result' to='%s' from='%s' id='%s' ns='%s'>"
|
||||
"<aimtrans><login id='%s' pass='%s'/></aimtrans>"
|
||||
"</xdb>",
|
||||
node["@from"], node["@to"],
|
||||
node["@id"], node["@ns"],
|
||||
config["nickname"], config["password"]));
|
||||
break;
|
||||
case "aimtrans:roster":
|
||||
emit(sprintf("<xdb type='result' to='%s' from='%s' ns='%s' "
|
||||
"id='%s'><aimtrans><buddies/></aimtrans></xdb>",
|
||||
node["@from"], node["@to"],
|
||||
node["@ns"], node["@id"]));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "set":
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
quit() {
|
||||
emit(sprintf("<presence type='unavailable' from='%s' to='%s'/>",
|
||||
"PSYCgate@" + SERVER_HOST, config["host"] + "/registered"));
|
||||
emit("</stream:stream>");
|
||||
}
|
||||
|
||||
reboot(reason, restart, pass) {
|
||||
emit(sprintf("<presence type='unavailable' from='%s' to='%s'/>",
|
||||
"PSYCgate@" + SERVER_HOST, config["host"] + "/registered"));
|
||||
emit("</stream:stream>");
|
||||
::reboot(reason, restart, pass);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue