]>
Commit | Line | Data |
---|---|---|
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 | ||
9 | void load_config_file(char *config); | |
10 | void unload_config_file(); | |
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 | |
20 | char *adminpass; // Administrator password | |
21 | char *welcomemsg; // Welcome Message | |
22 | int welcomedelay; // Welcome Message Delay | |
23 | int updateperiod; // Seconds until another player database update | |
24 | int forestfights; // Forest fights per day | |
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 | |
33 | char *monsterdata; // File to load monster data from | |
34 | ||
35 | #if defined(P10) | |
36 | char *gsnum = "[]AAA"; // GameServ Numeric | |
37 | #endif | |
38 | ||
39 | void unload_config_file() | |
40 | { | |
41 | if (s_GameServ) | |
42 | delete [] s_GameServ; | |
43 | if (gshost) | |
44 | delete [] gshost; | |
45 | if (gsident) | |
46 | delete [] gsident; | |
47 | if (servername) | |
48 | delete [] servername; | |
49 | if (c_Forest) | |
50 | delete [] c_Forest; | |
51 | if (c_ForestTopic) | |
52 | delete [] c_ForestTopic; | |
53 | if (remoteserver) | |
54 | delete [] remoteserver; | |
55 | if (remoteport) | |
56 | delete [] remoteport; | |
57 | if (remotepass) | |
58 | delete [] remotepass; | |
59 | if (playerdata) | |
60 | delete [] playerdata; | |
61 | if (monsterdata) | |
62 | delete [] monsterdata; | |
63 | if (adminpass) | |
64 | delete [] adminpass; | |
65 | if (welcomemsg) | |
66 | delete [] welcomemsg; | |
67 | } | |
68 | ||
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 | { | |
80 | log("Error opening %s", config); | |
81 | return; | |
82 | } | |
83 | ||
84 | while (infile.getline(buf, 1024, '\n')) | |
85 | { | |
86 | #ifdef DEBUGMODE | |
87 | log("Buf: %s", buf); | |
88 | #endif | |
89 | ||
90 | if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') | |
91 | continue; | |
92 | ||
93 | directive = strtok(buf, " "); | |
94 | ||
95 | if (stricmp(directive, "DIE") == 0) | |
96 | { | |
97 | value = strtok(NULL, ""); | |
98 | log("You should read the entire %s file!", config); | |
99 | exit(0); | |
100 | } | |
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 | } | |
161 | else if (stricmp(directive, "MONSTERDATA") == 0) | |
162 | { | |
163 | value = strtok(NULL, ""); | |
164 | monsterdata = new char[strlen(value) + 1]; | |
165 | strcpy(monsterdata, value); | |
166 | } | |
167 | else if (stricmp(directive, "ADMINPASS") == 0) | |
168 | { | |
169 | value = strtok(NULL, ""); | |
170 | adminpass = new char[strlen(value) + 1]; | |
171 | strcpy(adminpass, value); | |
172 | } | |
173 | else if (stricmp(directive, "WELCOMEDELAY") == 0) | |
174 | { | |
175 | value = strtok(NULL, " "); | |
176 | welcomedelay = stringtoint(value); | |
177 | } | |
178 | else if (stricmp(directive, "FORESTFIGHTS") == 0) | |
179 | { | |
180 | value = strtok(NULL, " "); | |
181 | forestfights = stringtoint(value); | |
182 | } | |
183 | else if (stricmp(directive, "UPDATEPERIOD") == 0) | |
184 | { | |
185 | value = strtok(NULL, " "); | |
186 | updateperiod = stringtoint(value); | |
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 | } | |
194 | else | |
195 | { | |
196 | #ifdef DEBUGMODE | |
197 | log("Unknown Directive. Buffer: %s", buf); | |
198 | #endif | |
199 | continue; | |
200 | } | |
201 | } | |
202 | delete [] buf; | |
203 | infile.close(); | |
204 | } |