]> jfr.im git - irc/gameservirc.git/blob - gameserv/config.cpp
Made config.cpp output errors now that it's a true daemon!
[irc/gameservirc.git] / gameserv / config.cpp
1 #include <fstream>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include "extern.h"
6
7 using std::ifstream;
8 using std::cerr;
9 using std::endl;
10
11 void load_config_file(char *config);
12 void unload_config_file();
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
22 char *adminpass; // Administrator password
23 char *welcomemsg; // Welcome Message
24 int welcomedelay; // Welcome Message Delay
25 int updateperiod; // Seconds until another player database update
26 int forestfights; // Forest fights per day
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
35 char *monsterdata; // File to load monster data from
36
37 #if defined(P10)
38 char *gsnum = "[]AAA"; // GameServ Numeric
39 #endif
40
41 void unload_config_file()
42 {
43 if (s_GameServ)
44 delete [] s_GameServ;
45 if (gshost)
46 delete [] gshost;
47 if (gsident)
48 delete [] gsident;
49 if (servername)
50 delete [] servername;
51 if (c_Forest)
52 delete [] c_Forest;
53 if (c_ForestTopic)
54 delete [] c_ForestTopic;
55 if (remoteserver)
56 delete [] remoteserver;
57 if (remoteport)
58 delete [] remoteport;
59 if (remotepass)
60 delete [] remotepass;
61 if (playerdata)
62 delete [] playerdata;
63 if (monsterdata)
64 delete [] monsterdata;
65 if (adminpass)
66 delete [] adminpass;
67 if (welcomemsg)
68 delete [] welcomemsg;
69 }
70
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 {
82 log("Error opening %s", config);
83 cerr << "Error opening " << config << endl;
84 return;
85 }
86
87 while (infile.getline(buf, 1024, '\n'))
88 {
89 #ifdef DEBUGMODE
90 log("Config file entry buf: %s", buf);
91 #endif
92
93 if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r')
94 continue;
95
96 directive = strtok(buf, " ");
97
98 if (stricmp(directive, "DIE") == 0)
99 {
100 value = strtok(NULL, "");
101 log("You should read the entire %s file!", config);
102 cerr << "You should read the entire " << config << " file!"
103 << endl;
104 exit(0);
105 }
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 }
166 else if (stricmp(directive, "MONSTERDATA") == 0)
167 {
168 value = strtok(NULL, "");
169 monsterdata = new char[strlen(value) + 1];
170 strcpy(monsterdata, value);
171 }
172 else if (stricmp(directive, "ADMINPASS") == 0)
173 {
174 value = strtok(NULL, "");
175 adminpass = new char[strlen(value) + 1];
176 strcpy(adminpass, value);
177 }
178 else if (stricmp(directive, "WELCOMEDELAY") == 0)
179 {
180 value = strtok(NULL, " ");
181 welcomedelay = stringtoint(value);
182 }
183 else if (stricmp(directive, "FORESTFIGHTS") == 0)
184 {
185 value = strtok(NULL, " ");
186 forestfights = stringtoint(value);
187 }
188 else if (stricmp(directive, "UPDATEPERIOD") == 0)
189 {
190 value = strtok(NULL, " ");
191 updateperiod = stringtoint(value);
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 }
199 else
200 {
201 #ifdef DEBUGMODE
202 log("Unknown Directive. Buffer: %s", buf);
203 cerr << "Unknown " << config << " directive. Buffer: "
204 << buf << endl;
205 #endif
206 continue;
207 }
208 }
209 delete [] buf;
210 infile.close();
211 }