]> jfr.im git - irc/gameservirc.git/blob - gameserv/config.cpp
Added a lot of functionality. Added player flags and save/load them in the players...
[irc/gameservirc.git] / gameserv / config.cpp
1 #include <fstream.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include "extern.h"
5
6 void load_config_file(char *config);
7 void unload_config_file();
8
9 /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
10
11 char *s_GameServ; // GameServ's nickname
12 char *gshost; // GameServ's Hostname
13 char *gsident; // GameServ's ident/username
14 char *servername; // GameServ's Server
15 char *c_Forest; // Forest channel
16 char *c_ForestTopic; // Forest Channel Topic
17 char *adminpass; // Administrator password
18
19
20 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
21 // to a real ircd.
22 char *remoteserver; // Server to connect to
23 char *remoteport; // Port to connect to on remoteserver
24 char *remotepass; // Password for the server link
25
26 char *playerdata; // File to store player data in
27
28 void unload_config_file()
29 {
30 if (s_GameServ)
31 delete [] s_GameServ;
32 if (gshost)
33 delete [] gshost;
34 if (gsident)
35 delete [] gsident;
36 if (servername)
37 delete [] servername;
38 if (c_Forest)
39 delete [] c_Forest;
40 if (c_ForestTopic)
41 delete [] c_ForestTopic;
42 if (remoteserver)
43 delete [] remoteserver;
44 if (remoteport)
45 delete [] remoteport;
46 if (remotepass)
47 delete [] remotepass;
48 if (playerdata)
49 delete [] playerdata;
50 if (adminpass)
51 delete [] adminpass;
52 }
53 void load_config_file(char *config)
54 {
55 char *buf, *directive, *value;
56 buf = new char[1024];
57
58 unload_config_file();
59
60 ifstream infile;
61 infile.open(config);
62 if (infile.fail())
63 {
64 cout << "Error opening " << config << endl;
65 return;
66 }
67
68 while (infile.getline(buf, 1024, '\n'))
69 {
70 cout << "Buf: " << buf << endl;
71
72 if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r')
73 continue;
74
75 directive = strtok(buf, " ");
76
77 if (stricmp(directive, "S_GAMESERV") == 0)
78 {
79 value = strtok(NULL, " ");
80 s_GameServ = new char[strlen(value) + 1];
81 strcpy(s_GameServ, value);
82 }
83 else if (stricmp(directive, "GSHOST") == 0)
84 {
85 value = strtok(NULL, " ");
86 gshost = new char[strlen(value) + 1];
87 strcpy(gshost, value);
88 }
89 else if (stricmp(directive, "GSIDENT") == 0)
90 {
91 value = strtok(NULL, " ");
92 gsident = new char[strlen(value) + 1];
93 strcpy(gsident, value);
94 }
95 else if (stricmp(directive, "SERVERNAME") == 0)
96 {
97 value = strtok(NULL, " ");
98 servername = new char[strlen(value) + 1];
99 strcpy(servername, value);
100 }
101 else if (stricmp(directive, "C_FOREST") == 0)
102 {
103 value = strtok(NULL, " ");
104 c_Forest = new char[strlen(value) + 1];
105 strcpy(c_Forest, value);
106 }
107 else if (stricmp(directive, "C_FORESTTOPIC") == 0)
108 {
109 value = strtok(NULL, "");
110 c_ForestTopic = new char[strlen(value) + 1];
111 strcpy(c_ForestTopic, value);
112 }
113 else if (stricmp(directive, "REMOTESERVER") == 0)
114 {
115 value = strtok(NULL, " ");
116 remoteserver = new char[strlen(value) + 1];
117 strcpy(remoteserver, value);
118 }
119 else if (stricmp(directive, "REMOTEPORT") == 0)
120 {
121 value = strtok(NULL, " ");
122 remoteport = new char[strlen(value) + 1];
123 strcpy(remoteport, value);
124 }
125 else if (stricmp(directive, "REMOTEPASS") == 0)
126 {
127 value = strtok(NULL, "");
128 remotepass = new char[strlen(value) + 1];
129 strcpy(remotepass, value);
130 }
131 else if (stricmp(directive, "PLAYERDATA") == 0)
132 {
133 value = strtok(NULL, "");
134 playerdata = new char[strlen(value) + 1];
135 strcpy(playerdata, value);
136 }
137 else if (stricmp(directive, "ADMINPASS") == 0)
138 {
139 value = strtok(NULL, "");
140 adminpass = new char[strlen(value) + 1];
141 strcpy(adminpass, value);
142 }
143 else
144 {
145 cout << "Unknown Directive. Buffer: " << buf << endl;
146 continue;
147 }
148 }
149 delete [] buf;
150 infile.close();
151 }