]>
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 | |
35 | void unload_config_file() | |
36 | { | |
37 | if (s_GameServ) | |
1cf88153 | 38 | delete [] s_GameServ; |
85ce9d3e | 39 | if (gshost) |
1cf88153 | 40 | delete [] gshost; |
85ce9d3e | 41 | if (gsident) |
1cf88153 | 42 | delete [] gsident; |
85ce9d3e | 43 | if (servername) |
1cf88153 | 44 | delete [] servername; |
85ce9d3e | 45 | if (c_Forest) |
1cf88153 | 46 | delete [] c_Forest; |
85ce9d3e | 47 | if (c_ForestTopic) |
1cf88153 | 48 | delete [] c_ForestTopic; |
85ce9d3e | 49 | if (remoteserver) |
1cf88153 | 50 | delete [] remoteserver; |
85ce9d3e | 51 | if (remoteport) |
1cf88153 | 52 | delete [] remoteport; |
85ce9d3e | 53 | if (remotepass) |
1cf88153 | 54 | delete [] remotepass; |
85ce9d3e | 55 | if (playerdata) |
1cf88153 | 56 | delete [] playerdata; |
4dde2ed9 | 57 | if (monsterdata) |
58 | delete [] monsterdata; | |
45a84400 | 59 | if (adminpass) |
60 | delete [] adminpass; | |
bf2cabcd | 61 | if (welcomemsg) |
62 | delete [] welcomemsg; | |
85ce9d3e | 63 | } |
bf2cabcd | 64 | |
85ce9d3e | 65 | void load_config_file(char *config) |
66 | { | |
67 | char *buf, *directive, *value; | |
68 | buf = new char[1024]; | |
69 | ||
70 | unload_config_file(); | |
71 | ||
72 | ifstream infile; | |
73 | infile.open(config); | |
74 | if (infile.fail()) | |
75 | { | |
fb37ecc7 | 76 | log("Error opening %s", config); |
85ce9d3e | 77 | return; |
78 | } | |
79 | ||
80 | while (infile.getline(buf, 1024, '\n')) | |
81 | { | |
9f8c2acc | 82 | #ifdef DEBUGMODE |
83 | log("Buf: %s", buf); | |
84 | #endif | |
85ce9d3e | 85 | |
9cc5ab57 | 86 | if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') |
85ce9d3e | 87 | continue; |
88 | ||
89 | directive = strtok(buf, " "); | |
90 | ||
20d5d721 | 91 | if (stricmp(directive, "DIE") == 0) |
92 | { | |
93 | value = strtok(NULL, ""); | |
fb37ecc7 | 94 | log("You should read the entire %s file!", config); |
20d5d721 | 95 | exit(0); |
96 | } | |
85ce9d3e | 97 | if (stricmp(directive, "S_GAMESERV") == 0) |
98 | { | |
99 | value = strtok(NULL, " "); | |
100 | s_GameServ = new char[strlen(value) + 1]; | |
101 | strcpy(s_GameServ, value); | |
102 | } | |
103 | else if (stricmp(directive, "GSHOST") == 0) | |
104 | { | |
105 | value = strtok(NULL, " "); | |
106 | gshost = new char[strlen(value) + 1]; | |
107 | strcpy(gshost, value); | |
108 | } | |
109 | else if (stricmp(directive, "GSIDENT") == 0) | |
110 | { | |
111 | value = strtok(NULL, " "); | |
112 | gsident = new char[strlen(value) + 1]; | |
113 | strcpy(gsident, value); | |
114 | } | |
115 | else if (stricmp(directive, "SERVERNAME") == 0) | |
116 | { | |
117 | value = strtok(NULL, " "); | |
118 | servername = new char[strlen(value) + 1]; | |
119 | strcpy(servername, value); | |
120 | } | |
121 | else if (stricmp(directive, "C_FOREST") == 0) | |
122 | { | |
123 | value = strtok(NULL, " "); | |
124 | c_Forest = new char[strlen(value) + 1]; | |
125 | strcpy(c_Forest, value); | |
126 | } | |
127 | else if (stricmp(directive, "C_FORESTTOPIC") == 0) | |
128 | { | |
129 | value = strtok(NULL, ""); | |
130 | c_ForestTopic = new char[strlen(value) + 1]; | |
131 | strcpy(c_ForestTopic, value); | |
132 | } | |
133 | else if (stricmp(directive, "REMOTESERVER") == 0) | |
134 | { | |
135 | value = strtok(NULL, " "); | |
136 | remoteserver = new char[strlen(value) + 1]; | |
137 | strcpy(remoteserver, value); | |
138 | } | |
139 | else if (stricmp(directive, "REMOTEPORT") == 0) | |
140 | { | |
141 | value = strtok(NULL, " "); | |
142 | remoteport = new char[strlen(value) + 1]; | |
143 | strcpy(remoteport, value); | |
144 | } | |
145 | else if (stricmp(directive, "REMOTEPASS") == 0) | |
146 | { | |
147 | value = strtok(NULL, ""); | |
148 | remotepass = new char[strlen(value) + 1]; | |
149 | strcpy(remotepass, value); | |
150 | } | |
151 | else if (stricmp(directive, "PLAYERDATA") == 0) | |
152 | { | |
153 | value = strtok(NULL, ""); | |
154 | playerdata = new char[strlen(value) + 1]; | |
155 | strcpy(playerdata, value); | |
156 | } | |
4dde2ed9 | 157 | else if (stricmp(directive, "MONSTERDATA") == 0) |
158 | { | |
159 | value = strtok(NULL, ""); | |
160 | monsterdata = new char[strlen(value) + 1]; | |
161 | strcpy(monsterdata, value); | |
162 | } | |
45a84400 | 163 | else if (stricmp(directive, "ADMINPASS") == 0) |
164 | { | |
165 | value = strtok(NULL, ""); | |
166 | adminpass = new char[strlen(value) + 1]; | |
167 | strcpy(adminpass, value); | |
168 | } | |
922daad7 | 169 | else if (stricmp(directive, "WELCOMEDELAY") == 0) |
bf2cabcd | 170 | { |
171 | value = strtok(NULL, " "); | |
922daad7 | 172 | welcomedelay = stringtoint(value); |
173 | } | |
20d5d721 | 174 | else if (stricmp(directive, "FORESTFIGHTS") == 0) |
175 | { | |
176 | value = strtok(NULL, " "); | |
177 | forestfights = stringtoint(value); | |
178 | } | |
922daad7 | 179 | else if (stricmp(directive, "UPDATEPERIOD") == 0) |
180 | { | |
181 | value = strtok(NULL, " "); | |
182 | updateperiod = stringtoint(value); | |
bf2cabcd | 183 | } |
184 | else if (stricmp(directive, "WELCOMEMSG") == 0) | |
185 | { | |
186 | value = strtok(NULL, ""); | |
187 | welcomemsg = new char[strlen(value) + 1]; | |
188 | strcpy(welcomemsg, value); | |
189 | } | |
85ce9d3e | 190 | else |
191 | { | |
9f8c2acc | 192 | #ifdef DEBUGMODE |
193 | log("Unknown Directive. Buffer: %s", buf); | |
194 | #endif | |
85ce9d3e | 195 | continue; |
196 | } | |
85ce9d3e | 197 | } |
1cf88153 | 198 | delete [] buf; |
85ce9d3e | 199 | infile.close(); |
200 | } |