forked from InfiniteRasa/Game-Server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DataInterface_SpawnSystem.cpp
76 lines (73 loc) · 2.8 KB
/
DataInterface_SpawnSystem.cpp
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
#include<winsock2.h>
#include<stdio.h>
#include"DataInterface.h"
void cb_DataInterface_SpawnSystem_getSpawnPoolList(MYSQL *dbCon, diJob_spawnpool_t *job, void *cb, void *param)
{
sint8 queryText[4096];
sprintf(queryText, "SELECT "
"id,mode,animType,"
"posx,posy,posz,contextid,"
// creature slots
"creatureType1,creatureMinCount1,creatureMaxCount1,"
"creatureType2,creatureMinCount2,creatureMaxCount2,"
"creatureType3,creatureMinCount3,creatureMaxCount3,"
"creatureType4,creatureMinCount4,creatureMaxCount4,"
"creatureType5,creatureMinCount5,creatureMaxCount5,"
"creatureType6,creatureMinCount6,creatureMaxCount6"
" FROM spawnpool");
// execute query
if( mysql_query(dbCon, queryText) )
{
printf("Error in query\n");
while(1) Sleep(1000);
}
MYSQL_RES *dbResult = mysql_store_result(dbCon);
MYSQL_ROW dbRow;
// parse rows
sint32 rowCount = mysql_num_rows(dbResult);
while((dbRow = mysql_fetch_row(dbResult)))
{
//"id,mode,animType,"
//"posx,posy,posz,contextid,"
//"creatureType1,creatureMinCount1,creatureMaxCount1,"
//"creatureType2,creatureMinCount2,creatureMaxCount2,"
//"creatureType3,creatureMinCount3,creatureMaxCount3,"
//"creatureType4,creatureMinCount4,creatureMaxCount4,"
//"creatureType5,creatureMinCount5,creatureMaxCount5,"
//"creatureType6,creatureMinCount6,creatureMaxCount6"
sint32 idx = 0;
// general data
sscanf(dbRow[idx], "%d", &job->id); idx++;
sscanf(dbRow[idx], "%d", &job->mode); idx++;
sscanf(dbRow[idx], "%d", &job->animType); idx++;
// location data
sscanf(dbRow[idx], "%f", &job->posX); idx++;
sscanf(dbRow[idx], "%f", &job->posY); idx++;
sscanf(dbRow[idx], "%f", &job->posZ); idx++;
sscanf(dbRow[idx], "%d", &job->contextId); idx++;
// creature spawn slots
for(sint32 spawnSlot=0; spawnSlot<6; spawnSlot++)
{
if( dbRow[idx] == NULL || dbRow[idx+1] == NULL || dbRow[idx+2] == NULL )
{
job->spawnSlot[spawnSlot].creatureType = 0;
idx += 3;
continue;
}
sscanf(dbRow[idx], "%d", &job->spawnSlot[spawnSlot].creatureType); idx++;
sscanf(dbRow[idx], "%d", &job->spawnSlot[spawnSlot].countMin); idx++;
sscanf(dbRow[idx], "%d", &job->spawnSlot[spawnSlot].countMax); idx++;
}
// do callback param1: mapchannel param2: list of spawnpool data
((void (*)(void*,void*))cb)(param, job);
}
// call with NULL job to inform callback that we are done
((void (*)(void*,void*))cb)(param, NULL);
mysql_free_result(dbResult);
DataInterface_freeJob(job);
}
void DataInterface_SpawnSystem_getSpawnPoolList(void (*cb)(void *param, diJob_spawnpool_t *jobData), void *param)
{
diJob_spawnpool_t *job = (diJob_spawnpool_t*)DataInterface_allocJob(sizeof(diJob_spawnpool_t));
DataInterface_queueJob(job, cb_DataInterface_SpawnSystem_getSpawnPoolList, cb, param);
}