]>
Commit | Line | Data |
---|---|---|
85ce9d3e | 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(); | |
85ce9d3e | 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 | |
45a84400 | 17 | char *adminpass; // Administrator password |
85ce9d3e | 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) | |
1cf88153 | 31 | delete [] s_GameServ; |
85ce9d3e | 32 | if (gshost) |
1cf88153 | 33 | delete [] gshost; |
85ce9d3e | 34 | if (gsident) |
1cf88153 | 35 | delete [] gsident; |
85ce9d3e | 36 | if (servername) |
1cf88153 | 37 | delete [] servername; |
85ce9d3e | 38 | if (c_Forest) |
1cf88153 | 39 | delete [] c_Forest; |
85ce9d3e | 40 | if (c_ForestTopic) |
1cf88153 | 41 | delete [] c_ForestTopic; |
85ce9d3e | 42 | if (remoteserver) |
1cf88153 | 43 | delete [] remoteserver; |
85ce9d3e | 44 | if (remoteport) |
1cf88153 | 45 | delete [] remoteport; |
85ce9d3e | 46 | if (remotepass) |
1cf88153 | 47 | delete [] remotepass; |
85ce9d3e | 48 | if (playerdata) |
1cf88153 | 49 | delete [] playerdata; |
45a84400 | 50 | if (adminpass) |
51 | delete [] adminpass; | |
85ce9d3e | 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 | { | |
9cc5ab57 | 64 | cout << "Error opening " << config << endl; |
85ce9d3e | 65 | return; |
66 | } | |
67 | ||
68 | while (infile.getline(buf, 1024, '\n')) | |
69 | { | |
70 | cout << "Buf: " << buf << endl; | |
71 | ||
9cc5ab57 | 72 | if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') |
85ce9d3e | 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 | } | |
45a84400 | 137 | else if (stricmp(directive, "ADMINPASS") == 0) |
138 | { | |
139 | value = strtok(NULL, ""); | |
140 | adminpass = new char[strlen(value) + 1]; | |
141 | strcpy(adminpass, value); | |
142 | } | |
85ce9d3e | 143 | else |
144 | { | |
9cc5ab57 | 145 | cout << "Unknown Directive. Buffer: " << buf << endl; |
85ce9d3e | 146 | continue; |
147 | } | |
85ce9d3e | 148 | } |
1cf88153 | 149 | delete [] buf; |
85ce9d3e | 150 | infile.close(); |
151 | } |