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