Esempio n. 1
0
bool parseZonesConfig(const char* path, const char* file)
{
	FILE* fp = fopen(path, "rt");

	if (!fp)
		return false;

	char buf[2048];
	size_t line_number = 0;
	CFields fields;

	char format[] = "[en] origin mins maxs";
	fields.parseFormat(format);

	while (fgets(buf, sizeof buf, fp)) {
		char* line = trimbuf(buf);
		line_number++;

		if (line[0] == '\xEF' && line[1] == '\xBB' && line[2] == '\xBF') // BOM
			line += 3;

		if (!line[0])
			continue;

		if (!parseLineToFields(line, fields, file, line_number))
			continue;

		if (!fields.getCount())
			continue;

		auto origin = fields.getField(dt_origin);
		auto mins = fields.getField(dt_mins);
		auto maxs = fields.getField(dt_maxs);
		auto lcorner = fields.getField(dt_lcorner);
		auto hcorner = fields.getField(dt_hcorner);

		translation_t translations[16];
		size_t translations_count = fields.getTranslations(translations, arraysize(translations));

		if (!translations_count) {
			LCPrintf("Invalid zone without name at line %i in %s\n", line_number, file);
			continue;
		}

		if (origin && mins && maxs) {
			g_zoneManager.addZone(translations, translations_count, origin->vec, mins->vec, maxs->vec);
			continue;
		}

		if (lcorner && hcorner) {
			g_zoneManager.addZone(translations, translations_count, lcorner->vec, hcorner->vec);
			continue;
		}

		LCPrintf("Not enough coordinates to create zone at line %i in %s\n", line_number, file);
	}

	return true;
}
Esempio n. 2
0
bool loadZonesConfig()
{
	char path[260], file[260];
	snprintf(file, sizeof file, "info_zone_%s.ini", STRING(gpGlobals->mapname));
	g_amxxapi.BuildPathnameR(path, sizeof path - 1, "%s/info_zone/%s", g_amxxapi.GetLocalInfo("amxx_datadir", "addons/amxmodx/data"), file);

	if (!parseZonesConfig(path, file)) {
		LCPrintf("Zones file %s not found\n", file);
		return false;
	}

	if (!g_zoneManager.getZonesCount()) {
		return false;
	}

	LCPrintf("Loaded %i zones for map %s\n", g_zoneManager.getZonesCount(), STRING(gpGlobals->mapname));
	return true;
}
Esempio n. 3
0
qboolean Steam_NotifyClientConnect_hook(IRehldsHook_Steam_NotifyClientConnect* chain, IGameClient *cl, const void *pvSteam2Key, unsigned int ucbSteam2Key) {
	if (g_CurrentAuthContext == NULL) {
		LCPrintf(true, "WARNING: %s is called outside auth context\n", __FUNCTION__);
		return chain->callNext(cl, pvSteam2Key, ucbSteam2Key);
	}

	qboolean authRes = chain->callNext(cl, pvSteam2Key, ucbSteam2Key);
	g_CurrentAuthContext->nativeAuthFailed = !authRes;

	return Renosteam_FinishClientAuth(cl) ? 1 : 0;
}
Esempio n. 4
0
void SV_ConnectClient_hook(IRehldsHook_SV_ConnectClient* chain) {
	if (g_CurrentAuthContext != NULL) {
		LCPrintf(true, "WARNING: %s: recursive call\n", __FUNCTION__);
		chain->callNext();
		return;
	}
	
	client_auth_context_t authContext = client_auth_context_t();
	g_CurrentAuthContext = &authContext;
	chain->callNext();
	g_CurrentAuthContext = NULL;
}
Esempio n. 5
0
void util_syserror(const char* fmt, ...)
{
	va_list	argptr;
	char buf[4096];
	va_start(argptr, fmt);
	vsnprintf(buf, ARRAYSIZE(buf) - 1, fmt, argptr);
	buf[ARRAYSIZE(buf) - 1] = 0;
	va_end(argptr);

	LCPrintf(true, "ERROR: %s", buf);
	*(int *)0 = 0;
}
Esempio n. 6
0
bool Revoice_RehldsApi_Init() {
	char failReason[2048];

#ifdef WIN32
	CSysModule* engineModule = Sys_LoadModule("swds.dll");
	if (!Revoice_RehldsApi_TryInit(engineModule, failReason)) {
		engineModule = Sys_LoadModule("filesystem_stdio.dll");
		if (!Revoice_RehldsApi_TryInit(engineModule, failReason)) {
			LCPrintf(true, "%s", failReason);
			return false;
		}
	}
#else
	CSysModule* engineModule = Sys_LoadModule("engine_i486.so");
	if (!Revoice_RehldsApi_TryInit(engineModule, failReason)) {
		LCPrintf(true, "%s", failReason);
		return false;
	}
#endif

	return true;
}
Esempio n. 7
0
bool loadMainConfig()
{
	auto regCvar = [](cvar_t* cvar) {g_engfuncs.pfnCvar_RegisterVariable(cvar); return g_engfuncs.pfnCVarGetPointer(cvar->name); };

	REG_CVAR(iz_zone_leave_time);
	REG_CVAR(iz_use_interval);
	REG_CVAR(iz_smooth_positioning);
	REG_CVAR(iz_max_aim_angle);
	REG_CVAR(iz_item_max_radius);

	char path[260], file[] = "info_zone.ini";
	g_amxxapi.BuildPathnameR(path, sizeof path - 1, "%s/%s", g_amxxapi.GetLocalInfo("amxx_configsdir", "addons/amxmodx/data"), file);
	memset(&g_config, 0, sizeof g_config);
	resetHudparms();

	if (!parseMainConfig(path, file)) {
		LCPrintf("Main config file %s not found.\n", file);
		return false;
	}

	LCPrintf("Main config loaded.\n");
	return true;
}
Esempio n. 8
0
bool Revoice_Load() {
	if (!Revoice_Utils_Init())
		return false;

	/*if (!Revoice_Cfg_LoadDefault())
		return false;*/

	if (!Revoice_RehldsApi_Init()) {
		LCPrintf(true, "Failed to locate REHLDS API\n");
		return false;
	}

	if (!Revoice_ReunionApi_Init())
		return false;

	Revoice_Init_Players();
	if (!Revoice_Main_Init()) {
		LCPrintf(true, "Initialization failed\n");
		return false;
	}

	return true;
}
Esempio n. 9
0
bool Revoice_RehldsApi_TryInit(CSysModule* engineModule, char* failureReason)
{
	if (!engineModule) {
		LCPrintf(true, "Failed to locate engine module\n");
		return false;
	}

	CreateInterfaceFn ifaceFactory = Sys_GetFactory(engineModule);
	if (!ifaceFactory) {
		sprintf(failureReason, "Failed to locate interface factory in engine module\n");
		return false;
	}

	int retCode = 0;
	g_RehldsApi = (IRehldsApi*)ifaceFactory(VREHLDS_HLDS_API_VERSION, &retCode);
	if (!g_RehldsApi) {
		sprintf(failureReason, "Failed to locate retrieve rehlds api interface from engine module, return code is %d\n", retCode);
		return false;
	}

	int majorVersion = g_RehldsApi->GetMajorVersion();
	int minorVersion = g_RehldsApi->GetMinorVersion();

	if (majorVersion != REHLDS_API_VERSION_MAJOR) {
		sprintf(failureReason, "REHLDS Api major version mismatch; expected %d, real %d\n", REHLDS_API_VERSION_MAJOR, majorVersion);
		return false;
	}

	if (minorVersion < REHLDS_API_VERSION_MINOR) {
		sprintf(failureReason, "REHLDS Api minor version mismatch; expected at least %d, real %d\n", REHLDS_API_VERSION_MINOR, majorVersion);
		return false;
	}

	g_RehldsFuncs = g_RehldsApi->GetFuncs();
	g_RehldsHookchains = g_RehldsApi->GetHookchains();
	g_RehldsSvs = g_RehldsApi->GetServerStatic();
	g_RehldsSv = g_RehldsApi->GetServerData();

	return true;
}
Esempio n. 10
0
int SV_FinishCertificateCheck_hook(IRehldsHook_SV_FinishCertificateCheck* chain, netadr_t *adr, int nAuthProtocol, char *szRawCertificate, char *userinfo) {
	if (g_CurrentAuthContext == NULL) {
		LCPrintf(true, "WARNING: %s is called outside auth context\n", __FUNCTION__);
		return chain->callNext(adr, nAuthProtocol, szRawCertificate, userinfo);
	}

	const char* hltv = g_engfuncs.pfnInfoKeyValue(userinfo, "*hltv");
	if (hltv && *hltv) {
		*g_CurrentAuthContext->pAuthProto = 3;
		g_CurrentAuthContext->hltv = true;

		sizebuf_t* pNetMessage = g_RehldsFuncs->GetNetMessage();
		int* pMsgReadCount = g_RehldsFuncs->GetMsgReadCount();

		//avoid "invalid steam certificate length" error
		if (*pMsgReadCount == pNetMessage->cursize) {
			pNetMessage->cursize += 1;
		}
	}
	
	return 1;
}
Esempio n. 11
0
void SV_WriteVoiceCodec_hooked(IRehldsHook_SV_WriteVoiceCodec* chain, sizebuf_t* sb) {

	IGameClient* cl = g_RehldsFuncs->GetHostClient();
	CRevoicePlayer* plr = GetPlayerByClientPtr(cl);

	switch (plr->GetCodecType()) {
	case vct_silk:
		g_RehldsFuncs->MSG_WriteByte(sb, svc_voiceinit); //svc_voiceinit
		g_RehldsFuncs->MSG_WriteString(sb, ""); //codec id
		g_RehldsFuncs->MSG_WriteByte(sb, 0); //quality
		break;

	case vct_speex:
		g_RehldsFuncs->MSG_WriteByte(sb, svc_voiceinit); //svc_voiceinit
		g_RehldsFuncs->MSG_WriteString(sb, "voice_speex"); //codec id
		g_RehldsFuncs->MSG_WriteByte(sb, 5); //quality
		break;

	default:
		LCPrintf(true, "SV_WriteVoiceCodec() called on client(%d) with unknown voice codec\n", cl->GetId());
		break;
	}
}
Esempio n. 12
0
int SV_CheckKeyInfo_hook(IRehldsHook_SV_CheckKeyInfo* chain, netadr_t *adr, char *protinfo, short unsigned int *port, int *pAuthProtocol, char *pszRaw, char *cdkey) {
	if (g_CurrentAuthContext == NULL) {
		LCPrintf(true, "WARNING: %s is called outside auth context\n",__FUNCTION__);
		return chain->callNext(adr, protinfo, port, pAuthProtocol, pszRaw, cdkey);
	}
	
	int authProto = atoi(g_engfuncs.pfnInfoKeyValue(protinfo, "prot"));
	if (authProto <= 0 || authProto > 4) {
		g_RehldsFuncs->RejectConnection(adr, "Invalid connection.\n");
		return 0;
	}

	strncpy(pszRaw, g_engfuncs.pfnInfoKeyValue(protinfo, "raw"), 32);
	pszRaw[33] = 0;

	strncpy(cdkey, g_engfuncs.pfnInfoKeyValue(protinfo, "cdkey"), 32);
	cdkey[33] = 0;

	*pAuthProtocol = authProto;
	*port = 27005;
	g_CurrentAuthContext->pAuthProto = pAuthProtocol;

	return 1;
}
Esempio n. 13
0
bool Renosteam_FinishClientAuth(IGameClient* cl)
{
	if (g_CurrentAuthContext == NULL) {
		LCPrintf(true, "WARNING: %s is called without active auth context\n", __FUNCTION__);
		return false;
	}

	// nosteam = bot
	if (g_CurrentAuthContext->nativeAuthFailed) {
		g_RehldsFuncs->SteamNotifyBotConnect(cl);
	}

	CRHNSPlayer* plr = GetPlayerByClientPtr(cl);

	if (g_CurrentAuthContext->hltv) {
		plr->authenticated(CA_HLTV);
	} else if (g_CurrentAuthContext->nativeAuthFailed) {
		plr->authenticated(CA_NOSTEAM);
	} else {
		plr->authenticated(CA_STEAM);
	}

	return true;
}
Esempio n. 14
0
bool parseMainConfig(const char* path, const char* file)
{
	FILE* fp = fopen(path, "rt");

	if (!fp)
		return false;

	char buf[8192];
	size_t line_number = 0;
	section_e section = st_unknown;
	CFields fields;

	while (fgets(buf, sizeof buf, fp)) {
		char* line = trimbuf(buf);
		line_number++;

		if (line[0] == '\xEF' && line[1] == '\xBB' && line[2] == '\xBF') // BOM
			line += 3;

		if (!line[0] || line[0] == '#')
			continue;

		if (line[0] == '[') {
			line++;

			if (nullLast(line, ']'))
				section = getSection(line);

			if (section != st_unknown && section < arraysize(section_default_format)) {
				char temp[256];
				strcpy(temp, section_default_format[section]);
				fields.parseFormat(temp);
			}

			continue;
		}

		if (section == st_unknown)
			continue;

		if (!parseLineToFields(line, fields, file, line_number))
			continue;

		if (!fields.getCount())
			continue;

		translation_t translations[16];
		size_t translations_count = fields.getTranslations(translations, arraysize(translations));

		switch (section) {
			case st_main:
			{
				auto param = fields.getField(dt_param);
				auto value = fields.getField(dt_value);

				if (!param || !value || !parseParam(param->string, value->string))
					LCPrintf("Invalid or unknown parameter at line %i in %s\n", line_number, file);
				break;
			}

			case st_hud:
			{
				if (!translations_count) {
					LCPrintf("Invalid hud mode name at line %i in %s\n", line_number, file);
					break;
				}

				auto x = fields.getField(dt_xcoord);
				auto y = fields.getField(dt_ycoord);
				auto r = fields.getField(dt_red);
				auto g = fields.getField(dt_green);
				auto b = fields.getField(dt_blue);

				if (x && y && r && g && b)
					addHudparms(translations, translations_count, x->float_number, y->float_number, r->int_number, g->int_number, b->int_number);
				else
					LCPrintf("Invalid hud parameters at line %i in %s\n", line_number, file);
				break;
			}

			case st_lang:
			{
				if (!translations_count) {
					LCPrintf("Invalid phrase without translations at line %i in %s\n", line_number, file);
					break;
				}

				auto phrase = fields.getField(dt_phrase);
				if(!phrase) {
					LCPrintf("Invalid phrase at line %i in %s\n", line_number, file);
					break;
				}

				g_lang.addPhrase(phrase->string, translations, translations_count);
				break;
			}

			case st_radio:
			{
				if (!translations_count) {
					LCPrintf("Invalid radio without translations at line %i in %s\n", line_number, file);
					break;
				}

				auto menuid = fields.getField(dt_menuid);
				if (!menuid) {
					LCPrintf("Invalid radio menu number at line %i in %s\n", line_number, file);
					break;
				}

				auto radio = fields.getField(dt_radio);
				if (!radio) {
					LCPrintf("Unknown radio command at line %i in %s\n", line_number, file);
					break;
				}

				translation_t phrase_translations[5][16];
				memset(phrase_translations, 0, sizeof phrase_translations);
				bool mult = false;

				for (size_t i = 0; i < translations_count; i++) {
					auto lang = translations[i].lang;
					char* argv[6];

					size_t phrases_count = parse((char *)translations[i].text, argv, arraysize(argv), ";\t", false);

					if (phrases_count != 3 && phrases_count != 5) {
						LCPrintf("Invalid radio phrases count at line %i in %s\n", line_number, file);
						continue;
					}

					if (phrases_count == 5) {
						mult = true;
					}

					for (size_t j = 0; j < phrases_count; j++) {
						phrase_translations[j][i].lang = lang;
						phrase_translations[j][i].text = argv[j];
					}
				}

				g_game.addRadio(menuid->int_number, radio->string, phrase_translations, translations_count, mult);
				break;
			}

			default:
				break;
		}
	}

	return true;
}
Esempio n. 15
0
bool parseLineToFields(char* line, CFields& fields, const char* file, size_t line_number)
{
	// format
	if (line[0] == '{') {
		line++;

		if (!nullLast(line, '}') || !fields.parseFormat(line)) {
			LCPrintf("Invalid format string at line %i in %s\n", line_number, file);
			return false;
		}

		return false; // no data
	}

	char* argv[32];
	size_t argc = parse(line, argv, arraysize(argv));

	if (!argc || argc != fields.getCount()) {
		LCPrintf("Invalid fields count at line %i in %s\n", line_number, file);
		return false;
	}

	// data
	for (size_t i = 0; i < fields.getCount(); i++) {
		auto field = fields.getField(i);

		switch (field->type) {
		case dt_origin:
		case dt_mins:
		case dt_maxs:
		case dt_lcorner:
		case dt_hcorner:
			if (!parseVector(argv[i], field->vec)) {
				LCPrintf("Invalid vector data in field %i at line %i in %s\n", i, line_number, file);
				return false;
			}
			break;

		case dt_param:
		case dt_value:
		case dt_radio:
		case dt_phrase:
		case dt_translation:
			strncpy(field->string, argv[i], sizeof field->string - 1);
			field->string[sizeof field->string - 1] = '\0';
			break;

		case dt_menuid:
		case dt_red:
		case dt_green:
		case dt_blue:
			field->int_number = strtol(argv[i], nullptr, 10);
			break;

		case dt_xcoord:
		case dt_ycoord:
			field->float_number = strtod(argv[i], nullptr);
			break;

		default:
		LCPrintf("Invalid field type %i (pos %i) at line %i in %s\n", field->type, i, line_number, file);
			return false;
		}
	}

	return true;
}