-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.c
351 lines (298 loc) · 7.15 KB
/
main.c
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
#include "version.h"
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
#include "init.h"
#include "net.h"
#include "handletime.h"
#include "char.h"
#include "map_warppoint.h"
#include "npcgen.h"
#include "log.h"
#include "configfile.h"
#include "battle.h"
#include "petmail.h"
#include "autil.h"
#include "family.h"
#include "trade.h"
#ifdef _CHATROOMPROTOCOL // (不可开) Syu ADD 聊天室频道
#include "chatroom.h"
#endif
static void ShutdownProc( void);
void mainloop( void );
struct tm tmNow, tmOld;
void family_proc();
#ifdef _CHANNEL_MODIFY
extern int InitOccChannel(void);
#endif
#ifdef _GMSV_DEBUG
extern char *DebugMainFunction;
#endif
#ifdef _ANGEL_SUMMON
#define ANGELTIMELIMIT 3*24*60*60 // 完成任务时限(秒)
int AngelReady =0;
int AngelTimelimit = ANGELTIMELIMIT;
time_t AngelNextTime;
void AngelReadyProc();
#endif
//#include "genver.h"
void warplog_proc();
int main( int argc , char** argv, char** env )
{
/* 午曰丐尹内凛棉毛涩烂仄化云仁 */
setNewTime();
/* if ( argc > 1 && 0==strcmp(argv[1],"-v"))
{
printf("%s",genver);
exit(0);
}
else fprintf(stderr,"%s",genver);*/
EXITWITHEXITCODEIFFALSE( util_Init() , 1);
LoadAnnounce(); // Arminius 7.12 loginannounce
/* 赓渝涩烂 */
memcpy( &tmOld, localtime( (time_t *)&NowTime.tv_sec), sizeof( tmNow ) );
EXITWITHEXITCODEIFFALSE( init(argc , argv ,env ) , 1);
LoadPetTalk(); // Arminius 8.14 pet talk
#ifdef _GAMBLE_BANK
Load_GambleBankItems();
#endif
#ifdef _CFREE_petskill
Load_PetSkillCodes();
#endif
#ifdef _ITEM_PILEFORTRADE
TRADE_InitTradeList();
#endif
mainloop();
return 0;
}
void mainloop( void )
{
print("初始化NPC...");
NPC_generateLoop( 1 );
print("完成\n");
print("初始化signal1...");
signal(SIGUSR1,sigusr1);
print("完成\n");
print("初始化signal2...");
signal(SIGUSR2,sigusr2);
print("完成\n");
#ifdef _MAP_WARPPOINT
print("初始化地图传送点...");
MAPPOINT_InitMapWarpPoint();
print("完成\n");
if( !MAPPOINT_loadMapWarpPoint() ){
return;
}
#endif
#ifdef _ASSESS_SYSEFFICACY
Assess_InitSysEfficacy();
#endif
#ifdef _CHATROOMPROTOCOL // (不可开) Syu ADD 聊天室频道
print("初始化聊天室频...");
InitChatRoom();
print("完成\n");
#endif
#ifdef _CHANNEL_MODIFY
print("初始化职业频道...");
if(!InitOccChannel()) return; // 初始化职业频道
print("完成\n");
#endif
#ifdef _ANGEL_SUMMON
print("初始化精灵召奂时间...");
AngelReady = 0;
#ifdef _ANGEL_TIME
AngelNextTime = time(NULL) + getAngelPlayerTime();
#else
AngelNextTime = time(NULL) + 1*60;
#endif
print("完成\n");
#endif
//#ifdef _ALLDOMAN
// print("初始化英雄表列...");
// InitHeroList();
// print("完成\n");
//#endif
int itime=0;
while(1){
if(getCpuUse()!=-1){
itime++;
if(itime>getCpuUse()){
itime=0;
usleep(1);
}
}
#ifdef _ASSESS_SYSEFFICACY
Assess_SysEfficacy( 0 );
#endif
setNewTime();
memcpy(&tmNow, localtime( (time_t *)&NowTime.tv_sec),
sizeof( tmNow ) );
if( tmOld.tm_hour != getLogHour( ) && tmNow.tm_hour == getLogHour( ) ){
#ifdef _GMSV_DEBUG
DebugMainFunction="backupAllLogFile";
#endif
backupAllLogFile( &tmOld );
}
setNewTime();
#ifdef _ASSESS_SYSEFFICACY_SUB //显示LOOP时间
Assess_SysEfficacy_sub( 0, 1);
#ifdef _GMSV_DEBUG
DebugMainFunction="netloop_faster";
#endif
netloop_faster();
Assess_SysEfficacy_sub( 1, 1);
Assess_SysEfficacy_sub( 0, 2);
#ifdef _GMSV_DEBUG
DebugMainFunction="NPC_generateLoop";
#endif
NPC_generateLoop( 0 );
Assess_SysEfficacy_sub( 1, 2);
Assess_SysEfficacy_sub( 0, 3);
#ifdef _GMSV_DEBUG
DebugMainFunction="BATTLE_Loop";
#endif
BATTLE_Loop();
Assess_SysEfficacy_sub( 1, 3);
Assess_SysEfficacy_sub( 0, 4);
#ifdef _GMSV_DEBUG
DebugMainFunction="CHAR_Loop";
#endif
CHAR_Loop();
Assess_SysEfficacy_sub( 1, 4);
#ifdef _GMSV_DEBUG
DebugMainFunction="PETMAIL_proc";
#endif
PETMAIL_proc();
#ifdef _GMSV_DEBUG
DebugMainFunction="family_proc";
#endif
family_proc();
#ifdef _GMSV_DEBUG
DebugMainFunction="chardatasavecheck";
#endif
chardatasavecheck();
#ifdef _GMSV_DEBUG
DebugMainFunction="AngelReadyProc";
#endif
AngelReadyProc();
tmOld = tmNow;
if( tmOld.tm_sec != tmNow.tm_sec ) {
#ifdef _GMSV_DEBUG
DebugMainFunction="CHAR_checkEffectLoop";
#endif
CHAR_checkEffectLoop();
}
if( SERVSTATE_getShutdown()> 0 ) {
ShutdownProc();
#ifdef _GMSV_DEBUG
DebugMainFunction="ShutdownProc";
#endif
}
tmOld = tmNow;
#ifdef _ASSESS_SYSEFFICACY
Assess_SysEfficacy( 1 );
#endif
#endif
}
}
static void sendmsg_toall( char *msg )
{
int i;
int playernum = CHAR_getPlayerMaxNum();
for( i = 0 ; i < playernum ; i++) {
if( CHAR_getCharUse(i) != FALSE ) {
CHAR_talkToCli( i, -1, msg, CHAR_COLORYELLOW);
}
}
}
static void ShutdownProc( void)
{
#define SYSINFO_SHUTDOWN_MSG "%d 分钟后开始进行系统停机维护, 请大家提前下线以免数据丢失。"
#define SYSINFO_SHUTDOWN_MSG_COMP "服务器已关闭。"
int diff,hun;
diff = NowTime.tv_sec - SERVSTATE_getShutdown();
hun = SERVSTATE_getLimittime() - (diff/60);
if( hun != SERVSTATE_getDsptime() ){
char buff[256];
if( hun != 0 ) {
snprintf( buff, sizeof(buff), SYSINFO_SHUTDOWN_MSG, hun);
}
else {
strcpy( buff, SYSINFO_SHUTDOWN_MSG_COMP);
}
sendmsg_toall( buff);
SERVSTATE_setDsptime(hun);
if( hun == 1 ) {
SERVSTATE_SetAcceptMore( 0 );
}
}
/* closesallsockets */
if( hun == 0) {
closeAllConnectionandSaveData();
SERVSTATE_setShutdown(0);
SERVSTATE_setDsptime(0);
SERVSTATE_setLimittime(0);
}
}
void family_proc()
{
static unsigned long gettime = 0;
static unsigned long checktime = 0;
static unsigned long proctime = 0;
if( time(NULL) < proctime ) return;
proctime = time(NULL)+5;
if( (unsigned long)NowTime.tv_sec > gettime ){
getNewFMList();
gettime = (unsigned long)NowTime.tv_sec + 60*10;
}
if( (unsigned long)NowTime.tv_sec > checktime ){
checkFamilyIndex();
checktime = (unsigned long)NowTime.tv_sec + 60*30;
}
}
void warplog_proc()
{
static unsigned long checktime = 0;
if( (unsigned long)NowTime.tv_sec > checktime ){
warplog_to_file();
checktime = (unsigned long)NowTime.tv_sec + 300;
}
}
#ifdef _ANGEL_SUMMON
extern int player_online;
void AngelReadyProc()
{
//static time_t lastCreateTime = time(NULL);
time_t nowTime;
//static unsigned long AngelNextTime = 30*60;
struct tm *temptime;
char msg[1024];
nowTime = time(NULL);
if( nowTime < AngelNextTime )
return;
#ifdef _ANGEL_TIME
if( player_online <= getAngelPlayerMun() )
#else
if( player_online <= 10 )
#endif
{
// print("\n精灵召唤:线上人数不足=%d\n", player_online );
return;
}
AngelReady = 1;
//AngelNextTime = min( (int)(10000/player_online), 100)*60 + (unsigned long)nowTime;
#ifdef _ANGEL_TIME
AngelNextTime = min( (int)(getAngelPlayerTime()/player_online), 100)*60 + (unsigned long)nowTime;
#else
AngelNextTime = min( (int)(5000/player_online), 100)*60 + (unsigned long)nowTime;
#endif
temptime = localtime( &AngelNextTime );
sprintf( msg, "\n精灵召唤:产生一位缺额 下次产生时间=(%d/%d %d:%d) 目前人数=%d\n",
temptime->tm_mon+1, temptime->tm_mday, temptime->tm_hour, temptime->tm_min, player_online );
print( msg);
//LogAngel( msg);
}
#endif