Zesstra | 83f011d | 2016-04-24 20:09:05 +0200 | [diff] [blame^] | 1 | #pragma strict_types, save_types, rtt_checks, pedantic |
| 2 | #pragma no_clone, no_shadow, no_inherit |
| 3 | |
| 4 | #include <intermud.h> |
| 5 | #include <regexp.h> |
| 6 | #include <living/comm.h> |
| 7 | #include <defines.h> |
| 8 | #include <daemon/mand.h> |
| 9 | |
| 10 | protected nosave string currentname = "INETD-service"; |
| 11 | |
| 12 | public string service_name() |
| 13 | { |
| 14 | return "undefined"; |
| 15 | } |
| 16 | |
| 17 | public string name(int egal) |
| 18 | { |
| 19 | return currentname || "INETD-"+service_name(); |
| 20 | } |
| 21 | |
| 22 | public string Name(int egal) |
| 23 | { |
| 24 | return capitalize(name(egal)); |
| 25 | } |
| 26 | |
| 27 | // we received a reply to one of our requests. |
| 28 | // Note: if response is 0, the peer did not respond (timeout)... |
| 29 | protected void recv_reply(int id, mapping request, mapping response) |
| 30 | { |
| 31 | if(response) |
| 32 | { |
| 33 | if (stringp(response[RECIPIENT])) |
| 34 | { |
| 35 | object ob = find_player(response[RECIPIENT]) |
| 36 | || find_object(response[RECIPIENT]); |
| 37 | if (ob) |
| 38 | { |
| 39 | currentname = capitalize(data[SENDER])+"@"+capitalize(data[NAME]); |
| 40 | ob->ReceiveMsg(regreplace(response[DATA],"[:^print:]|\n","",1), |
| 41 | MT_NOTIFICATION, service_name(), 0, ME); |
| 42 | currentname = 0; |
| 43 | } |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | // no response, timeout... |
| 48 | if (request[SENDER] && stringp(request[SENDER])) |
| 49 | { |
| 50 | object ob = find_player(request[SENDER]) |
| 51 | || find_object(request[SENDER]); |
| 52 | if (ob) |
| 53 | ob->ReceiveMsg("Das Mud \'" + request[NAME] + |
| 54 | "\' konnte nicht erreicht werden.\n", |
| 55 | MT_NOTIFICATION, 0, service_name(), ME); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // we received an intermud request |
| 61 | protected void recv_request(mapping data) |
| 62 | { |
| 63 | // implement it! |
| 64 | raise_error("recv_request() has to be implemented!\n"); |
| 65 | } |
| 66 | |
| 67 | // send request via intermud |
| 68 | public int request(string mudname, string|int data) |
| 69 | { |
| 70 | return INETD->send(mudname, ([REQUEST: servicename(), |
| 71 | DATA: data, |
| 72 | SENDER: getuid(previous_object())]), |
| 73 | #'recv_reply) > 0; |
| 74 | } |
| 75 | |
| 76 | protected void create() |
| 77 | { |
| 78 | INETD->register_service(service_name(), #'recv_request); |
| 79 | currentname = "INETD-"+service_name(); |
| 80 | } |
| 81 | |
| 82 | public varargs int remove(int silent) |
| 83 | { |
| 84 | INETD->unregister_service(service_name()); |
| 85 | destruct(this_object()); |
| 86 | } |
| 87 | |
| 88 | |