]>
Commit | Line | Data |
---|---|---|
85ce9d3e | 1 | #include <fstream.h> |
2 | #include <string.h> | |
20d5d721 | 3 | #include <stdlib.h> |
85ce9d3e | 4 | #include <stdio.h> |
5 | #include "extern.h" | |
6 | ||
7 | void load_config_file(char *config); | |
8 | void unload_config_file(); | |
85ce9d3e | 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 | |
45a84400 | 18 | char *adminpass; // Administrator password |
bf2cabcd | 19 | char *welcomemsg; // Welcome Message |
922daad7 | 20 | int welcomedelay; // Welcome Message Delay |
21 | int updateperiod; // Seconds until another player database update | |
20d5d721 | 22 | int forestfights; // Forest fights per day |
85ce9d3e | 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 | |
4dde2ed9 | 31 | char *monsterdata; // File to load monster data from |
85ce9d3e | 32 | |
33 | void unload_config_file() | |
34 | { | |
35 | if (s_GameServ) | |
1cf88153 | 36 | delete [] s_GameServ; |
85ce9d3e | 37 | if (gshost) |
1cf88153 | 38 | delete [] gshost; |
85ce9d3e | 39 | if (gsident) |
1cf88153 | 40 | delete [] gsident; |
85ce9d3e | 41 | if (servername) |
1cf88153 | 42 | delete [] servername; |
85ce9d3e | 43 | if (c_Forest) |
1cf88153 | 44 | delete [] c_Forest; |
85ce9d3e | 45 | if (c_ForestTopic) |
1cf88153 | 46 | delete [] c_ForestTopic; |
85ce9d3e | 47 | if (remoteserver) |
1cf88153 | 48 | delete [] remoteserver; |
85ce9d3e | 49 | if (remoteport) |
1cf88153 | 50 | delete [] remoteport; |
85ce9d3e | 51 | if (remotepass) |
1cf88153 | 52 | delete [] remotepass; |
85ce9d3e | 53 | if (playerdata) |
1cf88153 | 54 | delete [] playerdata; |
4dde2ed9 | 55 | if (monsterdata) |
56 | delete [] monsterdata; | |
45a84400 | 57 | if (adminpass) |
58 | delete [] adminpass; | |
bf2cabcd | 59 | if (welcomemsg) |
60 | delete [] welcomemsg; | |
85ce9d3e | 61 | } |
bf2cabcd | 62 | |
85ce9d3e | 63 | void load_config_file(char *config) |
64 | { | |
65 | char *buf, *directive, *value; | |
66 | buf = new char[1024]; | |
67 | ||
68 | unload_config_file(); | |
69 | ||
70 | ifstream infile; | |
71 | infile.open(config); | |
72 | if (infile.fail()) | |
73 | { | |
9cc5ab57 | 74 | cout << "Error opening " << config << endl; |
85ce9d3e | 75 | return; |
76 | } | |
77 | ||
78 | while (infile.getline(buf, 1024, '\n')) | |
79 | { | |
80 | cout << "Buf: " << buf << endl; | |
81 | ||
9cc5ab57 | 82 | if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') |
85ce9d3e | 83 | continue; |
84 | ||
85 | directive = strtok(buf, " "); | |
86 | ||
20d5d721 | 87 | if (stricmp(directive, "DIE") == 0) |
88 | { | |
89 | value = strtok(NULL, ""); | |
90 | cerr << value << endl; | |
91 | exit(0); | |
92 | } | |
85ce9d3e | 93 | if (stricmp(directive, "S_GAMESERV") == 0) |
94 | { | |
95 | value = strtok(NULL, " "); | |
96 | s_GameServ = new char[strlen(value) + 1]; | |
97 | strcpy(s_GameServ, value); | |
98 | } | |
99 | else if (stricmp(directive, "GSHOST") == 0) | |
100 | { | |
101 | value = strtok(NULL, " "); | |
102 | gshost = new char[strlen(value) + 1]; | |
103 | strcpy(gshost, value); | |
104 | } | |
105 | else if (stricmp(directive, "GSIDENT") == 0) | |
106 | { | |
107 | value = strtok(NULL, " "); | |
108 | gsident = new char[strlen(value) + 1]; | |
109 | strcpy(gsident, value); | |
110 | } | |
111 | else if (stricmp(directive, "SERVERNAME") == 0) | |
112 | { | |
113 | value = strtok(NULL, " "); | |
114 | servername = new char[strlen(value) + 1]; | |
115 | strcpy(servername, value); | |
116 | } | |
117 | else if (stricmp(directive, "C_FOREST") == 0) | |
118 | { | |
119 | value = strtok(NULL, " "); | |
120 | c_Forest = new char[strlen(value) + 1]; | |
121 | strcpy(c_Forest, value); | |
122 | } | |
123 | else if (stricmp(directive, "C_FORESTTOPIC") == 0) | |
124 | { | |
125 | value = strtok(NULL, ""); | |
126 | c_ForestTopic = new char[strlen(value) + 1]; | |
127 | strcpy(c_ForestTopic, value); | |
128 | } | |
129 | else if (stricmp(directive, "REMOTESERVER") == 0) | |
130 | { | |
131 | value = strtok(NULL, " "); | |
132 | remoteserver = new char[strlen(value) + 1]; | |
133 | strcpy(remoteserver, value); | |
134 | } | |
135 | else if (stricmp(directive, "REMOTEPORT") == 0) | |
136 | { | |
137 | value = strtok(NULL, " "); | |
138 | remoteport = new char[strlen(value) + 1]; | |
139 | strcpy(remoteport, value); | |
140 | } | |
141 | else if (stricmp(directive, "REMOTEPASS") == 0) | |
142 | { | |
143 | value = strtok(NULL, ""); | |
144 | remotepass = new char[strlen(value) + 1]; | |
145 | strcpy(remotepass, value); | |
146 | } | |
147 | else if (stricmp(directive, "PLAYERDATA") == 0) | |
148 | { | |
149 | value = strtok(NULL, ""); | |
150 | playerdata = new char[strlen(value) + 1]; | |
151 | strcpy(playerdata, value); | |
152 | } | |
4dde2ed9 | 153 | else if (stricmp(directive, "MONSTERDATA") == 0) |
154 | { | |
155 | value = strtok(NULL, ""); | |
156 | monsterdata = new char[strlen(value) + 1]; | |
157 | strcpy(monsterdata, value); | |
158 | } | |
45a84400 | 159 | else if (stricmp(directive, "ADMINPASS") == 0) |
160 | { | |
161 | value = strtok(NULL, ""); | |
162 | adminpass = new char[strlen(value) + 1]; | |
163 | strcpy(adminpass, value); | |
164 | } | |
922daad7 | 165 | else if (stricmp(directive, "WELCOMEDELAY") == 0) |
bf2cabcd | 166 | { |
167 | value = strtok(NULL, " "); | |
922daad7 | 168 | welcomedelay = stringtoint(value); |
169 | } | |
20d5d721 | 170 | else if (stricmp(directive, "FORESTFIGHTS") == 0) |
171 | { | |
172 | value = strtok(NULL, " "); | |
173 | forestfights = stringtoint(value); | |
174 | } | |
922daad7 | 175 | else if (stricmp(directive, "UPDATEPERIOD") == 0) |
176 | { | |
177 | value = strtok(NULL, " "); | |
178 | updateperiod = stringtoint(value); | |
bf2cabcd | 179 | } |
180 | else if (stricmp(directive, "WELCOMEMSG") == 0) | |
181 | { | |
182 | value = strtok(NULL, ""); | |
183 | welcomemsg = new char[strlen(value) + 1]; | |
184 | strcpy(welcomemsg, value); | |
185 | } | |
85ce9d3e | 186 | else |
187 | { | |
9cc5ab57 | 188 | cout << "Unknown Directive. Buffer: " << buf << endl; |
85ce9d3e | 189 | continue; |
190 | } | |
85ce9d3e | 191 | } |
1cf88153 | 192 | delete [] buf; |
85ce9d3e | 193 | infile.close(); |
194 | } |