Bonjour, je travaille présentement a modifié le code source d'un serveur de jeux, j'ai trouvé un vieux post sur un forum specialisé pour ce project qui donne des ajout interessant, allors j'ai ajouté les ligne de code au code que j'ai deja et qui est récent.

Déja j'ai fixé beaucoup de problemes (certains nom de classe avait changé entre autre) mais la j'en ai un que je sait vraiment pas quoi faire et encore moin par ou commencer...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/home/pierrick/Desktop/testtibiaserver/racetest/otserv.cpp:67: undefined reference to `Races::Races()'
/home/pierrick/Desktop/testtibiaserver/racetest/otserv.cpp:67: undefined reference to `Races::~Races()'
otserv.o: In function `mainLoader(CommandLineOptions const&, ServiceManager*)':
/home/pierrick/Desktop/testtibiaserver/racetest/otserv.cpp:517: undefined reference to `Races::loadFromXml(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
combat.o: In function `ValueCallback::getMinMaxValues(Player*, int&, int&, bool) const':
/home/pierrick/Desktop/testtibiaserver/racetest/combat.cpp:1227: undefined reference to `Races::getRace(int)'
/home/pierrick/Desktop/testtibiaserver/racetest/combat.cpp:1227: undefined reference to `Races::getRace(int)'
combat.o: In function `Combat::getMinMaxValues(Creature*, Creature*, int&, int&) const':
/home/pierrick/Desktop/testtibiaserver/racetest/combat.cpp:93: undefined reference to `Races::getRace(int)'
player.o: In function `Player::getLookCorpse() const':
/home/pierrick/Desktop/testtibiaserver/racetest/player.cpp:973: undefined reference to `Races::getRace(int)'
player.o: In function `Player::getAttackSpeed() const':
/home/pierrick/Desktop/testtibiaserver/racetest/player.cpp:3852: undefined reference to `Races::getRace(int)'
player.o:/home/pierrick/Desktop/testtibiaserver/racetest/player.cpp:520: more undefined references to `Races::getRace(int)' follow
collect2: ld returned 1 exit status
make[1]: *** [otserv] Error 1
make[1]: Leaving directory `/home/pierrick/Desktop/testtibiaserver/racetest'
make: *** [all] Error 2
Pourtant, la classe Races est dans le fichier race.h qui est bel et bien dans les include, et la premiere erreur ramenne sur la ligne 67 qui contient "Races g_races;"


Au cas ou sa aide, je vais mettre le code complet de otserv.cpp et race.h



otserv.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
// otserv main. The only place where things get instantiated.
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#include "otpch.h"
 
#include "otsystem.h"
#include "server.h"
#include "ioplayer.h"
#include "game.h"
#include <boost/thread.hpp>
#include <boost/asio.hpp>
#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <ctime>
 
 
#if !defined(__WINDOWS__)
	#include <unistd.h> // for access()
	#include <signal.h> // for sigemptyset()
#endif
 
#include "monsters.h"
#include "npc.h"
#include "outfit.h"
#include "vocation.h"
#include "scriptmanager.h"
#include "configmanager.h"
#include "guild.h"
 
#include "tools.h"
#include "ban.h"
#include "rsa.h"
 
#include "protocolgame.h"
#include "protocolold.h"
#include "protocollogin.h"
#include "status.h"
#include "admin.h"
 
#include "exception.h"
#include "networkmessage.h"
 
#ifdef __OTSERV_ALLOCATOR__
#include "allocator.h"
#endif
#include "race.h"
Races g_races;
 
Game g_game;
Dispatcher g_dispatcher;
Scheduler g_scheduler;
RSA g_RSA;
ConfigManager g_config;
Monsters g_monsters;
Npcs g_npcs;
BanManager g_bans;
Vocations g_vocations;
IPList serverIPs;
Guilds g_guilds;
 
boost::mutex g_loaderLock;
boost::condition_variable g_loaderSignal;
boost::unique_lock<boost::mutex> g_loaderUniqueLock(g_loaderLock);
 
extern AdminProtocolConfig* g_adminConfig;
 
#if !defined(__WINDOWS__)
time_t start_time;
#endif
 
 
void ErrorMessage(const char* message) {
	std::cout << std::endl << std::endl << "Error: " << message << std::endl;
	std::cin.get();
}
 
void ErrorMessage(std::string m){
	ErrorMessage(m.c_str());
}
 
struct CommandLineOptions{
	std::string configfile;
	bool truncate_log;
	bool start_closed;
	bool skip_scripts;
	std::string logfile;
	std::string errfile;
#if !defined(__WINDOWS__)
	std::string runfile;
#endif
};
 
CommandLineOptions g_command_opts;
 
bool parseCommandLine(CommandLineOptions& opts, std::vector<std::string> args);
void mainLoader(const CommandLineOptions& command_opts, ServiceManager* servicer);
 
void badAllocationHandler()
{
	// Use functions that only use stack allocation
	static const char* errorMessage =
		"Allocation failed, server out of memory.\nDecrease the size of your map or download the 64 bits version.";
	puts(errorMessage);
	std::exit(EXIT_SUCCESS);
}
 
#if !defined(__WINDOWS__)
// Runfile, for running OT as daemon in the background. If the server is shutdown by internal
// means, we need to clear the file to notify the daemon manager of our change in status.
// Note that if the server crashes, this will not happend. :|
void closeRunfile(void)
{
	std::ofstream runfile(g_command_opts.runfile.c_str(), std::ios::trunc | std::ios::out);
	runfile.close(); // Truncate file
}
#endif
 
int main(int argc, char** argv)
{
	// Provides stack traces when the server crashes
	ExceptionHandler mainExceptionHandler;
	mainExceptionHandler.InstallHandler();
 
	// Parse any command line (and display help text)
	if(!parseCommandLine(g_command_opts, std::vector<std::string>(argv, argv + argc))){
		return EXIT_SUCCESS;
	}
 
	// Setup bad allocation handler
	std::set_new_handler(badAllocationHandler);
 
#if !defined(__WINDOWS__)
	// Create the runfile
	if(g_command_opts.runfile != ""){
		std::ofstream f(g_command_opts.runfile.c_str(), std::ios::trunc | std::ios::out);
		f << getpid();
		f.close();
		atexit(closeRunfile);
	}
#endif
 
	// Redirect streams if we need to
	// use shared_ptr to guarantee file closing no matter what happens
	boost::shared_ptr<std::ofstream> logfile;
	boost::shared_ptr<std::ofstream> errfile;
	if(g_command_opts.logfile != ""){
		logfile.reset(new std::ofstream(g_command_opts.logfile.c_str(),
			(g_command_opts.truncate_log? std::ios::trunc : std::ios::app) | std::ios::out)
		);
		if(!logfile->is_open()){
			ErrorMessage("Could not open standard log file for writing!");
		}
		std::cout.rdbuf(logfile->rdbuf());
	}
	if(g_command_opts.errfile != ""){
		errfile.reset(new std::ofstream(g_command_opts.errfile.c_str(),
			(g_command_opts.truncate_log? std::ios::trunc : std::ios::app) | std::ios::out)
		);
		if(!errfile->is_open()){
			ErrorMessage("Could not open error log file for writing!");
		}
		std::cerr.rdbuf(errfile->rdbuf());
	}
 
#if !defined(__WINDOWS__)
	time(&start_time);
#endif
#ifdef __OTSERV_ALLOCATOR_STATS__
	// This keeps track of all allocations, can be used to find memory leak
	boost::thread(boost::bind(&allocatorStatsThread, (void*)NULL));
#endif
 
	std::cout << ":: " OTSERV_NAME " Version " OTSERV_VERSION << std::endl;
	std::cout << ":: ============================================================================" << std::endl;
	std::cout << "::" << std::endl;
 
#if defined __DEBUG__MOVESYS__ || defined __DEBUG_HOUSES__ || defined __DEBUG_MAILBOX__ \
	|| defined __DEBUG_LUASCRIPTS__ || defined __DEBUG_RAID__ || defined __DEBUG_NET__ \
	|| defined __DEBUG_SQL__
 
	std::cout << ":: Debugging:";
	#ifdef __DEBUG__MOVESYS__
	std::cout << " MOVESYS";
	#endif
	#ifdef __DEBUG_MAILBOX__
	std::cout << " MAILBOX";
	#endif
	#ifdef __DEBUG_HOUSES__
	std::cout << " HOUSES";
	#endif
	#ifdef __DEBUG_LUASCRIPTS__
	std::cout << " LUA-SCRIPTS";
	#endif
	#ifdef __DEBUG_RAID__
	std::cout << " RAIDS";
	#endif
	#ifdef __DEBUG_NET__
	std::cout << " NET-ASIO";
	#endif
	#ifdef __DEBUG_SQL__
	std::cout << " SQL";
	#endif
	std::cout << std::endl;
#endif
 
#if !defined(__WINDOWS__) && !defined(__ROOT_PERMISSION__)
	if( getuid() == 0 || geteuid() == 0 ){
		std::cout << std::endl << "OTServ executed as root user, please login with a normal user." << std::endl;
		return 1;
	}
#endif
 
 
#if !defined __WINDOWS__
	// ignore sigpipe...
	struct sigaction sigh;
	sigh.sa_handler = SIG_IGN;
	sigh.sa_flags = 0;
	sigemptyset(&sigh.sa_mask);
	sigaction(SIGPIPE, &sigh, NULL);
#endif
 
	ServiceManager servicer;
 
	// Start scheduler and dispatcher threads
	g_dispatcher.start();
	g_scheduler.start();
 
	// Add load task
	g_dispatcher.addTask(createTask(boost::bind(mainLoader, g_command_opts, &servicer)));
 
	// Wait for loading to finish
	g_loaderSignal.wait(g_loaderUniqueLock);
 
	boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
 
	if(servicer.is_running()){
		std::cout << "[done]" << std::endl;
		std::cout << ":: Server Running..." << std::endl;
		servicer.run();
	}
	else{
		ErrorMessage("No services running. Server is not online.");
	}
 
	mainExceptionHandler.RemoveHandler();
 
	return EXIT_SUCCESS;
}
 
bool parseCommandLine(CommandLineOptions& opts, std::vector<std::string> args)
{
	std::vector<std::string>::iterator argi = args.begin();
	opts.truncate_log = false;
	opts.start_closed = false;
	opts.skip_scripts = false;
 
	if(argi != args.end()){
		++argi;
	}
 
 
	while(argi != args.end()){
		std::string arg = *argi;
		if(arg == "-p" || arg == "--port"){
			if(++argi == args.end()){
				std::cout << "Missing parameter 1 for '" << arg << "'" << std::endl;
				return false;
			}
			std::string type = *argi;
 
			if(++argi == args.end()){
				std::cout << "Missing parameter 2 for '" << arg << "'" << std::endl;
				return false;
			}
 
			if(type == "g" || type == "game")
				g_config.setNumber(ConfigManager::GAME_PORT, atoi(argi->c_str()));
			if(type == "l" || type == "login")
				g_config.setNumber(ConfigManager::LOGIN_PORT, atoi(argi->c_str()));
			if(type == "a" || type == "admin")
				g_config.setNumber(ConfigManager::ADMIN_PORT, atoi(argi->c_str()));
			if(type == "s" || type == "status")
				g_config.setNumber(ConfigManager::STATUS_PORT, atoi(argi->c_str()));
		}
#if !defined(__WINDOWS__)
		else if(arg == "-r" || arg == "--runfile"){
			if(++argi == args.end()){
				std::cout << "Missing parameter for '" << arg << "'" << std::endl;
				return false;
			}
			opts.runfile = *argi;
		}
#endif
		else if(arg == "-i" || arg == "--ip"){
			if(++argi == args.end()){
				std::cout << "Missing parameter for '" << arg << "'" << std::endl;
				return false;
			}
			g_config.setString(ConfigManager::IP, *argi);
		}
		else if(arg == "-c" || arg == "--config"){
			if(++argi == args.end()){
				std::cout << "Missing parameter for '" << arg << "'" << std::endl;
				return false;
			}
			opts.configfile = *argi;
		}
		else if(arg == "--truncate-log"){
			opts.truncate_log = true;
		}
		else if(arg == "-l" || arg == "--log-file"){
			if(++argi == args.end()){
				std::cout << "Missing parameter 1 for '" << arg << "'" << std::endl;
				return false;
			}
			opts.logfile = *argi;
			if(++argi == args.end()){
				std::cout << "Missing parameter 2 for '" << arg << "'" << std::endl;
				return false;
			}
			opts.errfile = *argi;
		}
		else if(arg == "--closed"){
			opts.start_closed = true;
		}
		else if(arg == "--no-scripts"){
			opts.skip_scripts = true;
		}
		else if(arg == "--help"){
			std::cout <<
			"Usage: otserv {-i|-p|-c|-r|-l}\n"
			"\n"
			"\t-i, --ip $1\t\tIP of gameworld server. Should be equal to the \n"
			"\t\t\t\tglobal IP.\n"
			"\t-p, --port $1 $2\t\tPort ($2) for server to listen on ($1) is type\n"
			"\t\t\t\t(game, status, login, admin).\n"
			"\t-c, --config $1\t\tAlternate config file path.\n"
			"\t-l, --log-file $1 $2\tAll standard output will be logged to the $1\n"
			"\t\t\t\tfile, all errors will be logged to $2.\n"
			#if !defined(__WINDOWS__)
			"\t-r, --run-file $1\tSpecifies a runfile. Will contain the pid\n"
			"\t\t\t\tof the server process as long as it is running \n\t\t\t\t(UNIX).\n"
			#endif
			"\t--truncate-log\t\tReset log file each time the server is \n"
			"\t\t\t\tstarted.\n"
			"\t--closed\t\t\tStarts the server closed.\n"
			;
			return false;
		}
		else{
			std::cout << "Unrecognized command line argument '" << arg << "'\n"
			"Usage: otserv {-i|-p|-c|-r|-l}" << "\n";
			return false;
		}
		++argi;
	}
	return true;
}
 
void mainLoader(const CommandLineOptions& command_opts, ServiceManager* service_manager)
{
	int64_t startLoadTime = OTSYS_TIME();
 
	//dispatcher thread
	g_game.setGameState(GAME_STATE_STARTUP);
 
	// random numbers generator
	std::cout << ":: Initializing the random numbers... " << std::flush;
	std::srand((unsigned int)OTSYS_TIME());
	std::cout << "[done]" << std::endl;
 
#if defined LUA_CONFIGFILE
	const char* configname = LUA_CONFIGFILE;
#elif defined __LUA_NAME_ALTER__
	const char* configname = "otserv.lua";
#else
	const char* configname = "config.lua";
#endif
	if(command_opts.configfile != ""){
		configname = command_opts.configfile.c_str();
	}
 
	// read global config
	std::cout << ":: Loading lua script " << configname << "... " << std::flush;
 
#ifdef SYSCONFDIR
	std::string sysconfpath;
	sysconfpath = SYSCONFDIR;
	sysconfpath += "/otserv/";
	sysconfpath += configname;
#endif
 
 
#if !defined(__WINDOWS__) && !defined(__NO_HOMEDIR_CONF__)
	std::string configpath;
	configpath = getenv("HOME");
	configpath += "/.otserv/";
	configpath += configname;
 
	#ifdef SYSCONFDIR
		if (!g_config.loadFile(configname) && !g_config.loadFile(configpath) && !g_config.loadFile(sysconfpath))
	#else
		if (!g_config.loadFile(configname) && !g_config.loadFile(configpath))
	#endif
#else
	#ifdef SYSCONFDIR
		if (!g_config.loadFile(configname) && !g_config.loadFile(sysconfpath))
	#else
		if (!g_config.loadFile(configname))
	#endif
#endif
	{
		std::ostringstream os;
#if !defined(__WINDOWS__) && !defined(__NO_HOMEDIR_CONF__)
		os << "Unable to load " << configname << " or " << configpath;
#else
		os << "Unable to load " << configname;
#endif
		ErrorMessage(os.str());
		exit(-1);
	}
	std::cout << " [done]" << std::endl;
 
#ifdef __WINDOWS__
	std::stringstream mutexName;
	mutexName << "otserv_" << g_config.getNumber(ConfigManager::LOGIN_PORT);
	CreateMutex(NULL, FALSE, mutexName.str().c_str());
	if(GetLastError() == ERROR_ALREADY_EXISTS)
		ErrorMessage("There's an another instance of the OTServ running with the same login port, please shut it down first or change ports for this one.");
#endif
 
#if defined(PKGDATADIR) && !defined(__WINDOWS__) // I dont care enough to port this to win32, prolly not needed
	// let's fix the datadir, if necessary...
	if (access(g_config.getString(ConfigManager::DATA_DIRECTORY).c_str(), F_OK)) { // check if datadir exists
		// if not then try replacing it with "global" datadir
		std::cout << ":: No datadir '" << g_config.getString(ConfigManager::DATA_DIRECTORY).c_str() << "', using a system-wide one" << std::endl;
 
		std::string dd = PKGDATADIR;
		dd += "/";
		dd += g_config.getString(ConfigManager::DATA_DIRECTORY);
		g_config.setString(ConfigManager::DATA_DIRECTORY, dd);
	}
#endif
	std::cout << ":: Using data directory " << g_config.getString(ConfigManager::DATA_DIRECTORY).c_str() << "... " << std::flush;
	std::cout << "[done]" << std::endl;
 
	std::cout << ":: Checking Database Connection... ";
	Database* db = Database::instance();
	if(db == NULL || !db->isConnected()){
		ErrorMessage("Database Connection Failed!");
		exit(-1);
	}
	std::cout << "[done]" << std::endl;
 
	std::cout << ":: Checking Schema version... ";
	DBResult* result;
	if(!(result = db->storeQuery("SELECT `value` FROM `schema_info` WHERE `name` = 'version';"))){
		ErrorMessage("Can't get schema version! Does `schema_info` exist?");
		exit(-1);
	}
	int schema_version = result->getDataInt("value");
	db->freeResult(result);
	if(schema_version != CURRENT_SCHEMA_VERSION){
		ErrorMessage("Your database is outdated. Run the dbupdate utility to update it to the latest schema version.");
		exit(-1);
	}
	std::cout << "Version = " << schema_version << " ";
	std::cout << "[done]" << std::endl;
 
 
	//load RSA key
	std::cout << ":: Loading RSA key..." << std::flush;
	const char* p("14299623962416399520070177382898895550795403345466153217470516082934737582776038882967213386204600674145392845853859217990626450972452084065728686565928113");
	const char* q("7630979195970404721891201847792002125535401292779123937207447574596692788513647179235335529307251350570728407373705564708871762033017096809910315212884101");
	const char* d("46730330223584118622160180015036832148732986808519344675210555262940258739805766860224610646919605860206328024326703361630109888417839241959507572247284807035235569619173792292786907845791904955103601652822519121908367187885509270025388641700821735345222087940578381210879116823013776808975766851829020659073");
	g_RSA.setKey(p, q, d);
 
	std::cout << "[done]" << std::endl;
 
	std::stringstream filename;
 
	//load vocations
	filename.str("");
	filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << "vocations.xml";
	std::cout << ":: Loading " << filename.str() << "... " << std::flush;
	if(!g_vocations.loadFromXml(g_config.getString(ConfigManager::DATA_DIRECTORY))){
		ErrorMessage("Unable to load vocations!");
		exit(-1);
	}
 
 
//load races
	filename.str("");
	filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << "races.xml";
	std::cout << ":: Loading races... " << std::flush;
	if(!g_races.loadFromXml(g_config.getString(ConfigManager::DATA_DIRECTORY))){
		ErrorMessage("Unable to load races!");
		exit(-1);
	}
	std::cout << "[done]" << std::endl;
 
	// load item data
	filename.str("");
	filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << "items/items.otb";
	std::cout << ":: Loading " << filename.str() << "... " << std::flush;
	if(Item::items.loadFromOtb(filename.str())){
		std::stringstream errormsg;
		errormsg << "Unable to load " << filename.str() << "!";
		ErrorMessage(errormsg.str().c_str());
		exit(-1);
	}
	std::cout << "[done]" << std::endl;
 
	filename.str("");
	filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << "items/items.xml";
	std::cout << ":: Loading " << filename.str() << "... " << std::flush;
	if(!Item::items.loadFromXml(g_config.getString(ConfigManager::DATA_DIRECTORY))){
		std::stringstream errormsg;
		errormsg << "Unable to load " << filename.str() << "!";
		ErrorMessage(errormsg.str().c_str());
		exit(-1);
	}
	std::cout << "[done]" << std::endl;
 
	//load scripts
	if (!command_opts.skip_scripts){
		if(!ScriptingManager::getInstance()->loadScriptSystems()){
			std::exit(-1);
		}
	}
	else{
		// Dummy call to allocate the scripting system
		ScriptingManager::getInstance();
		std::cout << ":: Skipping loading script system." << std::endl;
	}
 
	// load monster data
	filename.str("");
	filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << "monster/monsters.xml";
	std::cout << ":: Loading " << filename.str() << "... " << std::flush;
	if(!g_monsters.loadFromXml(g_config.getString(ConfigManager::DATA_DIRECTORY))){
		std::stringstream errormsg;
		errormsg << "Unable to load " << filename.str() << "!";
		ErrorMessage(errormsg.str().c_str());
		exit(-1);
	}
	std::cout << "[done]" << std::endl;
 
	// load outfits data
	filename.str("");
	filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << "outfits.xml";
	std::cout << ":: Loading " << filename.str() << "... " << std::flush;
	Outfits* outfits = Outfits::getInstance();
	if(!outfits->loadFromXml(g_config.getString(ConfigManager::DATA_DIRECTORY))){
		std::stringstream errormsg;
		errormsg << "Unable to load " << filename.str() << "!";
		ErrorMessage(errormsg.str().c_str());
		exit(-1);
	}
	std::cout << "[done]" << std::endl;
 
	//load admin protocol configuration
	filename.str("");
	filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << "admin.xml";
	g_adminConfig = new AdminProtocolConfig();
	std::cout << ":: Loading admin protocol config... " << std::flush;
	if(!g_adminConfig->loadXMLConfig(g_config.getString(ConfigManager::DATA_DIRECTORY))){
		std::stringstream errormsg;
		errormsg << "Unable to load " << filename.str() << "!";
		ErrorMessage(errormsg.str().c_str());
		exit(-1);
	}
	std::cout << "[done]" << std::endl;
 
	std::string worldType = g_config.getString(ConfigManager::WORLD_TYPE);
 
	if(asLowerCaseString(worldType) == "pvp" || asLowerCaseString(worldType) == "openpvp"){
		g_game.setWorldType(WORLD_TYPE_OPEN_PVP);
	}
	else if(asLowerCaseString(worldType) == "no-pvp" || asLowerCaseString(worldType) == "optionalpvp"){
		g_game.setWorldType(WORLD_TYPE_OPTIONAL_PVP);
	}
	else if(asLowerCaseString(worldType) == "pvp-enforced" || asLowerCaseString(worldType) == "hardcorepvp"){
		g_game.setWorldType(WORLD_TYPE_HARDCORE_PVP);
	}
	else{
		ErrorMessage("Unknown world type!");
		exit(-1);
	}
 
	std::cout << ":: Worldtype: " << asUpperCaseString(worldType) << std::endl;
 
	std::cout << ":: Cleaning online players info... " << std::flush;
	if(!IOPlayer::instance()->cleanOnlineInfo()){
		std::stringstream errormsg;
		errormsg << "Unable to execute query for cleaning online status!";
		ErrorMessage(errormsg.str().c_str());
		exit(-1);
	}
	std::cout << "[done]" << std::endl;
 
	std::cout << ":: Setting up guilds in war... " << std::flush;
	g_guilds.loadWars();
	std::cout << "[done]" << std::endl;
 
	#ifdef __SKULLSYSTEM__
	std::cout << ":: Skulls enabled" << std::endl;
	#endif
 
	std::string passwordType = g_config.getString(ConfigManager::PASSWORD_TYPE_STR);
	if(passwordType.empty() || asLowerCaseString(passwordType) == "plain"){
		g_config.setNumber(ConfigManager::PASSWORD_TYPE, PASSWORD_TYPE_PLAIN);
		std::cout << ":: Use plain passwords";
	}
	else if(asLowerCaseString(passwordType) == "md5"){
		g_config.setNumber(ConfigManager::PASSWORD_TYPE, PASSWORD_TYPE_MD5);
		std::cout << ":: Use MD5 passwords";
	}
	else if(asLowerCaseString(passwordType) == "sha1"){
		g_config.setNumber(ConfigManager::PASSWORD_TYPE, PASSWORD_TYPE_SHA1);
		std::cout << ":: Use SHA1 passwords";
	}
	else{
		ErrorMessage("Unknown password type!");
		exit(-1);
	}
 
	if(g_config.getString(ConfigManager::PASSWORD_SALT) != "")
		std::cout << " [salted]";
	std::cout << std::endl;
 
	if(!g_game.loadMap(g_config.getString(ConfigManager::MAP_FILE),
		g_config.getString(ConfigManager::MAP_KIND))){
		// ok ... so we didn't succeed in laoding the map.
		// perhaps the path to map didn't include path to data directory?
		// let's try to prepend path to datadir before bailing out miserably.
		filename.str("");
		filename << g_config.getString(ConfigManager::DATA_DIRECTORY) << g_config.getString(ConfigManager::MAP_FILE);
 
		if(!g_game.loadMap(filename.str(), g_config.getString(ConfigManager::MAP_KIND))){
			ErrorMessage("Couldn't load map");
			exit(-1);
		}
	}
 
	g_game.setGameState(GAME_STATE_INIT);
 
	// Tie ports and register services
 
	// Tibia protocols
	service_manager->add<ProtocolGame>(g_config.getNumber(ConfigManager::GAME_PORT));
	service_manager->add<ProtocolLogin>(g_config.getNumber(ConfigManager::LOGIN_PORT));
 
	// OT protocols
	service_manager->add<ProtocolAdmin>(g_config.getNumber(ConfigManager::ADMIN_PORT));
	service_manager->add<ProtocolStatus>(g_config.getNumber(ConfigManager::STATUS_PORT));
 
	// Legacy protocols (they need to listen on login port as all old server only used one port
	// which was the login port.)
	service_manager->add<ProtocolOldLogin>(g_config.getNumber(ConfigManager::LOGIN_PORT));
	service_manager->add<ProtocolOldGame>(g_config.getNumber(ConfigManager::LOGIN_PORT));
 
 
	// Print ports/ip addresses that we listen too
 
	std::pair<uint32_t, uint32_t> IpNetMask;
	IpNetMask.first  = inet_addr("127.0.0.1");
	IpNetMask.second = 0xFFFFFFFF;
	serverIPs.push_back(IpNetMask);
 
	char szHostName[128];
	if(gethostname(szHostName, 128) == 0){
		std::cout << "::" << std::endl << ":: Running on host " << szHostName << std::endl;
 
		hostent *he = gethostbyname(szHostName);
 
		if(he){
			std::cout << ":: Local IP address(es):  ";
			unsigned char** addr = (unsigned char**)he->h_addr_list;
 
			while (addr[0] != NULL){
				std::cout << (unsigned int)(addr[0][0]) << "."
				<< (unsigned int)(addr[0][1]) << "."
				<< (unsigned int)(addr[0][2]) << "."
				<< (unsigned int)(addr[0][3]) << "  ";
 
				IpNetMask.first  = *(uint32_t*)(*addr);
				IpNetMask.second = 0x0000FFFF;
				serverIPs.push_back(IpNetMask);
 
				addr++;
			}
 
			std::cout << std::endl;
		}
	}
 
	std::cout << ":: Local ports:           ";
	std::list<uint16_t> ports = service_manager->get_ports();
	while(ports.size()){
		std::cout << ports.front() << "\t";
		ports.pop_front();
	}
	std::cout << std::endl;
 
	std::cout << ":: Global IP address:     ";
	std::string ip = g_config.getString(ConfigManager::IP);
 
	uint32_t resolvedIp = inet_addr(ip.c_str());
	if(resolvedIp == INADDR_NONE){
		struct hostent* he = gethostbyname(ip.c_str());
		if(he != 0){
			resolvedIp = *(uint32_t*)he->h_addr;
		}
		else{
			std::string error_msg = "Can't resolve: " + ip;
			ErrorMessage(error_msg.c_str());
			exit(-1);
		}
	}
 
	std::cout << convertIPToString(resolvedIp) << std::endl << "::" << std::endl;
 
	std::cout << ":: Total loading time: " << (OTSYS_TIME() - startLoadTime)/(1000.) << "s" << std::endl;
 
	IpNetMask.first  = resolvedIp;
	IpNetMask.second = 0;
	serverIPs.push_back(IpNetMask);
	std::cout << ":: Starting Server... ";
 
	g_game.start(service_manager);
 
	if(command_opts.start_closed){
		g_game.setGameState(GAME_STATE_CLOSED);
	}
	else{
		g_game.setGameState(GAME_STATE_NORMAL);
	}
	g_loaderSignal.notify_all();
}
race.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//////////////////////////////////////////////////////////////////////
 
#ifndef __OTSERV_RACE_H__
#define __OTSERV_RACE_H__
 
#include "enums.h"
#include "const.h"
#include <string>
#include <map>
 
class Race
{
public:
	const std::string& getRaceName() const {return name;}
	const std::string& getDescription() const {return description;}
	const uint16_t getCorpse() const {return corpse;}
 
	float getMeleeBaseDamage(WeaponType_t weaponType) const
	{
		if(weaponType == WEAPON_SWORD)
			return swordBaseDamage;
		else if(weaponType == WEAPON_AXE)
			return axeBaseDamage;
		else if(weaponType == WEAPON_CLUB)
			return clubBaseDamage;
		else if(weaponType == WEAPON_DIST)
			return distBaseDamage;
		else
			return fistBaseDamage;
	};
 
	float getMagicBaseDamage() const {return magicBaseDamage;};
	float getWandBaseDamage() const {return wandBaseDamage;};
	float getHealingBaseDamage() const {return healingBaseDamage;};
 
	float getBaseDefense() const {return baseDefense;};
	float getArmorDefense() const {return armorDefense;};
 
	float getMovementSpeed() const {return movementSpeed;};
	float getAttackSpeed() const {return attackSpeed;};
 
protected:
	friend class Races;
	Race();
 
	std::string name;
	std::string description;
	uint16_t corpse;
 
	float movementSpeed;
	float attackSpeed;
 
	float swordBaseDamage;
	float axeBaseDamage;
	float clubBaseDamage;
	float distBaseDamage;
	float fistBaseDamage;
 
	float magicBaseDamage;
	float wandBaseDamage;
	float healingBaseDamage;
 
	float baseDefense;
	float armorDefense;
};
 
typedef std::map<uint32_t, Race*> RaceMap;
 
class Races
{
public:
	Races();
	~Races();
 
	bool loadFromXml(const std::string& datadir);
	Race* getRace(int32_t raceId);
	int32_t getRaceId(const std::string& name);
 
private:
	RaceMap raceMap;
};
 
#endif


Merci beaucoup a tout ceux qui vont tenté de donné un coup de main, et je vais donné plus d'info sur demande