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