// An intermud (3) handler; Galileo, 12-05-98
#define SAVE_FILE "/secure/save/handlers/intermud"
#define ROUTERS ({ ({"*yatmim", "149.152.218.102 23"}) })
inherit "/secure/std/modules/tcp_client";
#include <network.h>
#include <intermud.h>
class list {
int id;
mapping list;
} /* class list */
class intermud {
int passwd, configured;
class list channel_list, mud_list;
string connected;
mixed routers;
} /* class intermud */
class admin_channel {
int type;
string *members;
} /* admin_channel() */
mixed *packet_allocate(string);
nosave int shutdown;
nosave function channel_event_receiver;
nosave string *ns_libs = ({ });
nosave string *dw_libs = ({ });
string *listen_channels = ({ });
mapping admin_channels = ([ ]);
class intermud config;
private void save_me() { unguarded((: save_object, SAVE_FILE :)); }
private void load_me() { unguarded((: restore_object,SAVE_FILE,1 :)); }
private void create() {
string host;
int port;
config = new(class intermud,
mud_list : new(class list, list : ([ ]) ),
channel_list : new(class list, list : ([ ]) ));
tcp_client::mudlib_setup();
config->routers = ROUTERS;
sscanf(config->routers[0][1], "%s %d", host, port);
listen_channels = DEFAULT_CHANNELS;
load_me();
config->connected = NULL;
config->configured = NULL;
open_socket(host, port, MUD);
} /* setup() */
void dest_me() {
// Remove I3 channels when the handler goes down.
// map(listen_channels, (: USER_H -> remove_channel($1+ "-channel") :));
tcp_client::dest_me();
// handler::dest_me();
} /* dest_me() */
string mud_exists(string mud) {
string *muds = keys(config->mud_list -> list);
for (int i = 0; i < sizeof(muds); i++)
if (lower_case(muds[i]) == lower_case(mud))
return muds[i];
return 0;
} /* mud_exists() */
mixed *packet_allocate(string type) {
mixed *packet;
if (member_array(type, keys(PACKET_SIZES)) != -1) {
packet = allocate(S_P + PACKET_SIZES[type]);
} else {
log_file("INTERMUD_H", sprintf("%s - %s",
"Invalid packet allocation", type));
return 0;
}
packet[P_TYPE] = type;
packet[P_TTL] = 5;
packet[P_SOURCE] = MUD_NAME;
return packet;
} /* allocate_packet() */
private void packet_invalid(mixed *packet) {
log_file("INTERMUD_H", sprintf("%s\n%O\n",
"Invalid packet", packet));
} /* packet_invalid() */
#include "intermud/channel.h"
#include "intermud/emoteto.h"
#include "intermud/error.h"
#include "intermud/finger.h"
#include "intermud/locate.h"
#include "intermud/mudlist.h"
#include "intermud/shutdown.h"
#include "intermud/startup.h"
#include "intermud/tell.h"
#include "intermud/who.h"
protected void client_close_callback(int fd) {
config->connected = NULL;
tcp_client::client_close_callback(fd);
} /* client_close_callback() */
protected void client_write_callback(int fd) {
if (!(config->connected))
startup_req();
tcp_client::client_write_callback(fd);
} /* client_write_callback() */
protected void client_read_callback(int fd, mixed *packet) {
tcp_client::client_read_callback(fd, packet);
if (!packet)
return;
switch (packet[P_TYPE]) {
default: packet_invalid(packet); return;
case CHANNEL_E_PACKET: channel_e(packet); return;
case CHANNEL_M_PACKET: channel_m(packet); return;
case CHANNEL_T_PACKET: channel_t(packet); return;
case CHANLIST_REPLY_PACKET: chanlist_reply(packet); return;
case CHAN_WHO_REPLY_PACKET: chan_who_reply(packet); return;
case CHAN_WHO_REQ_PACKET: chan_who_request(packet); return;
case EMOTETO_PACKET: emoteto_reply(packet); return;
case ERROR_PACKET: packet_error(packet); return;
case FINGER_REPLY_PACKET: finger_reply(packet); return;
case FINGER_REQ_PACKET: finger_request(packet); return;
case LOCATE_REPLY_PACKET: locate_reply(packet); return;
case LOCATE_REQ_PACKET: locate_request(packet); return;
case MUDLIST_PACKET: mudlist_reply(packet); return;
case STARTUP_REPLY_PACKET: startup_reply(packet); return;
case TELL_PACKET: tell_reply(packet); return;
case WHO_REPLY_PACKET: who_reply(packet); return;
case WHO_REQ_PACKET: who_request(packet); return;
}
} /* client_read_callback() */