]> jfr.im git - irc/gameservirc.git/blob - gameserv/config.cpp
Now saving inventory to players.dat. Updates made in an attempt to use old databases.
[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
33 void unload_config_file()
34 {
35 if (s_GameServ)
36 delete [] s_GameServ;
37 if (gshost)
38 delete [] gshost;
39 if (gsident)
40 delete [] gsident;
41 if (servername)
42 delete [] servername;
43 if (c_Forest)
44 delete [] c_Forest;
45 if (c_ForestTopic)
46 delete [] c_ForestTopic;
47 if (remoteserver)
48 delete [] remoteserver;
49 if (remoteport)
50 delete [] remoteport;
51 if (remotepass)
52 delete [] remotepass;
53 if (playerdata)
54 delete [] playerdata;
55 if (monsterdata)
56 delete [] monsterdata;
57 if (adminpass)
58 delete [] adminpass;
59 if (welcomemsg)
60 delete [] welcomemsg;
61 }
62
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 {
74 cout << "Error opening " << config << endl;
75 return;
76 }
77
78 while (infile.getline(buf, 1024, '\n'))
79 {
80 cout << "Buf: " << buf << endl;
81
82 if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r')
83 continue;
84
85 directive = strtok(buf, " ");
86
87 if (stricmp(directive, "DIE") == 0)
88 {
89 value = strtok(NULL, "");
90 cerr << value << endl;
91 exit(0);
92 }
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 }
153 else if (stricmp(directive, "MONSTERDATA") == 0)
154 {
155 value = strtok(NULL, "");
156 monsterdata = new char[strlen(value) + 1];
157 strcpy(monsterdata, value);
158 }
159 else if (stricmp(directive, "ADMINPASS") == 0)
160 {
161 value = strtok(NULL, "");
162 adminpass = new char[strlen(value) + 1];
163 strcpy(adminpass, value);
164 }
165 else if (stricmp(directive, "WELCOMEDELAY") == 0)
166 {
167 value = strtok(NULL, " ");
168 welcomedelay = stringtoint(value);
169 }
170 else if (stricmp(directive, "FORESTFIGHTS") == 0)
171 {
172 value = strtok(NULL, " ");
173 forestfights = stringtoint(value);
174 }
175 else if (stricmp(directive, "UPDATEPERIOD") == 0)
176 {
177 value = strtok(NULL, " ");
178 updateperiod = stringtoint(value);
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 }
186 else
187 {
188 cout << "Unknown Directive. Buffer: " << buf << endl;
189 continue;
190 }
191 }
192 delete [] buf;
193 infile.close();
194 }