bool CLIENT_DESC::Connect(int iPhaseWhenSucceed) { if (iPhaseWhenSucceed != 0) m_iPhaseWhenSucceed = iPhaseWhenSucceed; if (get_global_time() - m_LastTryToConnectTime < 3) // 3초 return false; m_LastTryToConnectTime = get_global_time(); if (m_sock != INVALID_SOCKET) return false; sys_log(0, "SYSTEM: Trying to connect to %s:%d", m_stHost.c_str(), m_wPort); m_sock = socket_connect(m_stHost.c_str(), m_wPort); if (m_sock != INVALID_SOCKET) { sys_log(0, "SYSTEM: connected to server (fd %d, ptr %p)", m_sock, this); fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_READ, false); fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_WRITE, false); SetPhase(m_iPhaseWhenSucceed); return true; } else { SetPhase(PHASE_CLIENT_CONNECTING); return false; } }
int marriage_get_married_time(lua_State* L) { LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr(); marriage::TMarriage* pMarriage = marriage::CManager::instance().Get(ch->GetPlayerID()); if (!pMarriage) { sys_err("trying to get time for not married character"); lua_pushnumber(L, 0); return 1; } lua_pushnumber(L, get_global_time() - pMarriage->marry_time); return 1; }
void CHorseNameManager::Validate(LPCHARACTER pChar) { CAffect *pkAff = pChar->FindAffect(AFFECT_HORSE_NAME); if ( pkAff != NULL ) { if ( pChar->GetQuestFlag("horse_name.valid_till") < get_global_time() ) { pChar->HorseSummon(false, true); pChar->RemoveAffect(pkAff); UpdateHorseName(pChar->GetPlayerID(), "", true); pChar->HorseSummon(true, true); } else { ++(pkAff->lDuration); } } }
int horse_set_name(lua_State* L) { // 리턴값 // 0 : 소유한 말이 없다 // 1 : 잘못된 이름이다 // 2 : 이름 바꾸기 성공 if ( lua_isstring(L, -1) != true ) return 0; LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr(); if ( ch->GetHorseLevel() > 0 ) { const char* pHorseName = lua_tostring(L, -1); if ( pHorseName == NULL || check_name(pHorseName) == 0 ) { lua_pushnumber(L, 1); } else { int nHorseNameDuration = test_server == true ? 60*5 : 60*60*24*30; ch->SetQuestFlag("horse_name.valid_till", get_global_time() + nHorseNameDuration); ch->AddAffect(AFFECT_HORSE_NAME, 0, 0, 0, PASSES_PER_SEC(nHorseNameDuration), 0, true); CHorseNameManager::instance().UpdateHorseName(ch->GetPlayerID(), lua_tostring(L, -1), true); ch->HorseSummon(false, true); ch->HorseSummon(true, true); lua_pushnumber(L, 2); } } else { lua_pushnumber(L, 0); } return 1; }
DWORD DESC_MANAGER::CreateHandshake() { char crc_buf[8]; crc_t crc; DESC_HANDSHAKE_MAP::iterator it; RETRY: do { DWORD val = thecore_random() % (1024 * 1024); *(DWORD *) (crc_buf ) = val; *((DWORD *) crc_buf + 1) = get_global_time(); crc = GetCRC32(crc_buf, 8); it = m_map_handshake.find(crc); } while (it != m_map_handshake.end()); if (crc == 0) goto RETRY; return (crc); }
int CHARACTER::ProcessAffect() { bool bDiff = false; CAffect *pkAff = NULL; // // 프리미엄 처리 // for (int i = 0; i <= PREMIUM_MAX_NUM; ++i) { int aff_idx = i + AFFECT_PREMIUM_START; pkAff = FindAffect(aff_idx); if (!pkAff) continue; int remain = GetPremiumRemainSeconds(i); if (remain < 0) { RemoveAffect(aff_idx); bDiff = true; } else pkAff->lDuration = remain + 1; } ////////// HAIR_AFFECT pkAff = FindAffect(AFFECT_HAIR); if (pkAff) { // IF HAIR_LIMIT_TIME() < CURRENT_TIME() if ( this->GetQuestFlag("hair.limit_time") < get_global_time()) { // SET HAIR NORMAL this->SetPart(PART_HAIR, 0); // REMOVE HAIR AFFECT RemoveAffect(AFFECT_HAIR); } else { // INCREASE AFFECT DURATION ++(pkAff->lDuration); } } ////////// HAIR_AFFECT // CHorseNameManager::instance().Validate(this); TAffectFlag afOld = m_afAffectFlag; long lMovSpd = GetPoint(POINT_MOV_SPEED); long lAttSpd = GetPoint(POINT_ATT_SPEED); itertype(m_list_pkAffect) it; it = m_list_pkAffect.begin(); while (it != m_list_pkAffect.end()) { pkAff = *it; bool bEnd = false; if (pkAff->dwType >= GUILD_SKILL_START && pkAff->dwType <= GUILD_SKILL_END) { if (!GetGuild() || !GetGuild()->UnderAnyWar()) bEnd = true; } if (pkAff->lSPCost > 0) { if (GetSP() < pkAff->lSPCost) bEnd = true; else PointChange(POINT_SP, -pkAff->lSPCost); } // AFFECT_DURATION_BUG_FIX // 무한 효과 아이템도 시간을 줄인다. // 시간을 매우 크게 잡기 때문에 상관 없을 것이라 생각됨. if ( --pkAff->lDuration <= 0 ) { bEnd = true; } // END_AFFECT_DURATION_BUG_FIX if (bEnd) { it = m_list_pkAffect.erase(it); ComputeAffect(pkAff, false); bDiff = true; if (IsPC()) { SendAffectRemovePacket(GetDesc(), GetPlayerID(), pkAff->dwType, pkAff->bApplyOn); } CAffect::Release(pkAff); continue; } ++it; } if (bDiff) { if (afOld != m_afAffectFlag || lMovSpd != GetPoint(POINT_MOV_SPEED) || lAttSpd != GetPoint(POINT_ATT_SPEED)) { UpdatePacket(); } CheckMaximumPoints(); } if (m_list_pkAffect.empty()) return true; return false; }
void heartbeat(LPHEART ht, int pulse) { DWORD t; t = get_dword_time(); num_events_called += event_process(pulse); s_dwProfiler[PROF_EVENT] += (get_dword_time() - t); t = get_dword_time(); // 1ГКё¶ґЩ if (!(pulse % ht->passes_per_sec)) { #ifdef ENABLE_LIMIT_TIME if ((unsigned)get_global_time() >= GLOBAL_LIMIT_TIME) { g_bShutdown = true; } #endif if (!g_bAuthServer) { TPlayerCountPacket pack; pack.dwCount = DESC_MANAGER::instance().GetLocalUserCount(); db_clientdesc->DBPacket(HEADER_GD_PLAYER_COUNT, 0, &pack, sizeof(TPlayerCountPacket)); } else DESC_MANAGER::instance().ProcessExpiredLoginKey(); int count = 0; std::map<DWORD, CLoginSim *>::const_iterator it = g_sim.begin(); while (it != g_sim.end()) { if (!it->second->IsCheck()) { it->second->SendLogin(); if (++count > 50) { sys_log(0, "FLUSH_SENT"); break; } } it++; } if (save_idx < g_vec_save.size()) { count = MIN(100, g_vec_save.size() - save_idx); for (int i = 0; i < count; ++i, ++save_idx) db_clientdesc->DBPacket(HEADER_GD_PLAYER_SAVE, 0, &g_vec_save[save_idx], sizeof(TPlayerTable)); sys_log(0, "SAVE_FLUSH %d", count); } } // // 25 PPS(Pulse per second) ¶у°н °ЎБ¤ЗТ ¶§ // // ѕа 1.16ГКё¶ґЩ if (!(pulse % (passes_per_sec + 4))) CHARACTER_MANAGER::instance().ProcessDelayedSave(); //4ГК ё¶ґЩ #if defined (__FreeBSD__) && defined(__FILEMONITOR__) if (!(pulse % (passes_per_sec * 5))) { FileMonitorFreeBSD::Instance().Update(pulse); } #endif // ѕа 5.08ГКё¶ґЩ if (!(pulse % (passes_per_sec * 5 + 2))) { ITEM_MANAGER::instance().Update(); DESC_MANAGER::instance().UpdateLocalUserCount(); } s_dwProfiler[PROF_HEARTBEAT] += (get_dword_time() - t); DBManager::instance().Process(); AccountDB::instance().Process(); CPVPManager::instance().Process(); if (g_bShutdown) { if (thecore_pulse() > g_shutdown_disconnect_pulse) { const DESC_MANAGER::DESC_SET & c_set_desc = DESC_MANAGER::instance().GetClientSet(); std::for_each(c_set_desc.begin(), c_set_desc.end(), ::SendDisconnectFunc()); g_shutdown_disconnect_pulse = INT_MAX; } else if (thecore_pulse() > g_shutdown_disconnect_force_pulse) { const DESC_MANAGER::DESC_SET & c_set_desc = DESC_MANAGER::instance().GetClientSet(); std::for_each(c_set_desc.begin(), c_set_desc.end(), ::DisconnectFunc()); } else if (thecore_pulse() > g_shutdown_disconnect_force_pulse + PASSES_PER_SEC(5)) { thecore_shutdown(); } } }