]> jfr.im git - irc/gameservirc.git/blame - gameserv/devel.cpp
updated the TODO
[irc/gameservirc.git] / gameserv / devel.cpp
CommitLineData
a46254e3 1#include "options.h"
2#include "list.h"
3#include "aClient.h"
4#include "extern.h"
5#include "flags.h"
6#include "player.h"
7#include "item.h"
8#include "pouch.h"
9
10#include <fstream>
11#include <iostream>
12
b6bf4226 13int sock = 1;
a46254e3 14
15using namespace std;
16
17char *PACKAGE = "GameServ";
18char *VERSION = "1.2.6 +devel";
19
20long lastrefresh;
21
22List<aClient> clients[U_TABLE_SIZE];
7f56a68b 23list <item*> items;
a46254e3 24
25void save_lastrefresh();
26void load_lastrefresh();
27void prettyIntro();
28void check_idles();
7f56a68b 29void testitems();
a46254e3 30
31int main(int argc, char *argv[])
32{
33 char buffer[1024], buf[1024];
34 memset(buffer, 0, 1024);
35 memset(buf, 0, 1024);
36 int connected;
37
38 char *conf;
39 srand(time(NULL));
40 conf = new char[16];
41 strcpy(conf, "gameserv.conf");
42
43 /*
44 * This needs to be fixed to work for any number of arguments in any
45 * order
46 *
47 */
48 if (argc > 1)
49 {
50 if ( argc > 2 || stricmp(argv[1], "--help") == 0)
51 {
52 cout << "Usage: gameserv [options] [configfile]" << endl;
53 cout << "Options:" << endl;
54 cout << "--help Displays this help dialogue" << endl;
55 return 1;
56 }
57 delete []conf;
58 conf = argv[1];
59 }
60
61 prettyIntro();
62
63 if (load_config_file(conf))
64 {
65 cout << "Config file loaded ok...\n"
66 << "Turning into a daemon" << endl;
67 }
68 else
69 exit(2);
70
71 if (argc <= 1)
72 delete []conf;
73
74 // Turn into a daemon
75 /*
76 if (daemon(1,0) < 0)
77 {
78 perror("Could not turn into a daemon");
79 exit(3);
80 }
81 */
82
83 load_gs_dbase();
84 loadNews(newsdata, todaysnews);
85
86 if (load_masters() == false)
87 {
88 log("Error loading masters");
89 goto end;
90 }
91
92 if (load_monsters() == false)
93 {
94 log("Error loading monsters");
95 goto end;
96 }
97
98 if (!load_dragon())
99 {
100 log("Error loading dragon");
101 goto end;
102 }
103
104 if (load_levels() == false)
105 {
106 log("Error loading levels");
107 goto end;
108 }
109
110 shuttingdown = false;
111
112 char ignoreservers[32][256];
113 char *currentserver;
114 currentserver = strtok(ignoreserverslist, " ");
115 for (int server = 0; server < 32 && currentserver != NULL; server++)
116 {
117 strncpy(ignoreservers[server], currentserver, 255);
118 log("Placing %s on the server ignore list", currentserver);
119 currentserver = strtok(NULL, " ");
120 }
121
122 // This loop will retry the connection 3 times
7f56a68b 123 connected = 1;
124 load_lastrefresh();
a46254e3 125
7f56a68b 126 {
127 testitems();
128 item *tester = items.front();
129 cout << tester->getName() << endl;
130 item *tester2 = items.back();
131 cout << tester2->getName() << endl;
132 items.clear();
133 }
a46254e3 134
b6bf4226 135 {
e696687e 136 // This is where you can test stuff
7f56a68b 137 /*
138 string itemname;
139 item *tempitem;
140
141 cout << "Enter an item name: ";
142 cin >> itemname;
143 char num[16];
144 for (int x = 1; x < 6000001; x++)
145 {
146 sprintf(num, "%d", x);
147 tempitem = new weapon((itemname + num));
148 items.push_back(tempitem);
149 }
150
151 item *tester = items.front();
152 cout << tester->getName() << endl;
153 item *tester2 = items.back();
154 cout << tester2->getName() << endl;
155 items.clear();
156 */
a46254e3 157 }
158
159 end:
160
161 save_gs_dbase();
162 save_dragon();
163 saveNews(newsdata, todaysnews);
164
165 delete_monsters();
166
167#ifdef DEBUGMODE
168 log("<CLOSED>");
169#endif
170
171 unload_config_file();
172 return 0;
173}
7f56a68b 174
175void testitems()
176{
177 // This is where you can test stuff
178 string itemname;
179 item *tempitem;
180
181 cout << "Enter an item name: ";
182 cin >> itemname;
183 char num[16];
184 char *testing;
185 testing = new char[80];
186 strncpy(testing, "1~1~Stick~200~-1~15~0~0~0", 80);
187 for (int x = 1; x < 6000001; x++)
188 {
189 sprintf(num, "%d", x);
190 tempitem = new weapon("blah");
191 if (!tempitem->setData(testing))
192 {
193 cout << "Error in setData()" << endl;
194 break;
195 }
196 items.push_back(tempitem);
197 }
198}
a46254e3 199
200aClient *find(char *nick)
201{
202 return findbynick(nick);
203}
204
205aClient *find(const char *nick)
206{
207 return findbynick(nick);
208}
209
210#ifdef P10
211
212aClient *findbyrealnick(char *realnick)
213{
214 ListNode <aClient> *newPtr;
215 unsigned long hv = sHASH((unsigned char *) realnick);
216 newPtr = clients[hv].First();
217
218 aClient *client = NULL;
219
220 while (newPtr)
221 {
222 client = newPtr->getData();
223 if (stricmp(client->getRealNick(), realnick) == 0)
224 return client;
225 client = NULL;
226 newPtr = newPtr->Next();
227 }
228 return client;
229}
230
231#else
232
233aClient *findbyrealnick(char *realnick)
234{
235 return findbynick(realnick);
236}
237
238#endif
239
240aClient *findbynick(char *nick)
241{
242 ListNode <aClient> *newPtr;
243#ifdef P10
244 unsigned long hv = sHASH((unsigned char *) nick);
245#else
246 unsigned long hv = iHASH((unsigned char *) nick);
247#endif
248
249 newPtr = clients[hv].First();
250
251 aClient *client = NULL;
252
253 while (newPtr)
254 {
255 client = newPtr->getData();
256#ifdef P10
257 if (strcmp(client->getNick(), nick) == 0)
258#else
259 if (stricmp(client->getNick(), nick) == 0)
260#endif
261 return client;
262 client = NULL;
263 newPtr = newPtr->Next();
264 }
265 return client;
266}
267
268aClient *findIRCplayer(const char *nick)
269{
270 ListNode <aClient> *newPtr;
271 aClient *p = NULL;
272
273 p = find(nick);
274
275 if (!is_playing(p))
276 return NULL;
277
278 unsigned long hv = iHASH((unsigned char *) p->stats->name.c_str());
279
280 for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
281 {
282 p = newPtr->getData();
283#ifdef P10
284 if (strcmp(p->getNick(), nick) == 0)
285#else
286 if (stricmp(p->getNick(), nick) == 0)
287#endif
288 return p;
289 p = NULL;
290 }
291 return NULL;
292}
293
294aClient *findplayer(const char *name)
295{
296 ListNode <aClient> *newPtr;
297 Player *p = NULL;
298 unsigned long hv = iHASH((unsigned char *) name);
299 for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
300 {
301 p = newPtr->getData()->stats;
302 if (stricmp(p->name.c_str(), name) == 0)
303 return newPtr->getData();
304 p = NULL;
305 }
306 return NULL;
307}
308
309void check_idles()
310{
311 ListNode <aClient> *newPtr;
312 Player *p = NULL;
313
314 for (int x = 0; x < U_TABLE_SIZE; x++)
315 {
316 for (newPtr = players[x].First(); newPtr; newPtr = newPtr->Next())
317 {
318 p = newPtr->getData()->stats;
319 switch(p->level)
320 {
321 case 1:
322 if ((time(NULL) - p->lastlogin) / 86400 >= level1expire)
323 {
324 logout(newPtr->getData());
325 players[x].remove(newPtr->getData());
326 return;
327 }
328 break;
329
330 default:
331 if ((time(NULL) - p->lastlogin) / 86400 >= defaultexpire)
332 {
333 logout(newPtr->getData());
334 players[x].remove(newPtr->getData());
335 return;
336 }
337 break;
338 }
339 if (timedOut(p))
340 {
341 timeOutEvent(p);
342 }
343 }
344 }
345}
346
347aClient *findbynick(const char *nick)
348{
349 ListNode <aClient> *newPtr;
350#ifdef P10
351 unsigned long hv = sHASH((unsigned char *) nick);
352#else
353 unsigned long hv = iHASH((unsigned char *) nick);
354#endif
355
356 newPtr = clients[hv].First();
357
358 aClient *client = NULL;
359
360 while (newPtr)
361 {
362 client = newPtr->getData();
363#ifdef P10
364 if (strcmp(client->getNick(), nick) == 0)
365#else
366 if (stricmp(client->getNick(), nick) == 0)
367#endif
368 return client;
369 client = NULL;
370 newPtr = newPtr->Next();
371 }
372 return client;
373}
374
375void prettyIntro()
376{
377 cout << endl;
378 cout << " GGGG AAA MM MM EEEEEEE SSSSS EEEEEEE RRRRRR VV VV " << endl;
379 cout << " GG GG AAAAA MMM MMM EE SS EE RR RR VV VV " << endl;
380 cout << "GG AA AA MM MM MM EEEEE SSSSS EEEEE RRRRRR VV VV " << endl;
381 cout << "GG GGG AAAAAAA MM MM EE SS EE RR RR VV VV " << endl;
382 cout << "G G AA AA MM MM EEEEEEE SSSSS EEEEEEE RR RR VVV" << endl;
383 cout << " GGGGG V\n\n" << endl;
384 cout << "Version: " << VERSION << endl;
385}
386
387void load_lastrefresh()
388{
389 ifstream infile;
390 infile.open(".gsrefresh");
391 if (infile.fail())
392 {
393#ifdef DEBUGMODE
394 log("Error opening .gsrefresh");
395#endif
396
397 generate:
398 long mytime = time(NULL);
399#ifdef DEBUGMODE
400 log("Generating new refresh time");
401#endif
402
403 // Just a safety measure... tho no one should
404 // get anywhere near the time as their refreshperiod
405 if (refreshperiod >= mytime)
406 refreshperiod = 86400;
407
408 lastrefresh = mytime - (mytime % refreshperiod);
409 refreshall();
410 save_lastrefresh();
411 return;
412 }
413 infile >> lastrefresh;
414 infile.close();
415 if (lastrefresh < 0)
416 goto generate;
417}
418
419void save_lastrefresh()
420{
421 ofstream outfile;
422
423 outfile.open(".gsrefresh");
424
425 if (outfile.fail())
426 {
427 log("Error creating new file .gsrefresh");
428 return;
429 }
430 outfile << lastrefresh << endl;
431
432 outfile.close();
433}