-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMUD.cc
More file actions
70 lines (56 loc) · 1.6 KB
/
MUD.cc
File metadata and controls
70 lines (56 loc) · 1.6 KB
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
#include "MUD.h"
#include "StaticBuffer.h"
#include <string.h>
#include <time.h>
// Class for handling a MUD
MUD::MUD (const char *_name, const char *_hostname, int _port, MUD *_inherits, const char *_commands) {
name = _name;
hostname = _hostname;
port = _port;
commands = _commands;
inherits = _inherits;
loaded = false;
}
MUD * MUDList::find(const char *_name) {
for (MUD *mud = rewind(); mud; mud = next()) {
if (!strcasecmp(mud->getName(), _name))
return mud;
}
return NULL;
}
void MUD::setHost(const char *_host, int _port) {
hostname = _host;
port = _port;
}
const char* MUD::getHostname() const {
if (hostname.length() == 0)
return inherits ? inherits->getHostname() : "";
return hostname.c_str();
}
int MUD::getPort() const {
if (port == 0)
return inherits ? inherits->getPort() : 0;
return port;
}
MUD globalMUD("global", "", 0, NULL, "");
void MUD::write(FILE *fp, bool global) {
const char *indent;
if (!global) {
fprintf(fp, "Mud %s {\n", name.c_str());
indent = " ";
} else
indent = "";
if (!global) {
if (hostname.length())
fprintf(fp, " Host %s %d\n", hostname.c_str(), port);
if (commands.length())
fprintf(fp, " Commands %s\n", commands.c_str());
if (inherits && inherits != &globalMUD)
fprintf(fp, " Inherit %s\n", inherits->getName());
}
if (!global)
fprintf(fp, "}\n");
}
const char *MUD::getFullName() const {
return Sprintf("%s@%s:%d", name.c_str(), hostname.c_str(), port);
}