📄 timer.cpp
字号:
// Timer.cpp: implementation of the Timer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Wox2head.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Timer::Timer()
{
//林荤困 檬扁拳
srand( (unsigned)time( NULL ) );
secure = 1;
//鸥捞赣 檬扁拳
timeout.tv_sec=0;
timeout.tv_usec=0;
NextCheckConn = 0;
CurTime=clock();
starttime=CurTime;
endtime=0;
lclock=0;
networkTime = 0;
timerTime = 0;
autoTime = 0;
loopTime = 0;
networkTimeCount = 1000;
timerTimeCount = 1000;
autoTimeCount = 1000;
loopTimeCount = 1000;
}
Timer::~Timer()
{
}
unsigned int Timer::Roll(unsigned int dice_var)
{
return (rand()%(dice_var+1));
}
void Timer::checkkey( void )
{
char c;
if (kbhit())
{
c=toupper(getch());
processkey( c );
}
}
void Timer::checktimers( void ) // Check shutdown timers
{
overflow = ( lclock > CurTime ); // Small optimization
if( endtime )
{
if( endtime <= CurTime )
Gv->ServerON = 0;
}
lclock = CurTime;
}
void Timer::processkey( int c )
{
if( c == 'S' )
{
if (secure)
{
printf("WOX2: 焊龋葛靛 荤侩吝瘤. ? 虐甫 穿福矫搁 疙飞阑 焊角 荐 乐嚼聪促.\n");
secure=0;
return;
}
else
{
printf("WOX2: 焊龋葛靛 荤侩.\n");
secure=1;
return;
}
}
else
{
// int i, j;
if( secure == 1 && c != '?' )
{
printf("WOX2: 焊龋葛靛 荤侩吝! 'S'虐甫 穿福矫搁 掺角 荐 乐嚼聪促.\n");
return;
}
switch( c )
{
case 0x1B:
case 'Q':
printf("WOX2: 辆丰矫累!\n");
Gv->ServerON=0;
break;
case '1':
Cw->BroadCast("规价抛胶飘涝聪促酒!!");
break;
case 'T':
endtime = CurTime + ( CLOCKS_PER_SEC * 600 );
//endmessage( 0 );
printf( "WOX2: %i 盒饶俊 辑滚 辆丰(固肯己).\n", ( ( endtime - CurTime ) / CLOCKS_PER_SEC ) / 60 );
break;
case '#':
//if ( !cwmWorldState->Saving() )
//{
// cwmWorldState->savenewworld(1);
Cc->SaveAccount();
// saveserverscript(1);
//}
break;
case 'L':
/*if (showlayer)
{
printf("UOX3: Layer display disabled.\n");
showlayer=0;
}
else
{
printf("UOX3: Layer display enabled.\n");
showlayer=1;
}*/
break;
case 'I':
Gv->ReadINI();
// for (i=0;i<servcount;i++)
// if (serv[i][1][0]=='*') sprintf(serv[i][1],"%i.%i.%i.%i",ph1,ph2,ph3,ph4);
printf("WOX2: INI颇老阑 促矫 佬菌嚼聪促.\n");
break;
case 'D': // Disconnect account 0 (useful when client crashes)
/*for( i = 0; i < now; i++ )
if( acctno[i] == 0 )
Network->Disconnect( i );
printf( "Account 0 disconnected" );*/
break;
case 'H': // Enable/Disable heartbeat
/*if (heartbeat==1) printf("UOX3: Heartbeat Disabled\n");
else printf("UOX3: Heartbeat Enabled\n");
heartbeat = !heartbeat;*/
break;
case 'P': // Display profiling information
/*LogMessage("欺器刚胶 待橇:\n");
LogMessage("匙侗 内靛: %fmsec [%i samples]\n" _ (float)((float)networkTime/(float)networkTimeCount) _ networkTimeCount);
LogMessage("矫埃 内靛: %fmsec [%i samples]\n" _ (float)((float)timerTime/(float)timerTimeCount) _ timerTimeCount);
LogMessage("磊悼 内靛: %fmsec [%i samples]\n" _ (float)((float)autoTime/(float)autoTimeCount) _ autoTimeCount);
LogMessage("风橇 鸥烙: %fmsec [%i samples]\n" _ (float)((float)loopTime/(float)loopTimeCount) _ loopTimeCount);
//LogMessage("某腐磐: %i/%i - Items: %i/%i (Dynamic)\n" _ chars.Count() _ cmem _ items.Count() _ imem);
LogMessage("矫鼓 荤努: %f per sec\n" _ (1000.0*(1.0/(float)((float)loopTime/(float)loopTimeCount))));*/
printf("欺器刚胶 待橇:\n");
printf("匙侗 内靛: %fmsec [%i samples]\n" , (float)((float)networkTime/(float)networkTimeCount) , networkTimeCount);
printf("矫埃 内靛: %fmsec [%i samples]\n" , (float)((float)timerTime/(float)timerTimeCount) , timerTimeCount);
printf("磊悼 内靛: %fmsec [%i samples]\n" , (float)((float)autoTime/(float)autoTimeCount) , autoTimeCount);
printf("风橇 鸥烙: %fmsec [%i samples]\n" , (float)((float)loopTime/(float)loopTimeCount) , loopTimeCount);
//LogMessage("某腐磐: %i/%i - Items: %i/%i (Dynamic)\n" _ chars.Count() _ cmem _ items.Count() _ imem);
printf("矫鼓 荤努: 檬寸 %f \n",(1000.0*(1.0/(float)((float)loopTime/(float)loopTimeCount))));
break;
case 'W': // Display logged in chars
/*printf("Current Users in the World:\n");
j = 0;
for (i=0;i<now;i++)
{
if(perm[i]) //Keeps NPC's from appearing on the list
{
j++;
printf("%i) %s [%x %x %x %x]\n", (j-1), chars[currchar[i]].name, chars[currchar[i]].ser1, chars[currchar[i]].ser2, chars[currchar[i]].ser3, chars[currchar[i]].ser4);
}
}
printf("Total Users Online: %d\n", j);*/
break;
case 'A': //reload the accounts file
/*printf( "UOX3: Reloading Accounts file..." );
Admin->LoadAccounts();
printf( "Done!" );*/
break;
case 'R':
/*printf("UOX3: Reloading Server/Spawn/Regions/Spells Script files:\n");
printf( "Loading spawn regions..." );
loadspawnregions();
printf( "Done!\nLoading regions..." );
loadregions();
printf( "Done!\nLoading server.scp..." );
loadserverscript();
printf( "Done!\nLoading Spells.scp...");
Magic->LoadScript();
printf( "Done!\n" );
Commands->Load();
printf( "Reloading races.scp..." );
delete Races;
if(( Races = new cRaces ) == NULL ) Shutdown( FATAL_UOX3_ALLOC_RACES );
Races->load();
printf( "Done!\n" );
*/
break;
case 'M':
/*unsigned long int tmp, total;
total = 0;
tmp = 0;
printf("UOX3 Memory Information:\n" );
printf(" Cache:\n");
printf(" Tiles: %li bytes\n", Map->TileMem );
printf(" Statics: %li bytes\n", Map->StaMem );
printf(" Version: %li bytes\n", Map->versionMemory );
printf(" Map0: %i bytes [%i Hits - %i Misses]\n", 9*MAP0CACHE, Map->Map0CacheHit, Map->Map0CacheMiss );
total += tmp = chars.Size() + cmem*sizeof( teffect_st ) + cmem*sizeof(char) + cmem*sizeof(int)*5;
printf(" Characters: %li bytes [%i chars (%i allocated)]\n", tmp, chars.Count(), cmem );
total += tmp = items.Size() + imem*sizeof(int)*4;
printf(" Items: %li bytes [%i items (%i allocated)]\n", tmp, items.Count(), imem );
printf(" You save I:%li & C:%li bytes!\n", ((imem*sizeof(item_st))-items.Size()), (((cmem*sizeof(char_st))-chars.Size())+((sizeof(teffect_st)*5*cmem)-(sizeof(teffect_st)*cmem))));
total+= tmp = 69 * sizeof( splInfo_st );
printf(" Spells: %i bytes\n", tmp );
printf(" Sizes:\n" );
printf(" Item_st: %i bytes\n", sizeof( item_st ) );
printf(" Char_st: %i bytes\n", sizeof( char_st ) );
printf(" TEffect: %i bytes (%i total)\n", sizeof( teffect_st ), sizeof( teffect_st ) * Effects->Count() );
printf(" Int : %i bytes\n", sizeof( int ) );
printf(" Short : %i bytes\n", sizeof( short int ) );
total+= tmp = Map->TileMem + Map->StaMem + Map->versionMemory;
printf("Approximate Total: %i bytes\n", total );
//printf("End of Memory Information.\n" );*/
break;
case '?':
printf("==疙飞虐甸==\n");
printf(" <Esc> 唱 Q: 辑滚 辆丰.\n");
printf(" # - 岿靛 历厘\n");
printf(" A - 拌沥 促矫 佬扁\n");
printf(" 1 - 规价 抛胶飘\n");
//printf(" C - Dump Items.scp menu into a file.\n" );
//printf(" D - Disconnect Account 0\n");
//printf(" H - Toggle hearbeat\n");
printf(" I - Reload INI file.\n");
//printf(" L - Toggle layer Display\n");
//printf(" M - Display Memory Information\n" );
printf(" P - 欺器刚胶 待橇\n");
//printf(" R - Reload server, spawn, commands, regions and races scripts.\n");
printf(" S - 焊龋 葛靛 "); // This key was missing
if( secure )
printf( "[臼 鞠]栏肺 函版\n" );
else
printf( "[荤侩窃]栏肺 函版\n" );
printf(" T - 矫胶袍 辆丰: 10盒饶俊 辆丰.\n");
printf(" W - 肺弊牢茄 某腐磐 焊咯林扁\n");
//printf(" X - Mass Disconnect\n" );
printf(" ? - 疙飞虐甸 (捞芭)\n");
printf("====场====\n");
break;
case 'b':
case 'B':
// printf( "Item_st: %i\nTile_st: %i\nChar_st: %i\nmulti_st: %i\nland_st: %i\n", sizeof( item_st ), sizeof( tile_st ), sizeof( char_st ), sizeof( st_multi ), sizeof( land_st ) );
printf( "acct: %i\n", sizeof( acct ) );
break;
case 'X':
//for( i = now - 1; i >= 0; i-- )
// Network->Disconnect( i );
break;
case 0x0D: // User hit [Enter]
break;
default:
printf("WOX2: 虐 %c [%x] 绰 棵官弗 疙飞捞 酒凑聪促. '?' 甫 穿福矫搁 档框富阑 焊角 荐 乐嚼聪促\n",c,c); // Looks Better
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -