]>
Commit | Line | Data |
---|---|---|
fb37ecc7 | 1 | #include <fstream> |
85ce9d3e | 2 | #include <string.h> |
20d5d721 | 3 | #include <stdlib.h> |
85ce9d3e | 4 | #include <stdio.h> |
5 | #include "extern.h" | |
6 | ||
fb37ecc7 | 7 | using std::ifstream; |
33ac4371 | 8 | using std::cerr; |
9 | using std::endl; | |
fb37ecc7 | 10 | |
85ce9d3e | 11 | void load_config_file(char *config); |
12 | void unload_config_file(); | |
85ce9d3e | 13 | |
14 | /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/ | |
15 | ||
16 | char *s_GameServ; // GameServ's nickname | |
17 | char *gshost; // GameServ's Hostname | |
18 | char *gsident; // GameServ's ident/username | |
19 | char *servername; // GameServ's Server | |
20 | char *c_Forest; // Forest channel | |
21 | char *c_ForestTopic; // Forest Channel Topic | |
45a84400 | 22 | char *adminpass; // Administrator password |
bf2cabcd | 23 | char *welcomemsg; // Welcome Message |
922daad7 | 24 | int welcomedelay; // Welcome Message Delay |
25 | int updateperiod; // Seconds until another player database update | |
20d5d721 | 26 | int forestfights; // Forest fights per day |
85ce9d3e | 27 | |
28 | // Remote server stuff. This is used for the outgoing connection gameserv needs to make | |
29 | // to a real ircd. | |
30 | char *remoteserver; // Server to connect to | |
31 | char *remoteport; // Port to connect to on remoteserver | |
32 | char *remotepass; // Password for the server link | |
33 | ||
34 | char *playerdata; // File to store player data in | |
4dde2ed9 | 35 | char *monsterdata; // File to load monster data from |
85ce9d3e | 36 | |
e1c41a84 | 37 | #if defined(P10) |
38 | char *gsnum = "[]AAA"; // GameServ Numeric | |
39 | #endif | |
40 | ||
85ce9d3e | 41 | void unload_config_file() |
42 | { | |
43 | if (s_GameServ) | |
1cf88153 | 44 | delete [] s_GameServ; |
85ce9d3e | 45 | if (gshost) |
1cf88153 | 46 | delete [] gshost; |
85ce9d3e | 47 | if (gsident) |
1cf88153 | 48 | delete [] gsident; |
85ce9d3e | 49 | if (servername) |
1cf88153 | 50 | delete [] servername; |
85ce9d3e | 51 | if (c_Forest) |
1cf88153 | 52 | delete [] c_Forest; |
85ce9d3e | 53 | if (c_ForestTopic) |
1cf88153 | 54 | delete [] c_ForestTopic; |
85ce9d3e | 55 | if (remoteserver) |
1cf88153 | 56 | delete [] remoteserver; |
85ce9d3e | 57 | if (remoteport) |
1cf88153 | 58 | delete [] remoteport; |
85ce9d3e | 59 | if (remotepass) |
1cf88153 | 60 | delete [] remotepass; |
85ce9d3e | 61 | if (playerdata) |
1cf88153 | 62 | delete [] playerdata; |
4dde2ed9 | 63 | if (monsterdata) |
64 | delete [] monsterdata; | |
45a84400 | 65 | if (adminpass) |
66 | delete [] adminpass; | |
bf2cabcd | 67 | if (welcomemsg) |
68 | delete [] welcomemsg; | |
85ce9d3e | 69 | } |
bf2cabcd | 70 | |
85ce9d3e | 71 | void load_config_file(char *config) |
72 | { | |
73 | char *buf, *directive, *value; | |
74 | buf = new char[1024]; | |
75 | ||
76 | unload_config_file(); | |
77 | ||
78 | ifstream infile; | |
79 | infile.open(config); | |
80 | if (infile.fail()) | |
81 | { | |
fb37ecc7 | 82 | log("Error opening %s", config); |
33ac4371 | 83 | cerr << "Error opening " << config << endl; |
85ce9d3e | 84 | return; |
85 | } | |
86 | ||
87 | while (infile.getline(buf, 1024, '\n')) | |
88 | { | |
9f8c2acc | 89 | #ifdef DEBUGMODE |
33ac4371 | 90 | log("Config file entry buf: %s", buf); |
9f8c2acc | 91 | #endif |
85ce9d3e | 92 | |
9cc5ab57 | 93 | if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') |
85ce9d3e | 94 | continue; |
95 | ||
96 | directive = strtok(buf, " "); | |
97 | ||
20d5d721 | 98 | if (stricmp(directive, "DIE") == 0) |
99 | { | |
100 | value = strtok(NULL, ""); | |
fb37ecc7 | 101 | log("You should read the entire %s file!", config); |
33ac4371 | 102 | cerr << "You should read the entire " << config << " file!" |
103 | << endl; | |
20d5d721 | 104 | exit(0); |
105 | } | |
85ce9d3e | 106 | if (stricmp(directive, "S_GAMESERV") == 0) |
107 | { | |
108 | value = strtok(NULL, " "); | |
109 | s_GameServ = new char[strlen(value) + 1]; | |
110 | strcpy(s_GameServ, value); | |
111 | } | |
112 | else if (stricmp(directive, "GSHOST") == 0) | |
113 | { | |
114 | value = strtok(NULL, " "); | |
115 | gshost = new char[strlen(value) + 1]; | |
116 | strcpy(gshost, value); | |
117 | } | |
118 | else if (stricmp(directive, "GSIDENT") == 0) | |
119 | { | |
120 | value = strtok(NULL, " "); | |
121 | gsident = new char[strlen(value) + 1]; | |
122 | strcpy(gsident, value); | |
123 | } | |
124 | else if (stricmp(directive, "SERVERNAME") == 0) | |
125 | { | |
126 | value = strtok(NULL, " "); | |
127 | servername = new char[strlen(value) + 1]; | |
128 | strcpy(servername, value); | |
129 | } | |
130 | else if (stricmp(directive, "C_FOREST") == 0) | |
131 | { | |
132 | value = strtok(NULL, " "); | |
133 | c_Forest = new char[strlen(value) + 1]; | |
134 | strcpy(c_Forest, value); | |
135 | } | |
136 | else if (stricmp(directive, "C_FORESTTOPIC") == 0) | |
137 | { | |
138 | value = strtok(NULL, ""); | |
139 | c_ForestTopic = new char[strlen(value) + 1]; | |
140 | strcpy(c_ForestTopic, value); | |
141 | } | |
142 | else if (stricmp(directive, "REMOTESERVER") == 0) | |
143 | { | |
144 | value = strtok(NULL, " "); | |
145 | remoteserver = new char[strlen(value) + 1]; | |
146 | strcpy(remoteserver, value); | |
147 | } | |
148 | else if (stricmp(directive, "REMOTEPORT") == 0) | |
149 | { | |
150 | value = strtok(NULL, " "); | |
151 | remoteport = new char[strlen(value) + 1]; | |
152 | strcpy(remoteport, value); | |
153 | } | |
154 | else if (stricmp(directive, "REMOTEPASS") == 0) | |
155 | { | |
156 | value = strtok(NULL, ""); | |
157 | remotepass = new char[strlen(value) + 1]; | |
158 | strcpy(remotepass, value); | |
159 | } | |
160 | else if (stricmp(directive, "PLAYERDATA") == 0) | |
161 | { | |
162 | value = strtok(NULL, ""); | |
163 | playerdata = new char[strlen(value) + 1]; | |
164 | strcpy(playerdata, value); | |
165 | } | |
4dde2ed9 | 166 | else if (stricmp(directive, "MONSTERDATA") == 0) |
167 | { | |
168 | value = strtok(NULL, ""); | |
169 | monsterdata = new char[strlen(value) + 1]; | |
170 | strcpy(monsterdata, value); | |
171 | } | |
45a84400 | 172 | else if (stricmp(directive, "ADMINPASS") == 0) |
173 | { | |
174 | value = strtok(NULL, ""); | |
175 | adminpass = new char[strlen(value) + 1]; | |
176 | strcpy(adminpass, value); | |
177 | } | |
922daad7 | 178 | else if (stricmp(directive, "WELCOMEDELAY") == 0) |
bf2cabcd | 179 | { |
180 | value = strtok(NULL, " "); | |
922daad7 | 181 | welcomedelay = stringtoint(value); |
182 | } | |
20d5d721 | 183 | else if (stricmp(directive, "FORESTFIGHTS") == 0) |
184 | { | |
185 | value = strtok(NULL, " "); | |
186 | forestfights = stringtoint(value); | |
187 | } | |
922daad7 | 188 | else if (stricmp(directive, "UPDATEPERIOD") == 0) |
189 | { | |
190 | value = strtok(NULL, " "); | |
191 | updateperiod = stringtoint(value); | |
bf2cabcd | 192 | } |
193 | else if (stricmp(directive, "WELCOMEMSG") == 0) | |
194 | { | |
195 | value = strtok(NULL, ""); | |
196 | welcomemsg = new char[strlen(value) + 1]; | |
197 | strcpy(welcomemsg, value); | |
198 | } | |
85ce9d3e | 199 | else |
200 | { | |
9f8c2acc | 201 | #ifdef DEBUGMODE |
202 | log("Unknown Directive. Buffer: %s", buf); | |
33ac4371 | 203 | cerr << "Unknown " << config << " directive. Buffer: " |
204 | << buf << endl; | |
9f8c2acc | 205 | #endif |
85ce9d3e | 206 | continue; |
207 | } | |
85ce9d3e | 208 | } |
1cf88153 | 209 | delete [] buf; |
85ce9d3e | 210 | infile.close(); |
211 | } |