]>
jfr.im git - irc/gameservirc.git/blob - gameserv/config.cpp
11 int load_config_file(char *config
);
12 void unload_config_file();
14 /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
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
28 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
30 char *remoteserver
; // Server to connect to
31 char *remoteport
; // Port to connect to on remoteserver
32 char *remotepass
; // Password for the server link
34 char *playerdata
; // File to store player data in
35 char *monsterdata
; // File to load monster data from
36 char *pidfile
; // Process ID file
39 char *gsnum
= "[]AAA"; // GameServ Numeric
42 void unload_config_file()
55 delete [] c_ForestTopic
;
57 delete [] remoteserver
;
65 delete [] monsterdata
;
74 int load_config_file(char *config
)
76 char *buf
, *directive
, *value
;
78 #define numdirectives 17
87 DIRECTIVE directives
[numdirectives
];
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";
105 directives
[16].desc
= "PIDFILE - Filename to store the gameserv process ID in";
107 for (int count
= 0; count
< numdirectives
; count
++)
109 directives
[count
].done
= false;
116 log("Error opening %s", config
);
117 cerr
<< "Error opening " << config
<< endl
;
121 buf
= new char[1024];
123 while (infile
.getline(buf
, 1024, '\n'))
126 log("Config file entry buf: %s", buf
);
129 if (buf
[0] == '#' || buf
[0] == ' ' || buf
[0] == '\0' || buf
[0] == '\n' || buf
[0] == '\r')
132 directive
= strtok(buf
, " ");
134 if (stricmp(directive
, "DIE") == 0)
136 value
= strtok(NULL
, "");
137 log("You should read the entire %s file!", config
);
138 cerr
<< "You should read the entire " << config
<< " file!"
143 if (stricmp(directive
, "S_GAMESERV") == 0)
145 value
= strtok(NULL
, " ");
146 s_GameServ
= new char[strlen(value
) + 1];
147 strcpy(s_GameServ
, value
);
148 directives
[0].done
= true;
150 else if (stricmp(directive
, "GSHOST") == 0)
152 value
= strtok(NULL
, " ");
153 gshost
= new char[strlen(value
) + 1];
154 strcpy(gshost
, value
);
155 directives
[1].done
= true;
157 else if (stricmp(directive
, "GSIDENT") == 0)
159 value
= strtok(NULL
, " ");
160 gsident
= new char[strlen(value
) + 1];
161 strcpy(gsident
, value
);
162 directives
[2].done
= true;
164 else if (stricmp(directive
, "SERVERNAME") == 0)
166 value
= strtok(NULL
, " ");
167 servername
= new char[strlen(value
) + 1];
168 strcpy(servername
, value
);
169 directives
[3].done
= true;
171 else if (stricmp(directive
, "C_FOREST") == 0)
173 value
= strtok(NULL
, " ");
174 c_Forest
= new char[strlen(value
) + 1];
175 strcpy(c_Forest
, value
);
176 directives
[4].done
= true;
178 else if (stricmp(directive
, "C_FORESTTOPIC") == 0)
180 value
= strtok(NULL
, "");
181 c_ForestTopic
= new char[strlen(value
) + 1];
182 strcpy(c_ForestTopic
, value
);
183 directives
[5].done
= true;
185 else if (stricmp(directive
, "REMOTESERVER") == 0)
187 value
= strtok(NULL
, " ");
188 remoteserver
= new char[strlen(value
) + 1];
189 strcpy(remoteserver
, value
);
190 directives
[6].done
= true;
192 else if (stricmp(directive
, "REMOTEPORT") == 0)
194 value
= strtok(NULL
, " ");
195 remoteport
= new char[strlen(value
) + 1];
196 strcpy(remoteport
, value
);
197 directives
[7].done
= true;
199 else if (stricmp(directive
, "REMOTEPASS") == 0)
201 value
= strtok(NULL
, "");
202 remotepass
= new char[strlen(value
) + 1];
203 strcpy(remotepass
, value
);
204 directives
[8].done
= true;
206 else if (stricmp(directive
, "PLAYERDATA") == 0)
208 value
= strtok(NULL
, "");
209 playerdata
= new char[strlen(value
) + 1];
210 strcpy(playerdata
, value
);
211 directives
[9].done
= true;
213 else if (stricmp(directive
, "MONSTERDATA") == 0)
215 value
= strtok(NULL
, "");
216 monsterdata
= new char[strlen(value
) + 1];
217 strcpy(monsterdata
, value
);
218 directives
[10].done
= true;
220 else if (stricmp(directive
, "ADMINPASS") == 0)
222 value
= strtok(NULL
, "");
223 adminpass
= new char[strlen(value
) + 1];
224 strcpy(adminpass
, value
);
225 directives
[11].done
= true;
227 else if (stricmp(directive
, "WELCOMEDELAY") == 0)
229 value
= strtok(NULL
, " ");
230 welcomedelay
= stringtoint(value
);
231 directives
[12].done
= true;
233 else if (stricmp(directive
, "FORESTFIGHTS") == 0)
235 value
= strtok(NULL
, " ");
236 forestfights
= stringtoint(value
);
237 directives
[13].done
= true;
239 else if (stricmp(directive
, "UPDATEPERIOD") == 0)
241 value
= strtok(NULL
, " ");
242 updateperiod
= stringtoint(value
);
243 directives
[14].done
= true;
245 else if (stricmp(directive
, "WELCOMEMSG") == 0)
247 value
= strtok(NULL
, "");
248 welcomemsg
= new char[strlen(value
) + 1];
249 strcpy(welcomemsg
, value
);
250 directives
[15].done
= true;
252 else if (stricmp(directive
, "PIDFILE") == 0)
254 value
= strtok(NULL
, " ");
255 pidfile
= new char[strlen(value
) + 1];
256 strcpy(pidfile
, value
);
257 directives
[16].done
= true;
262 log("Unknown Directive. Buffer: %s", buf
);
263 cerr
<< "Unknown " << config
<< " directive. Buffer: "
273 for (int count2
= 0; count2
< numdirectives
; count2
++)
275 if (!directives
[count2
].done
)
277 cerr
<< "Missing config directive: " << directives
[count2
].desc
<< endl
;