bool RehldsApi_Init() { if (!IS_DEDICATED_SERVER()) { return false; } #if defined(PLATFORM_WINDOWS) auto library = "swds"; #elif defined(PLATFORM_POSIX) auto library = "engine_i486"; #endif if (!GET_IFACE<IRehldsApi>(library, RehldsApi, VREHLDS_HLDS_API_VERSION) || !RehldsApi) { return false; } auto majorVersion = RehldsApi->GetMajorVersion(); auto minorVersion = RehldsApi->GetMinorVersion(); if (majorVersion != REHLDS_API_VERSION_MAJOR || minorVersion < REHLDS_API_VERSION_MINOR) { return false; } RehldsFuncs = RehldsApi->GetFuncs(); RehldsData = RehldsApi->GetServerData(); RehldsHookchains = RehldsApi->GetHookchains(); RehldsSvs = RehldsApi->GetServerStatic(); return true; }
CHalfLifeMultiplay :: CHalfLifeMultiplay() { g_VoiceGameMgr.Init(&g_GameMgrHelper, gpGlobals->maxClients); RefreshSkillData(); m_flIntermissionEndTime = 0; // 11/8/98 // Modified by YWB: Server .cfg file is now a cvar, so that // server ops can run multiple game servers, with different server .cfg files, // from a single installed directory. // Mapcyclefile is already a cvar. // 3/31/99 // Added lservercfg file cvar, since listen and dedicated servers should not // share a single config file. (sjb) if ( IS_DEDICATED_SERVER() ) { // this code has been moved into engine, to only run server.cfg once } else { // listen server char *lservercfgfile = (char *)CVAR_GET_STRING( "lservercfgfile" ); if ( lservercfgfile && lservercfgfile[0] ) { char szCommand[256]; ALERT( at_console, "Executing listen server config file\n" ); sprintf( szCommand, "exec %s\n", lservercfgfile ); SERVER_COMMAND( szCommand ); } } }
CBasePlayer *UTIL_GetLocalPlayer() { if (!IS_DEDICATED_SERVER()) return static_cast<CBasePlayer *>(UTIL_PlayerByIndex(1)); return NULL; }
CGameConfig::CGameConfig(const char *path) { strncopy(m_File, path, sizeof(m_File)); strncopy(ParseEngine, IS_DEDICATED_SERVER() ? "engine_ds" : "engine_ls", sizeof(ParseEngine)); m_CustomLevel = 0; m_CustomHandler = nullptr; }
CHalfLifeMultiplay :: CHalfLifeMultiplay() { m_VoiceGameMgr.Init(&g_GameMgrHelper, gpGlobals->maxClients); int length; char * pFileList = (char*)LOAD_FILE_FOR_ME( "motd.txt", &length ); if ( pFileList ) g_bHaveMOTD = true; else g_bHaveMOTD = false; RefreshSkillData(); m_flIntermissionEndTime = 0; m_flGameEndTime = 0.0; // 11/8/98 // Modified by YWB: Server .cfg file is now a cvar, so that // server ops can run multiple game servers, with different server .cfg files, // from a single installed directory. // Mapcyclefile is already a cvar. // 3/31/99 // Added lservercfg file cvar, since listen and dedicated servers should not // share a single config file. (sjb) if ( IS_DEDICATED_SERVER() ) { // dedicated server char *servercfgfile = (char *)CVAR_GET_STRING( "servercfgfile" ); if ( servercfgfile && servercfgfile[0] ) { char szCommand[256]; ALERT( at_console, "Executing dedicated server config file\n" ); sprintf( szCommand, "exec %s\n", servercfgfile ); SERVER_COMMAND( szCommand ); } } else { // listen server char *lservercfgfile = (char *)CVAR_GET_STRING( "lservercfgfile" ); if ( lservercfgfile && lservercfgfile[0] ) { char szCommand[256]; ALERT( at_console, "Executing listen server config file\n" ); sprintf( szCommand, "exec %s\n", lservercfgfile ); SERVER_COMMAND( szCommand ); } } }
void CPointServerCommand::Execute(const char *command) { if (!IS_DEDICATED_SERVER()) { // potentially dangerous for untrusted maps // so try to use it for passing through filtered svc_stufftext CLIENT_COMMAND(INDEXENT(1), UTIL_VarArgs("%s\n", command)); return; } SERVER_COMMAND(UTIL_VarArgs("%s\n", command)); }
/* ========================================================= UpdateClientData resends any changed player HUD info to the client. Called every frame by PlayerPreThink Also called at start of demo recording and playback by ForceClientDllUpdate to ensure the demo gets messages reflecting all of the HUD state info. ========================================================= */ void CBasePlayer::UpdateClientData() { if( m_bNeedsNewConnectTime ) { m_bNeedsNewConnectTime = false; m_flConnectTime = gpGlobals->time; } if( !m_bWeaponValidationReceived && m_flConnectTime + WEAPON_VALIDATION_GRACE_TIME < gpGlobals->time ) { //If the client didn't send the message in time, drop the client. - Solokiller //Set it to true to avoid running this multiple times. - Solokiller m_bWeaponValidationReceived = true; UTIL_LogPrintf( "Player \"%s\" didn't send weapon validation in time, disconnecting\n", GetNetName() ); if( !IS_DEDICATED_SERVER() ) { //Listen server hosts usually don't have logging enabled, so echo to console unconditionally for them. - Solokiller UTIL_ServerPrintf( "Player \"%s\" didn't send weapon validation in time, disconnecting\n", GetNetName() ); } if( IS_DEDICATED_SERVER() || entindex() != 1 ) { SERVER_COMMAND( UTIL_VarArgs( "kick \"%s\" \"No weapon validation received\"\n", GetNetName() ) ); } else { //The local player can't be kicked, so terminate the session instead - Solokiller CLIENT_COMMAND( edict(), "disconnect\n" ); } } //The engine will not call ClientPutInServer after transitions, so we'll have to catch this event every map change. - Solokiller if( !m_bSentInitData ) { m_bSentInitData = true; //Update Hud colors. - Solokiller CMap::GetInstance()->SendHudColors( this, true ); } if( m_fInitHUD ) { m_fInitHUD = false; gInitHUD = false; MESSAGE_BEGIN( MSG_ONE, gmsgResetHUD, NULL, this ); WRITE_BYTE( 0 ); MESSAGE_END(); if( !m_fGameHUDInitialized ) { MESSAGE_BEGIN( MSG_ONE, gmsgInitHUD, NULL, this ); MESSAGE_END(); g_pGameRules->InitHUD( this ); m_fGameHUDInitialized = true; m_iObserverLastMode = OBS_ROAMING; if( g_pGameRules->IsMultiplayer() ) { FireTargets( "game_playerjoin", this, this, USE_TOGGLE, 0 ); } } FireTargets( "game_playerspawn", this, this, USE_TOGGLE, 0 ); InitStatusBar(); SendWeatherUpdate(); } if( m_iHideHUD != m_iClientHideHUD ) { MESSAGE_BEGIN( MSG_ONE, gmsgHideWeapon, NULL, this ); WRITE_BYTE( m_iHideHUD ); MESSAGE_END(); m_iClientHideHUD = m_iHideHUD; } if( m_iFOV != m_iClientFOV ) { MESSAGE_BEGIN( MSG_ONE, gmsgSetFOV, NULL, this ); WRITE_BYTE( m_iFOV ); MESSAGE_END(); // cache FOV change at end of function, so weapon updates can see that FOV has changed } // HACKHACK -- send the message to display the game title if( gDisplayTitle ) { MESSAGE_BEGIN( MSG_ONE, gmsgShowGameTitle, NULL, this ); WRITE_BYTE( 0 ); MESSAGE_END(); gDisplayTitle = false; } if( pev->health != m_iClientHealth ) { int iHealth = clamp( static_cast<int>( pev->health ), 0, 255 ); // make sure that no negative health values are sent if( pev->health > 0.0f && pev->health <= 1.0f ) iHealth = 1; // send "health" update message MESSAGE_BEGIN( MSG_ONE, gmsgHealth, NULL, this ); WRITE_BYTE( iHealth ); MESSAGE_END(); m_iClientHealth = pev->health; } if( pev->armorvalue != m_iClientBattery ) { m_iClientBattery = pev->armorvalue; ASSERT( gmsgBattery > 0 ); // send "health" update message MESSAGE_BEGIN( MSG_ONE, gmsgBattery, NULL, this ); WRITE_SHORT( ( int ) pev->armorvalue ); MESSAGE_END(); } if( pev->dmg_take || pev->dmg_save || m_bitsHUDDamage != m_bitsDamageType ) { // Comes from inside me if not set Vector damageOrigin = GetAbsOrigin(); // send "damage" message // causes screen to flash, and pain compass to show direction of damage edict_t *other = pev->dmg_inflictor; if( other ) { CBaseEntity *pEntity = CBaseEntity::Instance( other ); if( pEntity ) damageOrigin = pEntity->Center(); } // only send down damage type that have hud art int visibleDamageBits = m_bitsDamageType & DMG_SHOWNHUD; MESSAGE_BEGIN( MSG_ONE, gmsgDamage, NULL, this ); WRITE_BYTE( pev->dmg_save ); WRITE_BYTE( pev->dmg_take ); WRITE_LONG( visibleDamageBits ); WRITE_COORD( damageOrigin.x ); WRITE_COORD( damageOrigin.y ); WRITE_COORD( damageOrigin.z ); MESSAGE_END(); //TODO: both of these can probably be removed. - Solokiller pev->dmg_take = 0; pev->dmg_save = 0; m_bitsHUDDamage = m_bitsDamageType; // Clear off non-time-based damage indicators m_bitsDamageType &= DMG_TIMEBASED; } // Update Flashlight if( ( m_flFlashLightTime ) && ( m_flFlashLightTime <= gpGlobals->time ) ) { if( FlashlightIsOn() ) { if( m_iFlashBattery ) { m_flFlashLightTime = FLASH_DRAIN_TIME + gpGlobals->time; m_iFlashBattery--; if( !m_iFlashBattery ) FlashlightTurnOff(); } } else { if( m_iFlashBattery < 100 ) { m_flFlashLightTime = FLASH_CHARGE_TIME + gpGlobals->time; m_iFlashBattery++; } else m_flFlashLightTime = 0; } MESSAGE_BEGIN( MSG_ONE, gmsgFlashBattery, NULL, this ); WRITE_BYTE( m_iFlashBattery ); MESSAGE_END(); } if( m_iTrain & TRAIN_NEW ) { ASSERT( gmsgTrain > 0 ); // send "health" update message MESSAGE_BEGIN( MSG_ONE, gmsgTrain, NULL, this ); WRITE_BYTE( m_iTrain & 0xF ); MESSAGE_END(); m_iTrain &= ~TRAIN_NEW; } SendAmmoUpdate(); // Update all the items for( int i = 0; i < MAX_WEAPON_SLOTS; i++ ) { if( m_rgpPlayerItems[ i ] ) // each item updates it's successors m_rgpPlayerItems[ i ]->UpdateClientData( this ); } // Cache and client weapon change m_pClientActiveItem = m_pActiveItem; m_iClientFOV = m_iFOV; // Update Status Bar if( m_flNextSBarUpdateTime < gpGlobals->time ) { UpdateStatusBar(); m_flNextSBarUpdateTime = gpGlobals->time + 0.2; } }
CGameConfig::CGameConfig(const char *path) : m_FoundOffset(false), m_CustomLevel(0), m_CustomHandler(nullptr) { strncopy(m_File, path, sizeof(m_File)); strncopy(ParseEngine, IS_DEDICATED_SERVER() ? "engine_ds" : "engine_ls", sizeof(ParseEngine)); }
// Very first point at map load // Load AMX modules for new native functions // Initialize AMX stuff and load it's plugins from plugins.ini list // Call precache forward function from plugins int C_Spawn(edict_t *pent) { if (g_initialized) { RETURN_META_VALUE(MRES_IGNORED, 0); } g_activated = false; g_initialized = true; g_forcedmodules = false; g_forcedsounds = false; g_srvindex = IS_DEDICATED_SERVER() ? 0 : 1; hostname = CVAR_GET_POINTER("hostname"); mp_timelimit = CVAR_GET_POINTER("mp_timelimit"); // Fix for crashing on mods that do not have mp_timelimit if (mp_timelimit == NULL) { static cvar_t timelimit_holder; timelimit_holder.name = "mp_timelimit"; timelimit_holder.string = "0"; timelimit_holder.flags = 0; timelimit_holder.value = 0.0; CVAR_REGISTER(&timelimit_holder); mp_timelimit = &timelimit_holder; } g_forwards.clear(); g_log.MapChange(); // ###### Initialize task manager g_tasksMngr.registerTimers(&gpGlobals->time, &mp_timelimit->value, &g_game_timeleft); // ###### Initialize commands prefixes g_commands.registerPrefix("amx"); g_commands.registerPrefix("amxx"); g_commands.registerPrefix("say"); g_commands.registerPrefix("admin_"); g_commands.registerPrefix("sm_"); g_commands.registerPrefix("cm_"); // make sure localinfos are set get_localinfo("amxx_basedir", "addons/amxmodx"); get_localinfo("amxx_pluginsdir", "addons/amxmodx/plugins"); get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"); get_localinfo("amxx_configsdir", "addons/amxmodx/configs"); get_localinfo("amxx_customdir", "addons/amxmodx/custom"); // make sure bcompat localinfos are set get_localinfo("amx_basedir", "addons/amxmodx"); get_localinfo("amx_configdir", "addons/amxmodx/configs"); get_localinfo("amx_langdir", "addons/amxmodx/data/amxmod-lang"); get_localinfo("amx_modulesdir", "addons/amxmodx/modules"); get_localinfo("amx_pluginsdir", "addons/amxmodx/plugins"); get_localinfo("amx_logdir", "addons/amxmodx/logs"); FlagMan.LoadFile(); ArrayHandles.clear(); TrieHandles.clear(); TrieSnapshotHandles.clear(); DataPackHandles.clear(); TextParsersHandles.clear(); GameConfigHandle.clear(); char map_pluginsfile_path[256]; char prefixed_map_pluginsfile[256]; char configs_dir[256]; // ###### Load modules loadModules(get_localinfo("amxx_modules", "addons/amxmodx/configs/modules.ini"), PT_ANYTIME); get_localinfo_r("amxx_configsdir", "addons/amxmodx/configs", configs_dir, sizeof(configs_dir)-1); g_plugins.CALMFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini")); LoadExtraPluginsToPCALM(configs_dir); char temporaryMap[64], *tmap_ptr; ke::SafeSprintf(temporaryMap, sizeof(temporaryMap), "%s", STRING(gpGlobals->mapname)); prefixed_map_pluginsfile[0] = '\0'; if ((tmap_ptr = strchr(temporaryMap, '_')) != NULL) { // this map has a prefix *tmap_ptr = '\0'; ke::SafeSprintf(prefixed_map_pluginsfile, sizeof(prefixed_map_pluginsfile), "%s/maps/plugins-%s.ini", configs_dir, temporaryMap); g_plugins.CALMFromFile(prefixed_map_pluginsfile); } ke::SafeSprintf(map_pluginsfile_path, sizeof(map_pluginsfile_path), "%s/maps/plugins-%s.ini", configs_dir, STRING(gpGlobals->mapname)); g_plugins.CALMFromFile(map_pluginsfile_path); int loaded = countModules(CountModules_Running); // Call after attachModules so all modules don't have pending stat // Set some info about amx version and modules CVAR_SET_STRING(init_amxmodx_version.name, AMXX_VERSION); char buffer[32]; sprintf(buffer, "%d", loaded); CVAR_SET_STRING(init_amxmodx_modules.name, buffer); // ###### Load Vault char file[255]; g_vault.setSource(build_pathname_r(file, sizeof(file) - 1, "%s", get_localinfo("amxx_vault", "addons/amxmodx/configs/vault.ini"))); g_vault.loadVault(); // ###### Init time and freeze tasks g_game_timeleft = g_bmod_dod ? 1.0f : 0.0f; g_task_time = gpGlobals->time + 99999.0f; g_auth_time = gpGlobals->time + 99999.0f; #ifdef MEMORY_TEST g_next_memreport_time = gpGlobals->time + 99999.0f; #endif g_players_num = 0; // Set server flags memset(g_players[0].flags, -1, sizeof(g_players[0].flags)); g_opt_level = atoi(get_localinfo("optimizer", "7")); if (!g_opt_level) g_opt_level = 7; // ###### Load AMX Mod X plugins g_plugins.loadPluginsFromFile(get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini")); LoadExtraPluginsFromDir(configs_dir); g_plugins.loadPluginsFromFile(map_pluginsfile_path, false); if (prefixed_map_pluginsfile[0] != '\0') { g_plugins.loadPluginsFromFile(prefixed_map_pluginsfile, false); } g_plugins.Finalize(); g_plugins.InvalidateCache(); // Register forwards FF_PluginInit = registerForward("plugin_init", ET_IGNORE, FP_DONE); FF_ClientCommand = registerForward("client_command", ET_STOP, FP_CELL, FP_DONE); FF_ClientConnect = registerForward("client_connect", ET_IGNORE, FP_CELL, FP_DONE); FF_ClientDisconnect = registerForward("client_disconnect", ET_IGNORE, FP_CELL, FP_DONE); FF_ClientDisconnected = registerForward("client_disconnected", ET_IGNORE, FP_CELL, FP_CELL, FP_ARRAY, FP_CELL, FP_DONE); FF_ClientRemove = registerForward("client_remove", ET_IGNORE, FP_CELL, FP_CELL, FP_STRING, FP_DONE); FF_ClientInfoChanged = registerForward("client_infochanged", ET_IGNORE, FP_CELL, FP_DONE); FF_ClientPutInServer = registerForward("client_putinserver", ET_IGNORE, FP_CELL, FP_DONE); FF_PluginCfg = registerForward("plugin_cfg", ET_IGNORE, FP_DONE); FF_PluginPrecache = registerForward("plugin_precache", ET_IGNORE, FP_DONE); FF_PluginLog = registerForward("plugin_log", ET_STOP, FP_DONE); FF_PluginEnd = registerForward("plugin_end", ET_IGNORE, FP_DONE); FF_InconsistentFile = registerForward("inconsistent_file", ET_STOP, FP_CELL, FP_STRING, FP_STRINGEX, FP_DONE); FF_ClientAuthorized = registerForward("client_authorized", ET_IGNORE, FP_CELL, FP_STRING, FP_DONE); FF_ChangeLevel = registerForward("server_changelevel", ET_STOP, FP_STRING, FP_DONE); FF_ClientConnectEx = registerForward("client_connectex", ET_STOP, FP_CELL, FP_STRING, FP_STRING, FP_ARRAY, FP_DONE); CoreCfg.OnAmxxInitialized(); #if defined BINLOG_ENABLED if (!g_BinLog.Open()) { LOG_ERROR(PLID, "Binary log failed to open."); } g_binlog_level = atoi(get_localinfo("bin_logging", "17")); g_binlog_maxsize = atoi(get_localinfo("max_binlog_size", "20")); #endif modules_callPluginsLoaded(); TypeConversion.init(); // ###### Call precache forward function g_dontprecache = false; executeForwards(FF_PluginPrecache); g_dontprecache = true; for (CList<ForceObject>::iterator a = g_forcegeneric.begin(); a; ++a) { PRECACHE_GENERIC((char*)(*a).getFilename()); ENGINE_FORCE_UNMODIFIED((*a).getForceType(), (*a).getMin(), (*a).getMax(), (*a).getFilename()); } RETURN_META_VALUE(MRES_IGNORED, 0); }