]> jfr.im git - irc/gameservirc.git/blame - gameserv/config.cpp
Added ONE monster lol
[irc/gameservirc.git] / gameserv / config.cpp
CommitLineData
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 7using std::ifstream;
33ac4371 8using std::cerr;
9using std::endl;
fb37ecc7 10
624c0352 11int load_config_file(char *config);
85ce9d3e 12void unload_config_file();
85ce9d3e 13
14/* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
15
16char *s_GameServ; // GameServ's nickname
17char *gshost; // GameServ's Hostname
18char *gsident; // GameServ's ident/username
19char *servername; // GameServ's Server
20char *c_Forest; // Forest channel
21char *c_ForestTopic; // Forest Channel Topic
45a84400 22char *adminpass; // Administrator password
bf2cabcd 23char *welcomemsg; // Welcome Message
922daad7 24int welcomedelay; // Welcome Message Delay
25int updateperiod; // Seconds until another player database update
20d5d721 26int 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.
30char *remoteserver; // Server to connect to
31char *remoteport; // Port to connect to on remoteserver
32char *remotepass; // Password for the server link
33
34char *playerdata; // File to store player data in
4dde2ed9 35char *monsterdata; // File to load monster data from
69ae096c 36char *pidfile; // Process ID file
85ce9d3e 37
e1c41a84 38#if defined(P10)
39 char *gsnum = "[]AAA"; // GameServ Numeric
40#endif
41
85ce9d3e 42void unload_config_file()
43{
44 if (s_GameServ)
1cf88153 45 delete [] s_GameServ;
85ce9d3e 46 if (gshost)
1cf88153 47 delete [] gshost;
85ce9d3e 48 if (gsident)
1cf88153 49 delete [] gsident;
85ce9d3e 50 if (servername)
1cf88153 51 delete [] servername;
85ce9d3e 52 if (c_Forest)
1cf88153 53 delete [] c_Forest;
85ce9d3e 54 if (c_ForestTopic)
1cf88153 55 delete [] c_ForestTopic;
85ce9d3e 56 if (remoteserver)
1cf88153 57 delete [] remoteserver;
85ce9d3e 58 if (remoteport)
1cf88153 59 delete [] remoteport;
85ce9d3e 60 if (remotepass)
1cf88153 61 delete [] remotepass;
85ce9d3e 62 if (playerdata)
1cf88153 63 delete [] playerdata;
4dde2ed9 64 if (monsterdata)
65 delete [] monsterdata;
45a84400 66 if (adminpass)
67 delete [] adminpass;
bf2cabcd 68 if (welcomemsg)
69 delete [] welcomemsg;
69ae096c 70 if (pidfile)
71 delete [] pidfile;
85ce9d3e 72}
bf2cabcd 73
624c0352 74int load_config_file(char *config)
85ce9d3e 75{
76 char *buf, *directive, *value;
69ae096c 77
78 #define numdirectives 17
85ce9d3e 79
80 unload_config_file();
81
1e1b5312 82 struct DIRECTIVE {
83 bool done;
84 char *desc;
85 };
86
87 DIRECTIVE directives[numdirectives];
88
89 directives[0].desc = "s_GameServ - GameServ Nickname";
90 directives[1].desc = "GSHOST - GameServ Hostname";
91 directives[2].desc = "GSIDENT - GameServ Ident";
92 directives[3].desc = "SERVERNAME - Pseudo Server's Name";
93 directives[4].desc = "C_FOREST - Forest Channel";
94 directives[5].desc = "C_FORESTTOPIC - Topic for the Forest Channel";
95 directives[6].desc = "REMOTESERVER - Server for gameserv to connect to (ip or hostname)";
96 directives[7].desc = "REMOTEPORT - Port on the remote server to connect to";
97 directives[8].desc = "REMOTEPASS - Password on the remote server";
98 directives[9].desc = "PLAYERDATA - File to store the player saves in";
99 directives[10].desc = "MONSTERDATA - File to load the monsters from";
100 directives[11].desc = "ADMINPASS - Password to identify as an admin with";
101 directives[12].desc = "WELCOMEDELAY - Delay (in seconds) to wait before welcoming new users to the network";
102 directives[13].desc = "FORESTFIGHTS - Number of forest fights players get every day";
103 directives[14].desc = "UPDATEPERIOD - Number of seconds between every player data save";
104 directives[15].desc = "WELCOMEMSG - Message to send to new users on the network";
69ae096c 105 directives[16].desc = "PIDFILE - Filename to store the gameserv process ID in";
1e1b5312 106
107 for (int count = 0; count < numdirectives; count++)
108 {
109 directives[count].done = false;
110 }
111
85ce9d3e 112 ifstream infile;
113 infile.open(config);
114 if (infile.fail())
115 {
fb37ecc7 116 log("Error opening %s", config);
33ac4371 117 cerr << "Error opening " << config << endl;
624c0352 118 return 0;
85ce9d3e 119 }
120
1e1b5312 121 buf = new char[1024];
122
85ce9d3e 123 while (infile.getline(buf, 1024, '\n'))
124 {
9f8c2acc 125 #ifdef DEBUGMODE
33ac4371 126 log("Config file entry buf: %s", buf);
9f8c2acc 127 #endif
85ce9d3e 128
9cc5ab57 129 if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r')
85ce9d3e 130 continue;
131
132 directive = strtok(buf, " ");
133
20d5d721 134 if (stricmp(directive, "DIE") == 0)
135 {
136 value = strtok(NULL, "");
fb37ecc7 137 log("You should read the entire %s file!", config);
33ac4371 138 cerr << "You should read the entire " << config << " file!"
139 << endl;
1e1b5312 140 delete []buf;
20d5d721 141 exit(0);
142 }
85ce9d3e 143 if (stricmp(directive, "S_GAMESERV") == 0)
144 {
145 value = strtok(NULL, " ");
146 s_GameServ = new char[strlen(value) + 1];
147 strcpy(s_GameServ, value);
1e1b5312 148 directives[0].done = true;
85ce9d3e 149 }
150 else if (stricmp(directive, "GSHOST") == 0)
151 {
152 value = strtok(NULL, " ");
153 gshost = new char[strlen(value) + 1];
154 strcpy(gshost, value);
1e1b5312 155 directives[1].done = true;
85ce9d3e 156 }
157 else if (stricmp(directive, "GSIDENT") == 0)
158 {
159 value = strtok(NULL, " ");
160 gsident = new char[strlen(value) + 1];
161 strcpy(gsident, value);
1e1b5312 162 directives[2].done = true;
85ce9d3e 163 }
164 else if (stricmp(directive, "SERVERNAME") == 0)
165 {
166 value = strtok(NULL, " ");
167 servername = new char[strlen(value) + 1];
168 strcpy(servername, value);
1e1b5312 169 directives[3].done = true;
85ce9d3e 170 }
171 else if (stricmp(directive, "C_FOREST") == 0)
172 {
173 value = strtok(NULL, " ");
174 c_Forest = new char[strlen(value) + 1];
175 strcpy(c_Forest, value);
1e1b5312 176 directives[4].done = true;
85ce9d3e 177 }
178 else if (stricmp(directive, "C_FORESTTOPIC") == 0)
179 {
180 value = strtok(NULL, "");
181 c_ForestTopic = new char[strlen(value) + 1];
182 strcpy(c_ForestTopic, value);
1e1b5312 183 directives[5].done = true;
85ce9d3e 184 }
185 else if (stricmp(directive, "REMOTESERVER") == 0)
186 {
187 value = strtok(NULL, " ");
188 remoteserver = new char[strlen(value) + 1];
189 strcpy(remoteserver, value);
1e1b5312 190 directives[6].done = true;
85ce9d3e 191 }
192 else if (stricmp(directive, "REMOTEPORT") == 0)
193 {
194 value = strtok(NULL, " ");
195 remoteport = new char[strlen(value) + 1];
196 strcpy(remoteport, value);
1e1b5312 197 directives[7].done = true;
85ce9d3e 198 }
199 else if (stricmp(directive, "REMOTEPASS") == 0)
200 {
201 value = strtok(NULL, "");
202 remotepass = new char[strlen(value) + 1];
203 strcpy(remotepass, value);
1e1b5312 204 directives[8].done = true;
85ce9d3e 205 }
206 else if (stricmp(directive, "PLAYERDATA") == 0)
207 {
208 value = strtok(NULL, "");
209 playerdata = new char[strlen(value) + 1];
210 strcpy(playerdata, value);
1e1b5312 211 directives[9].done = true;
85ce9d3e 212 }
4dde2ed9 213 else if (stricmp(directive, "MONSTERDATA") == 0)
214 {
215 value = strtok(NULL, "");
216 monsterdata = new char[strlen(value) + 1];
217 strcpy(monsterdata, value);
1e1b5312 218 directives[10].done = true;
4dde2ed9 219 }
45a84400 220 else if (stricmp(directive, "ADMINPASS") == 0)
221 {
222 value = strtok(NULL, "");
223 adminpass = new char[strlen(value) + 1];
224 strcpy(adminpass, value);
1e1b5312 225 directives[11].done = true;
45a84400 226 }
922daad7 227 else if (stricmp(directive, "WELCOMEDELAY") == 0)
bf2cabcd 228 {
229 value = strtok(NULL, " ");
922daad7 230 welcomedelay = stringtoint(value);
1e1b5312 231 directives[12].done = true;
922daad7 232 }
20d5d721 233 else if (stricmp(directive, "FORESTFIGHTS") == 0)
234 {
235 value = strtok(NULL, " ");
236 forestfights = stringtoint(value);
1e1b5312 237 directives[13].done = true;
20d5d721 238 }
922daad7 239 else if (stricmp(directive, "UPDATEPERIOD") == 0)
240 {
241 value = strtok(NULL, " ");
242 updateperiod = stringtoint(value);
1e1b5312 243 directives[14].done = true;
bf2cabcd 244 }
245 else if (stricmp(directive, "WELCOMEMSG") == 0)
246 {
247 value = strtok(NULL, "");
248 welcomemsg = new char[strlen(value) + 1];
249 strcpy(welcomemsg, value);
1e1b5312 250 directives[15].done = true;
bf2cabcd 251 }
69ae096c 252 else if (stricmp(directive, "PIDFILE") == 0)
253 {
254 value = strtok(NULL, " ");
255 pidfile = new char[strlen(value) + 1];
256 strcpy(pidfile, value);
257 directives[16].done = true;
258 }
85ce9d3e 259 else
260 {
9f8c2acc 261 #ifdef DEBUGMODE
262 log("Unknown Directive. Buffer: %s", buf);
33ac4371 263 cerr << "Unknown " << config << " directive. Buffer: "
264 << buf << endl;
9f8c2acc 265 #endif
85ce9d3e 266 continue;
267 }
85ce9d3e 268 }
1cf88153 269delete [] buf;
85ce9d3e 270infile.close();
1e1b5312 271
272 int nonemissing = 1;
273 for (int count2 = 0; count2 < numdirectives; count2++)
274 {
275 if (!directives[count2].done)
276 {
277 cerr << "Missing config directive: " << directives[count2].desc << endl;
278 nonemissing = 0;
279 }
280 }
281
282 return nonemissing;
85ce9d3e 283}