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