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