Example #1
0
intptr_t CL_UISystemCalls( intptr_t *args ) {
	switch( args[0] ) {
	//rww - alright, DO NOT EVER add a GAME/CGAME/UI generic call without adding a trap to match, and
	//all of these traps must be shared and have cases in sv_game, cl_cgame, and cl_ui. They must also
	//all be in the same order, and start at 100.
	case TRAP_MEMSET:
		Com_Memset( VMA(1), args[2], args[3] );
		return 0;
	case TRAP_MEMCPY:
		Com_Memcpy( VMA(1), VMA(2), args[3] );
		return 0;
	case TRAP_STRNCPY:
		return (int)strncpy( (char *)VMA(1), (const char *)VMA(2), args[3] );
	case TRAP_SIN:
		return FloatAsInt( sin( VMF(1) ) );
	case TRAP_COS:
		return FloatAsInt( cos( VMF(1) ) );
	case TRAP_ATAN2:
		return FloatAsInt( atan2( VMF(1), VMF(2) ) );
	case TRAP_SQRT:
		return FloatAsInt( sqrt( VMF(1) ) );
	case TRAP_MATRIXMULTIPLY:
		MatrixMultiply( (vec3_t *)VMA(1), (vec3_t *)VMA(2), (vec3_t *)VMA(3) );
		return 0;
	case TRAP_ANGLEVECTORS:
		AngleVectors( (const float *)VMA(1), (float *)VMA(2), (float *)VMA(3), (float *)VMA(4) );
		return 0;
	case TRAP_PERPENDICULARVECTOR:
		PerpendicularVector( (float *)VMA(1), (const float *)VMA(2) );
		return 0;


	case UI_ERROR:
		Com_Error( ERR_DROP, "%s", VMA(1) );
		return 0;

	case UI_PRINT:
		Com_Printf( "%s", VMA(1) );
		return 0;

	case UI_MILLISECONDS:
		return Sys_Milliseconds();

	case UI_CVAR_REGISTER:
		Cvar_Register( (vmCvar_t *)VMA(1), (const char *)VMA(2), (const char *)VMA(3), args[4] ); 
		return 0;

	case UI_CVAR_UPDATE:
		Cvar_Update( (vmCvar_t *)VMA(1) );
		return 0;

	case UI_CVAR_SET:
		Cvar_Set( (const char *)VMA(1), (const char *)VMA(2) );
		return 0;

	case UI_CVAR_VARIABLEVALUE:
		return FloatAsInt( Cvar_VariableValue( (const char *)VMA(1) ) );

	case UI_CVAR_VARIABLESTRINGBUFFER:
		Cvar_VariableStringBuffer( (const char *)VMA(1), (char *)VMA(2), args[3] );
		return 0;

	case UI_CVAR_SETVALUE:
		Cvar_SetValue( (const char *)VMA(1), VMF(2) );
		return 0;

	case UI_CVAR_RESET:
		Cvar_Reset( (const char *)VMA(1) );
		return 0;

	case UI_CVAR_CREATE:
		Cvar_Get( (const char *)VMA(1), (const char *)VMA(2), args[3] );
		return 0;

	case UI_CVAR_INFOSTRINGBUFFER:
		Cvar_InfoStringBuffer( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_ARGC:
		return Cmd_Argc();

	case UI_ARGV:
		Cmd_ArgvBuffer( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_CMD_EXECUTETEXT:
		Cbuf_ExecuteText( args[1], (const char *)VMA(2) );
		return 0;

	case UI_FS_FOPENFILE:
		return FS_FOpenFileByMode( (const char *)VMA(1), (int *)VMA(2), (fsMode_t)args[3] );

	case UI_FS_READ:
		FS_Read2( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_WRITE:
		FS_Write( VMA(1), args[2], args[3] );
		return 0;

	case UI_FS_FCLOSEFILE:
		FS_FCloseFile( args[1] );
		return 0;

	case UI_FS_GETFILELIST:
		return FS_GetFileList( (const char *)VMA(1), (const char *)VMA(2), (char *)VMA(3), args[4] );

	case UI_R_REGISTERMODEL:
		return re.RegisterModel( (const char *)VMA(1) );

	case UI_R_REGISTERSKIN:
		return re.RegisterSkin( (const char *)VMA(1) );

	case UI_R_REGISTERSHADERNOMIP:
		return re.RegisterShaderNoMip( (const char *)VMA(1) );

	case UI_R_SHADERNAMEFROMINDEX:
		{
			char *gameMem = (char *)VMA(1);
			const char *retMem = re.ShaderNameFromIndex(args[2]);
			if (retMem)
			{
				strcpy(gameMem, retMem);
			}
			else
			{
				gameMem[0] = 0;
			}
		}
		return 0;

	case UI_R_CLEARSCENE:
		re.ClearScene();
		return 0;

	case UI_R_ADDREFENTITYTOSCENE:
		re.AddRefEntityToScene( (const refEntity_t *)VMA(1) );
		return 0;

	case UI_R_ADDPOLYTOSCENE:
		re.AddPolyToScene( args[1], args[2], (const polyVert_t *)VMA(3), 1 );
		return 0;

	case UI_R_ADDLIGHTTOSCENE:
#ifdef VV_LIGHTING
		VVLightMan.RE_AddLightToScene( (const float *)VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
#else
		re.AddLightToScene( (const float *)VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
#endif
		return 0;

	case UI_R_RENDERSCENE:
		re.RenderScene( (const refdef_t *)VMA(1) );
		return 0;

	case UI_R_SETCOLOR:
		re.SetColor( (const float *)VMA(1) );
		return 0;

	case UI_R_DRAWSTRETCHPIC:
		re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] );
		return 0;

  case UI_R_MODELBOUNDS:
		re.ModelBounds( args[1], (float *)VMA(2), (float *)VMA(3) );
		return 0;

	case UI_UPDATESCREEN:
		SCR_UpdateScreen();
		return 0;

	case UI_CM_LERPTAG:
		re.LerpTag( (orientation_t *)VMA(1), args[2], args[3], args[4], VMF(5), (const char *)VMA(6) );
		return 0;

	case UI_S_REGISTERSOUND:
		return S_RegisterSound( (const char *)VMA(1) );

	case UI_S_STARTLOCALSOUND:
		S_StartLocalSound( args[1], args[2] );
		return 0;

	case UI_KEY_KEYNUMTOSTRINGBUF:
		Key_KeynumToStringBuf( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_KEY_GETBINDINGBUF:
		Key_GetBindingBuf( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_KEY_SETBINDING:
		Key_SetBinding( args[1], (const char *)VMA(2) );
		return 0;

	case UI_KEY_ISDOWN:
		return Key_IsDown( args[1] );

	case UI_KEY_GETOVERSTRIKEMODE:
		return Key_GetOverstrikeMode();

	case UI_KEY_SETOVERSTRIKEMODE:
		Key_SetOverstrikeMode( (qboolean)args[1] );
		return 0;

	case UI_KEY_CLEARSTATES:
		Key_ClearStates();
		return 0;

	case UI_KEY_GETCATCHER:
		return Key_GetCatcher();

	case UI_KEY_SETCATCHER:
		// Don't allow the ui module to close the console
		Key_SetCatcher( args[1] | ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) );
		return 0;

	case UI_GETCLIPBOARDDATA:
		GetClipboardData( (char *)VMA(1), args[2] );
		return 0;

	case UI_GETCLIENTSTATE:
		GetClientState( (uiClientState_t *)VMA(1) );
		return 0;		

	case UI_GETGLCONFIG:
		CL_GetGlconfig( (glconfig_t *)VMA(1) );
		return 0;

	case UI_GETCONFIGSTRING:
		return GetConfigString( args[1], (char *)VMA(2), args[3] );

	case UI_LAN_LOADCACHEDSERVERS:
		LAN_LoadCachedServers();
		return 0;

	case UI_LAN_SAVECACHEDSERVERS:
		LAN_SaveServersToCache();
		return 0;

	case UI_LAN_ADDSERVER:
		return LAN_AddServer(args[1], (const char *)VMA(2), (const char *)VMA(3));

	case UI_LAN_REMOVESERVER:
		LAN_RemoveServer(args[1], (const char *)VMA(2));
		return 0;

	case UI_LAN_GETPINGQUEUECOUNT:
		return LAN_GetPingQueueCount();

	case UI_LAN_CLEARPING:
		LAN_ClearPing( args[1] );
		return 0;

	case UI_LAN_GETPING:
		LAN_GetPing( args[1], (char *)VMA(2), args[3], (int *)VMA(4) );
		return 0;

	case UI_LAN_GETPINGINFO:
		LAN_GetPingInfo( args[1], (char *)VMA(2), args[3] );
		return 0;

	case UI_LAN_GETSERVERCOUNT:
		return LAN_GetServerCount(args[1]);

	case UI_LAN_GETSERVERADDRESSSTRING:
		LAN_GetServerAddressString( args[1], args[2], (char *)VMA(3), args[4] );
		return 0;

	case UI_LAN_GETSERVERINFO:
		LAN_GetServerInfo( args[1], args[2], (char *)VMA(3), args[4] );
		return 0;

	case UI_LAN_GETSERVERPING:
		return LAN_GetServerPing( args[1], args[2] );

	case UI_LAN_MARKSERVERVISIBLE:
		LAN_MarkServerVisible( args[1], args[2], (qboolean)args[3] );
		return 0;

	case UI_LAN_SERVERISVISIBLE:
		return LAN_ServerIsVisible( args[1], args[2] );

	case UI_LAN_UPDATEVISIBLEPINGS:
		return LAN_UpdateVisiblePings( args[1] );

	case UI_LAN_RESETPINGS:
		LAN_ResetPings( args[1] );
		return 0;

	case UI_LAN_SERVERSTATUS:
		return LAN_GetServerStatus( (char *)VMA(1), (char *)VMA(2), args[3] );

	case UI_LAN_COMPARESERVERS:
		return LAN_CompareServers( args[1], args[2], args[3], args[4], args[5] );

	case UI_MEMORY_REMAINING:
		return Hunk_MemoryRemaining();

	case UI_R_REGISTERFONT:
		return re.RegisterFont( (const char *)VMA(1) );

	case UI_R_FONT_STRLENPIXELS:
		return re.Font_StrLenPixels( (const char *)VMA(1), args[2], VMF(3) );

	case UI_R_FONT_STRLENCHARS:
		return re.Font_StrLenChars( (const char *)VMA(1) );

	case UI_R_FONT_STRHEIGHTPIXELS:
		return re.Font_HeightPixels( args[1], VMF(2) );

	case UI_R_FONT_DRAWSTRING:
		re.Font_DrawString( args[1], args[2], (const char *)VMA(3), (const float *) VMA(4), args[5], args[6], VMF(7) );
		return 0;

	case UI_LANGUAGE_ISASIAN:
		return re.Language_IsAsian();

	case UI_LANGUAGE_USESSPACES:
		return re.Language_UsesSpaces();

	case UI_ANYLANGUAGE_READCHARFROMSTRING:
		return re.AnyLanguage_ReadCharFromString( (const char *)VMA(1), (int *) VMA(2), (qboolean *) VMA(3) );

	case UI_PC_ADD_GLOBAL_DEFINE:
		return botlib_export->PC_AddGlobalDefine( (char *)VMA(1) );
	case UI_PC_LOAD_SOURCE:
		return botlib_export->PC_LoadSourceHandle( (const char *)VMA(1) );
	case UI_PC_FREE_SOURCE:
		return botlib_export->PC_FreeSourceHandle( args[1] );
	case UI_PC_READ_TOKEN:
		return botlib_export->PC_ReadTokenHandle( args[1], (struct pc_token_s *)VMA(2) );
	case UI_PC_SOURCE_FILE_AND_LINE:
		return botlib_export->PC_SourceFileAndLine( args[1], (char *)VMA(2), (int *)VMA(3) );
	case UI_PC_LOAD_GLOBAL_DEFINES:
		return botlib_export->PC_LoadGlobalDefines ( (char *)VMA(1) );
	case UI_PC_REMOVE_ALL_GLOBAL_DEFINES:
		botlib_export->PC_RemoveAllGlobalDefines ( );
		return 0;

	case UI_S_STOPBACKGROUNDTRACK:
		S_StopBackgroundTrack();
		return 0;
	case UI_S_STARTBACKGROUNDTRACK:
		S_StartBackgroundTrack( (const char *)VMA(1), (const char *)VMA(2), qfalse);
		return 0;

	case UI_REAL_TIME:
		return Com_RealTime( (struct qtime_s *)VMA(1) );

	case UI_CIN_PLAYCINEMATIC:
	  Com_DPrintf("UI_CIN_PlayCinematic\n");
	  return CIN_PlayCinematic((const char *)VMA(1), args[2], args[3], args[4], args[5], args[6]);

	case UI_CIN_STOPCINEMATIC:
	  return CIN_StopCinematic(args[1]);

	case UI_CIN_RUNCINEMATIC:
	  return CIN_RunCinematic(args[1]);

	case UI_CIN_DRAWCINEMATIC:
	  CIN_DrawCinematic(args[1]);
	  return 0;

	case UI_CIN_SETEXTENTS:
	  CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]);
	  return 0;

	case UI_R_REMAP_SHADER:
		re.RemapShader( (const char *)VMA(1), (const char *)VMA(2), (const char *)VMA(3) );
		return 0;

	case UI_SP_GETNUMLANGUAGES:
		return SE_GetNumLanguages();

	case UI_SP_GETLANGUAGENAME:
		char *languageName,*holdName;

		holdName = ((char *)VMA(2));
		languageName = (char *) SE_GetLanguageName((const int)VMA(1));
		Q_strncpyz( holdName, languageName,128 );
		return 0;

	case UI_SP_GETSTRINGTEXTSTRING:
		const char* text;

		assert(VMA(1));
		assert(VMA(2));
		text = SE_GetString((const char *) VMA(1));
		Q_strncpyz( (char *) VMA(2), text, args[3] );
		return qtrue;

/*
Ghoul2 Insert Start
*/
/*
Ghoul2 Insert Start
*/
		
	case UI_G2_LISTSURFACES:
		re.G2API_ListSurfaces( (CGhoul2Info *) args[1] );
		return 0;

	case UI_G2_LISTBONES:
		re.G2API_ListBones( (CGhoul2Info *) args[1], args[2]);
		return 0;

	case UI_G2_HAVEWEGHOULMODELS:
		return re.G2API_HaveWeGhoul2Models( *((CGhoul2Info_v *)args[1]) );

	case UI_G2_SETMODELS:
		re.G2API_SetGhoul2ModelIndexes( *((CGhoul2Info_v *)args[1]),(qhandle_t *)VMA(2),(qhandle_t *)VMA(3));
		return 0;

	case UI_G2_GETBOLT:
		return re.G2API_GetBoltMatrix(*((CGhoul2Info_v *)args[1]), args[2], args[3], (mdxaBone_t *)VMA(4), (const float *)VMA(5),(const float *)VMA(6), args[7], (qhandle_t *)VMA(8), (float *)VMA(9));

	case UI_G2_GETBOLT_NOREC:
		re.G2API_BoltMatrixReconstruction( qfalse );//gG2_GBMNoReconstruct = qtrue;
		return re.G2API_GetBoltMatrix(*((CGhoul2Info_v *)args[1]), args[2], args[3], (mdxaBone_t *)VMA(4), (const float *)VMA(5),(const float *)VMA(6), args[7], (qhandle_t *)VMA(8), (float *)VMA(9));

	case UI_G2_GETBOLT_NOREC_NOROT:
		//RAZFIXME: cgame reconstructs bolt matrix, why is this different?
		re.G2API_BoltMatrixReconstruction( qfalse );//gG2_GBMNoReconstruct = qtrue;
		re.G2API_BoltMatrixSPMethod( qtrue );//gG2_GBMUseSPMethod = qtrue;
		return re.G2API_GetBoltMatrix(*((CGhoul2Info_v *)args[1]), args[2], args[3], (mdxaBone_t *)VMA(4), (const float *)VMA(5),(const float *)VMA(6), args[7], (qhandle_t *)VMA(8), (float *)VMA(9));

	case UI_G2_INITGHOUL2MODEL:
#ifdef _FULL_G2_LEAK_CHECKING
		g_G2AllocServer = 0;
#endif
		return	re.G2API_InitGhoul2Model((CGhoul2Info_v **)VMA(1), (const char *)VMA(2), args[3], (qhandle_t) args[4],
									  (qhandle_t) args[5], args[6], args[7]);


	case UI_G2_COLLISIONDETECT:
	case UI_G2_COLLISIONDETECTCACHE:
		return 0; //not supported for ui

	case UI_G2_ANGLEOVERRIDE:
		return re.G2API_SetBoneAngles(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3), (float *)VMA(4), args[5],
							 (const Eorientations) args[6], (const Eorientations) args[7], (const Eorientations) args[8],
							 (qhandle_t *)VMA(9), args[10], args[11] );
	
	case UI_G2_CLEANMODELS:
#ifdef _FULL_G2_LEAK_CHECKING
		g_G2AllocServer = 0;
#endif
		re.G2API_CleanGhoul2Models((CGhoul2Info_v **)VMA(1));
	//	re.G2API_CleanGhoul2Models((CGhoul2Info_v **)args[1]);
		return 0;

	case UI_G2_PLAYANIM:
		return re.G2API_SetBoneAnim(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3), args[4], args[5],
								args[6], VMF(7), args[8], VMF(9), args[10]);

	case UI_G2_GETBONEANIM:
		{
			CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]);
			int modelIndex = args[10];

			return re.G2API_GetBoneAnim(&g2[modelIndex], (const char*)VMA(2), args[3], (float *)VMA(4), (int *)VMA(5),
								(int *)VMA(6), (int *)VMA(7), (float *)VMA(8), (int *)VMA(9));
		}

	case UI_G2_GETBONEFRAME:
		{ //rwwFIXMEFIXME: Just make a G2API_GetBoneFrame func too. This is dirty.
			CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]);
			int modelIndex = args[6];
			int iDontCare1 = 0, iDontCare2 = 0, iDontCare3 = 0;
			float fDontCare1 = 0;

			return re.G2API_GetBoneAnim(&g2[modelIndex], (const char*)VMA(2), args[3], (float *)VMA(4), &iDontCare1,
								&iDontCare2, &iDontCare3, &fDontCare1, (int *)VMA(5));
		}

	case UI_G2_GETGLANAME:
		//	return (int)G2API_GetGLAName(*((CGhoul2Info_v *)VMA(1)), args[2]);
		{
			char *point = ((char *)VMA(3));
			char *local;
			local = re.G2API_GetGLAName(*((CGhoul2Info_v *)args[1]), args[2]);
			if (local)
			{
				strcpy(point, local);
			}
		}
		return 0;

	case UI_G2_COPYGHOUL2INSTANCE:
		return (int)re.G2API_CopyGhoul2Instance(*((CGhoul2Info_v *)args[1]), *((CGhoul2Info_v *)args[2]), args[3]);

	case UI_G2_COPYSPECIFICGHOUL2MODEL:
		re.G2API_CopySpecificG2Model(*((CGhoul2Info_v *)args[1]), args[2], *((CGhoul2Info_v *)args[3]), args[4]);
		return 0;

	case UI_G2_DUPLICATEGHOUL2INSTANCE:
#ifdef _FULL_G2_LEAK_CHECKING
		g_G2AllocServer = 0;
#endif
		re.G2API_DuplicateGhoul2Instance(*((CGhoul2Info_v *)args[1]), (CGhoul2Info_v **)VMA(2));
		return 0;

	case UI_G2_HASGHOUL2MODELONINDEX:
		return (int)re.G2API_HasGhoul2ModelOnIndex((CGhoul2Info_v **)VMA(1), args[2]);
		//return (int)G2API_HasGhoul2ModelOnIndex((CGhoul2Info_v **)args[1], args[2]);

	case UI_G2_REMOVEGHOUL2MODEL:
#ifdef _FULL_G2_LEAK_CHECKING
		g_G2AllocServer = 0;
#endif
		return (int)re.G2API_RemoveGhoul2Model((CGhoul2Info_v **)VMA(1), args[2]);
		//return (int)G2API_RemoveGhoul2Model((CGhoul2Info_v **)args[1], args[2]);

	case UI_G2_ADDBOLT:
		return re.G2API_AddBolt(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3));

//	case UI_G2_REMOVEBOLT:
//		return G2API_RemoveBolt(*((CGhoul2Info_v *)VMA(1)), args[2]);

	case UI_G2_SETBOLTON:
		re.G2API_SetBoltInfo(*((CGhoul2Info_v *)args[1]), args[2], args[3]);
		return 0;

#ifdef _SOF2	
	case UI_G2_ADDSKINGORE:
		re.G2API_AddSkinGore(*((CGhoul2Info_v *)args[1]),*(SSkinGoreData *)VMA(2));
		return 0;
#endif // _SOF2
/*
Ghoul2 Insert End
*/
	case UI_G2_SETROOTSURFACE:
		return re.G2API_SetRootSurface(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3));

	case UI_G2_SETSURFACEONOFF:
		return re.G2API_SetSurfaceOnOff(*((CGhoul2Info_v *)args[1]), (const char *)VMA(2), /*(const int)VMA(3)*/args[3]);

	case UI_G2_SETNEWORIGIN:
		return re.G2API_SetNewOrigin(*((CGhoul2Info_v *)args[1]), /*(const int)VMA(2)*/args[2]);

	case UI_G2_GETTIME:
		return re.G2API_GetTime(0);

	case UI_G2_SETTIME:
		re.G2API_SetTime(args[1], args[2]);
		return 0;

	case UI_G2_SETRAGDOLL:
		return 0; //not supported for ui
		break;
	case UI_G2_ANIMATEG2MODELS:
		return 0; //not supported for ui
		break;

	case UI_G2_SETBONEIKSTATE:
		return re.G2API_SetBoneIKState(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3), args[4], (sharedSetBoneIKStateParams_t *)VMA(5));
	case UI_G2_IKMOVE:
		return re.G2API_IKMove(*((CGhoul2Info_v *)args[1]), args[2], (sharedIKMoveParams_t *)VMA(3));

	case UI_G2_GETSURFACENAME:
		{ //Since returning a pointer in such a way to a VM seems to cause MASSIVE FAILURE<tm>, we will shove data into the pointer the vm passes instead
			char *point = ((char *)VMA(4));
			char *local;
			int modelindex = args[3];

			CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]);

			local = re.G2API_GetSurfaceName(&g2[modelindex], args[2]);
			if (local)
			{
				strcpy(point, local);
			}
		}

		return 0;
	case UI_G2_SETSKIN:
		{
			CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]);
			int modelIndex = args[2];
			
			return re.G2API_SetSkin(&g2[modelIndex], args[3], args[4]);
		}

	case UI_G2_ATTACHG2MODEL:
		{
			CGhoul2Info_v *g2From = ((CGhoul2Info_v *)args[1]);
			CGhoul2Info_v *g2To = ((CGhoul2Info_v *)args[3]);
			
			return re.G2API_AttachG2Model(*g2From, args[2], *g2To, args[4], args[5]);
		}

	// Jedi Knight Galaxies

	case UI_JKG_CHANGEPROTOCOL:
		return 0;

	case UI_SYSCALL_CG:
		currentVM = cgvm;
		return 0;

	case UI_SYSCALL_UI:
		currentVM = uivm;
		return 0;
/*
Ghoul2 Insert End
*/
	default:
		Com_Error( ERR_DROP, "Bad UI system trap: %ld", (long int) args[0] );

	}

	return 0;
}
int ASTAR_FindPathFast(int from, int to, int *pathlist, qboolean shorten)
{
	//all the data we have to hold...since we can't do dynamic allocation, has to be MAX_WPARRAY_SIZE
	//we can probably lower this later - eg, the open list should never have more than at most a few dozen items on it
	int			badwp = -1;
	int			numOpen = 0;
	int			atNode, temp, newnode = -1;
	qboolean	found = qfalse;
	int			count = -1;
	float		gc;
	int			i, j, u, v, m;
	gentity_t	*bot = NULL;

	if (!PATHING_IGNORE_FRAME_TIME && trap_Milliseconds() - FRAME_TIME > 300)
	{// Never path on an already long frame time...
		return -1;
	}

	if ( (from == NODE_INVALID) || (to == NODE_INVALID) || (from >= gWPNum) || (to >= gWPNum) || (from == to) )
	{
		//G_Printf("Bad from or to node.\n");
		return ( -1 );
	}

	// Check if memory needs to be allocated...
	AllocatePathFindingMemory();

	memset( openlist, 0, (sizeof(int) * (gWPNum + 1)) );
	memset( gcost, 0, (sizeof(float) * gWPNum) );
	memset( fcost, 0, (sizeof(int) * gWPNum) );
	memset( list, 0, (sizeof(char) * gWPNum) );
	memset( parent, 0, (sizeof(int) * gWPNum) );

	for (i = 0; i < gWPNum; i++)
	{
		gcost[i] = Distance(gWPArray[i]->origin, gWPArray[to]->origin); 
	}

	openlist[gWPNum+1] = 0;

	openlist[1] = from;																	//add the starting node to the open list
	numOpen++;
	gcost[from] = 0;																	//its f and g costs are obviously 0
	fcost[from] = 0;

	while ( 1 )
	{
		if ( numOpen != 0 )																//if there are still items in the open list
		{
			//pop the top item off of the list
			atNode = openlist[1];
			list[atNode] = 2;															//put the node on the closed list so we don't check it again
			numOpen--;
			openlist[1] = openlist[numOpen + 1];										//move the last item in the list to the top position
			v = 1;

			//this while loop reorders the list so that the new lowest fcost is at the top again
			while ( 1 )
			{
				u = v;
				if ( (2 * u + 1) < numOpen )											//if both children exist
				{
					if ( fcost[openlist[u]] >= fcost[openlist[2 * u]] )
					{
						v = 2 * u;
					}

					if ( fcost[openlist[v]] >= fcost[openlist[2 * u + 1]] )
					{
						v = 2 * u + 1;
					}
				}
				else
				{
					if ( (2 * u) < numOpen )											//if only one child exists
					{
						if ( fcost[openlist[u]] >= fcost[openlist[2 * u]] )
						{
							v = 2 * u;
						}
					}
				}

				if ( u != v )															//if they're out of order, swap this item with its parent
				{
					temp = openlist[u];
					openlist[u] = openlist[v];
					openlist[v] = temp;
				}
				else
				{
					break;
				}
			}

			for ( i = 0; i < gWPArray[atNode]->neighbornum && i < MAX_NODELINKS; i++ )								//loop through all the links for this node
			{
				newnode = gWPArray[atNode]->neighbors[i].num;

				if (newnode > gWPNum)
					continue;

				if (newnode < 0)
					continue;

				//if (nodes[newnode].objectNum[0] == 1)
				//	continue; // Skip water/ice disabled node!

				if ( list[newnode] == 2 )
				{																		//if this node is on the closed list, skip it
					continue;
				}

				if ( list[newnode] != 1 )												//if this node is not already on the open list
				{
					openlist[++numOpen] = newnode;										//add the new node to the open list
					list[newnode] = 1;
					parent[newnode] = atNode;											//record the node's parent

					if ( newnode == to )
					{																	//if we've found the goal, don't keep computing paths!
						break;															//this will break the 'for' and go all the way to 'if (list[to] == 1)'
					}

					fcost[newnode] = BOT_GetFCost( bot, to, newnode, parent[newnode], gcost );	//store it's f cost value

					//this loop re-orders the heap so that the lowest fcost is at the top
					m = numOpen;

					while ( m != 1 )													//while this item isn't at the top of the heap already
					{
						if ( fcost[openlist[m]] <= fcost[openlist[m / 2]] )				//if it has a lower fcost than its parent
						{
							temp = openlist[m / 2];
							openlist[m / 2] = openlist[m];
							openlist[m] = temp;											//swap them
							m /= 2;
						}
						else
						{
							break;
						}
					}
				}
				else										//if this node is already on the open list
				{
					gc = gcost[atNode];

					if (gWPArray[atNode]->neighbors[i].cost > 0 && gWPArray[atNode]->neighbors[i].cost < 9999)
					{// UQ1: Already have a cost value, skip the calculations!
						gc += gWPArray[atNode]->neighbors[i].cost;
					}
					else
					{
						vec3_t	vec;

						VectorSubtract( gWPArray[newnode]->origin, gWPArray[atNode]->origin, vec );
						gc += VectorLength( vec );				//calculate what the gcost would be if we reached this node along the current path
						gWPArray[atNode]->neighbors[i].cost = VectorLength( vec );

						/*
						float height_diff = 0.0f;
						float cost = 0.0f;

						cost = Distance(gWPArray[newnode]->origin, gWPArray[atNode]->origin);

						height_diff = HeightDistance(gWPArray[newnode]->origin, gWPArray[atNode]->origin);
						cost += (height_diff * height_diff); // Squared for massive preferance to staying at same plane...

						gWPArray[atNode]->neighbors[i].cost = cost;

						gc += cost;
						*/
					}

					if ( gc < gcost[newnode] )				//if the new gcost is less (ie, this path is shorter than what we had before)
					{
						parent[newnode] = atNode;			//set the new parent for this node
						gcost[newnode] = gc;				//and the new g cost

						for ( j = 1; j < numOpen; j++ )		//loop through all the items on the open list
						{
							if ( openlist[j] == newnode )	//find this node in the list
							{
								//calculate the new fcost and store it
								fcost[newnode] = BOT_GetFCost( bot, to, newnode, parent[newnode], gcost );

								//reorder the list again, with the lowest fcost item on top
								m = j;

								while ( m != 1 )
								{
									if ( fcost[openlist[m]] < fcost[openlist[m / 2]] )	//if the item has a lower fcost than it's parent
									{
										temp = openlist[m / 2];
										openlist[m / 2] = openlist[m];
										openlist[m] = temp;								//swap them
										m /= 2;
									}
									else
									{
										break;
									}
								}
								break;													//exit the 'for' loop because we already changed this node
							}															//if
						}																//for
					}											//if (gc < gcost[newnode])
				}												//if (list[newnode] != 1) --> else
			}													//for (loop through links)
		}														//if (numOpen != 0)
		else
		{
			found = qfalse;										//there is no path between these nodes
			break;
		}

		if ( list[to] == 1 )									//if the destination node is on the open list, we're done
		{
			found = qtrue;
			break;
		}
	}															//while (1)

	if ( found == qtrue )							//if we found a path, and are trying to store the pathlist...
	{
		count = 0;
		temp = to;												//start at the end point

		while ( temp != from )									//travel along the path (backwards) until we reach the starting point
		{
			if (count+1 >= MAX_WPARRAY_SIZE)
			{
				Com_Printf("ERROR: pathlist count > MAX_WPARRAY_SIZE.\n");
				return -1; // UQ1: Added to stop crash if path is too long for the memory allocation...
			}

			pathlist[count++] = temp;							//add the node to the pathlist and increment the count
			temp = parent[temp];								//move to the parent of this node to continue the path
		}

		pathlist[count++] = from;								//add the beginning node to the end of the pathlist

#ifdef __SLOW_PATHING__
		if (shorten)
		{// UQ1: Now use the path shortener on these waypoints...
			int pathlist_copy[MAX_WPARRAY_SIZE];
			memcpy(pathlist_copy, pathlist, sizeof(int)*(MAX_WPARRAY_SIZE));
			count = ASTAR_ShortenPath(count, pathlist_copy, pathlist);
		}
#endif //__SLOW_PATHING__

		//G_Printf("Pathsize is %i.\n", count);
		return ( count );
	}

	//G_Printf("Failed to find path.\n");
	return ( -1 );											//return the number of nodes in the path, -1 if not found
}
Example #3
0
bool Sys_GetPacket( netadr_t *net_from, msg_t *net_message ) {
	int 	ret;
	struct sockaddr from;
	int		fromlen;
	int		net_socket;
	int		protocol;
	int		err;

	for( protocol = 0 ; protocol < 2 ; protocol++ )	{
		if( protocol == 0 ) {
			net_socket = ip_socket;
		}
		else {
			net_socket = ipx_socket;
		}

		if( !net_socket ) {
			continue;
		}

		fromlen = sizeof(from);
		recvfromCount++;		// performance check
		ret = recvfrom( net_socket, reinterpret_cast<char*>(net_message->data), net_message->maxsize, 0, (struct sockaddr *)&from, &fromlen );
		if (ret == SOCKET_ERROR)
		{
			err = WSAGetLastError();

			if( err == WSAEWOULDBLOCK || err == WSAECONNRESET ) {
				continue;
			}
			Com_Printf( "NET_GetPacket: %s\n", NET_ErrorString() );
			continue;
		}

		if ( net_socket == ip_socket ) {
			memset( ((struct sockaddr_in *)&from)->sin_zero, 0, 8 );
		}

		if ( usingSocks && net_socket == ip_socket && memcmp( &from, &socksRelayAddr, fromlen ) == 0 ) {
			if ( ret < 10 || net_message->data[0] != 0 || net_message->data[1] != 0 || net_message->data[2] != 0 || net_message->data[3] != 1 ) {
				continue;
			}
			net_from->type = NA_IP;
			net_from->ip[0] = net_message->data[4];
			net_from->ip[1] = net_message->data[5];
			net_from->ip[2] = net_message->data[6];
			net_from->ip[3] = net_message->data[7];
			net_from->port = *(short *)&net_message->data[8];
			net_message->readcount = 10;
		}
		else {
			SockadrToNetadr( &from, net_from );
			net_message->readcount = 0;
		}

		if( ret == net_message->maxsize ) {
			Com_Printf( "Oversize packet from %s\n", NET_AdrToString (*net_from) );
			continue;
		}

		net_message->cursize = ret;
		return true;
	}

	return false;
}
Example #4
0
qboolean UI_RegisterClientModelname(playerInfo_t * pi, const char *modelSkinName)
{
	char            modelName[MAX_QPATH];
	char            skinName[MAX_QPATH];
	char            filename[MAX_QPATH];
	char           *slash;
	const char     *backpack = NULL;
	const char     *helmet = NULL;

	pi->torsoModel = 0;
	pi->headModel = 0;

	if(!modelSkinName[0])
	{
		return qfalse;
	}

	Q_strncpyz(modelName, modelSkinName, sizeof(modelName));

	slash = strchr(modelName, '/');
	if(!slash)
	{
		// modelName did not include a skin name
		Q_strncpyz(skinName, "default", sizeof(skinName));
	}
	else
	{
		Q_strncpyz(skinName, slash + 1, sizeof(skinName));
		// truncate modelName
		*slash = 0;
	}

	// NERVE - SMF - set weapon
	pi->weapon = trap_Cvar_VariableValue("mp_weapon");
	UI_PlayerInfo_SetWeapon(pi, pi->weapon);

	// NERVE - SMF - determine skin
	{
		const char     *team;
		const char     *playerClass;
		int             var, teamval;

		// DHM - Nerve :: Don't rely on cvar for team, use modelname instead
		//teamval = trap_Cvar_VariableValue( "mp_team" );
		if(!strcmp(modelSkinName, "multi"))
		{
			teamval = 1;
			team = "blue";
		}
		else
		{
			teamval = 0;
			team = "red";
		}

		var = trap_Cvar_VariableValue("mp_playerType");

		if(var == 0)
		{
			playerClass = "soldier";

			if(teamval == 1)
			{
				backpack = "acc/backpack/backpack_sol.md3";
				helmet = "acc/helmet_american/sol.md3";
			}
			else
			{
				backpack = "acc/backpack/backpack_german_sol.md3";
				helmet = "acc/helmet_german/helmet_sol.md3";
			}
		}
		else if(var == 1)
		{
			playerClass = "medic";

			if(teamval == 1)
			{
				backpack = "acc/backpack/backpack_med.md3";
				helmet = "acc/helmet_american/med.md3";
			}
			else
			{
				backpack = "acc/backpack/backpack_german_med.md3";
				helmet = "acc/helmet_german/helmet_med.md3";
			}
		}
		else if(var == 2)
		{
			playerClass = "engineer";

			if(teamval == 1)
			{
				backpack = "acc/backpack/backpack_eng.md3";
				helmet = "acc/helmet_american/eng.md3";
			}
			else
			{
				backpack = "acc/backpack/backpack_german_eng.md3";
				helmet = "acc/helmet_german/helmet_eng.md3";
			}
		}
		else if(var == 4)
		{
			playerClass = "covert ops";

			if(teamval == 1)
			{
				backpack = "acc/backpack/backpack_cvops.md3";
				helmet = "acc/helmet_american/cvops.md3";
			}
			else
			{
				backpack = "acc/backpack/backpack_german_cvops.md3";
				helmet = "acc/helmet_german/helmet_cvops.md3";
			}
		}
		else
		{
			playerClass = "lieutenant";

			if(teamval == 1)
			{
				backpack = "acc/backpack/backpack_lieu.md3";
				helmet = "acc/helmet_american/lieu.md3";
			}
			else
			{
				backpack = "acc/backpack/backpack_german_lieu.md3";
				helmet = "acc/helmet_german/helmet_leiu.md3";
			}
		}

		strcpy(skinName, va("%s%s1", team, playerClass));
	}
	// -NERVE - SMF

//      Q_strncpyz( skinName, "bluesoldier1", sizeof( skinName ) );     // NERVE - SMF - make this work with wolf - TESTING!!!
//  }
//  else {
//      Q_strncpyz( skinName, "redsoldier1", sizeof( skinName ) );      // NERVE - SMF - make this work with wolf - TESTING!!!
//  }

	// load cmodels before models so filecache works

//  Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower.md3", modelName );
	Com_sprintf(filename, sizeof(filename), "models/players/%s/body.mds", modelName);	// NERVE - SMF - make this work with wolf
	pi->legsModel = trap_R_RegisterModel(filename);
	if(!pi->legsModel)
	{
		Com_Printf("Failed to load model file %s\n", filename);
		return qfalse;
	}

//  Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper.md3", modelName );
	Com_sprintf(filename, sizeof(filename), "models/players/%s/body.mds", modelName);	// NERVE - SMF - make this work with wolf
	pi->torsoModel = trap_R_RegisterModel(filename);
	if(!pi->torsoModel)
	{
		Com_Printf("Failed to load model file %s\n", filename);
		return qfalse;
	}

	Com_sprintf(filename, sizeof(filename), "models/players/%s/head.md3", modelName);
	pi->headModel = trap_R_RegisterModel(filename);
	if(!pi->headModel)
	{
		Com_Printf("Failed to load model file %s\n", filename);
		return qfalse;
	}

	// NERVE - SMF - load backpack and helmet
	if(backpack)
	{
		pi->backpackModel = trap_R_RegisterModel(va("models/players/%s/%s", modelName, backpack));
	}

	if(helmet)
	{
		pi->helmetModel = trap_R_RegisterModel(va("models/players/%s/%s", modelName, helmet));
	}

	// if any skins failed to load, fall back to default
	if(!UI_RegisterClientSkin(pi, modelName, skinName))
	{
		if(!UI_RegisterClientSkin(pi, modelName, "default"))
		{
			Com_Printf("Failed to load skin file: %s : %s\n", modelName, skinName);
			return qfalse;
		}
	}

	// load the animations
//----(SA) changing name of config file to avoid backwards or alternate compatibility confustion
//  Com_sprintf( filename, sizeof( filename ), "models/players/%s/animation.cfg", modelName );
	Com_sprintf(filename, sizeof(filename), "models/players/%s/wolfanim.cfg", modelName);
//----(SA) end
	if(!UI_ParseAnimationFile(filename, pi))
	{							// NERVE - SMF - make this work with wolf
		Com_Printf("Failed to load animation file %s\n", filename);
		return qfalse;
	}

	return qtrue;
}
Example #5
0
/**
 * @brief DB_Init
 *
 * @return
 */
int DB_Init()
{
	char *to_ospath;

	isDBActive = qfalse;

	db_mode = Cvar_Get("db_mode", "0", CVAR_ARCHIVE | CVAR_LATCH);
	db_url  = Cvar_Get("db_url", "etl.db", CVAR_ARCHIVE | CVAR_LATCH); // filename in path (not real DB URL for now)

	if (db_mode->integer < 1 || db_mode->integer > 2)
	{
		Com_Printf("... DBMS is disabled\n");
		return 0; // return 0! - see isDBActive
	}

	Com_Printf("SQLite3 libversion %s - database URL '%s' - %s\n", sqlite3_libversion(), db_url->string, db_mode->integer == 1 ? "in-memory" : "in file");

	if (!db_url->string[0]) // FIXME: check extension db
	{
		Com_Printf("... can't init database - empty URL\n");
		return 1;
	}

	to_ospath                        = FS_BuildOSPath(Cvar_VariableString("fs_homepath"), db_url->string, "");
	to_ospath[strlen(to_ospath) - 1] = '\0';

	if (FS_SV_FileExists(db_url->string))
	{
		int result;

		Com_Printf("... loading existing database '%s'\n", to_ospath);

		if (db_mode->integer == 1)
		{
			// init memory table
			//result = sqlite3_open(":memory:", &db); // memory table, not shared see https://www.sqlite.org/inmemorydb.html
			result = sqlite3_open("file::memory:?cache=shared", &db); // In-memory databases with shared cache

			if (result != SQLITE_OK)
			{
				Com_Printf("... failed to open memory database - error: %s\n", sqlite3_errstr(result));
				(void) sqlite3_close(db);
				return 1;
			}

			// load from disk into memory
			result = DB_LoadOrSaveDb(db, to_ospath, 0);

			if (result != SQLITE_OK)
			{
				Com_Printf("... WARNING can't load database file %s\n", db_url->string);
				return 1;
			}
		}
		else if (db_mode->integer == 2)
		{
			result = sqlite3_open(to_ospath, &db);

			if (result != SQLITE_OK)
			{
				Com_Printf("... failed to open file database - error: %s\n", sqlite3_errstr(result));
				(void) sqlite3_close(db);
				return 1;
			}
		}
		else
		{
			Com_Printf("... failed to open database - unknown mode\n");
			return 1;
		}

		Com_Printf("... database file '%s' loaded\n", to_ospath);
	}
	else // create new
	{
		int result;

		Com_Printf("... no database file '%s' found ... creating now\n", to_ospath);
		result = DB_Create();

		if (result != 0)
		{
			Com_Printf("... WARNING can't create database [%i]\n", result);
			return 1;
		}

		// save memory db to disk
		if (db_mode->integer == 1)
		{
			result = DB_SaveMemDB();

			if (result != SQLITE_OK)
			{
				Com_Printf("... WARNING can't save memory database file [%i]\n", result);
				return 1;
			}
		}
	}

	Com_Printf("SQLite3 ET: L [%i] database '%s' init - autocommit %i\n", ETL_DBMS_VERSION, to_ospath, sqlite3_get_autocommit(db));

	isDBActive = qtrue;
	return 0;
}
Example #6
0
void FF_Stop(ffFX_e effect)
{
	Com_Printf("FF_Stop: Please implement fffx_id = %i\n",effect);
	// Do nothing
}
Example #7
0
void FF_Play(ffFX_e effect)
{
	int s;	// script id
	static int const_rumble[2] = {-1, -1}; // script id for constant rumble
	int client;

	// super huge switch for rumble effects
	switch(effect)
	{
	case fffx_AircraftCarrierTakeOff:
	case fffx_BasketballDribble:
	case fffx_CarEngineIdle:
	case fffx_ChainsawIdle:
	case fffx_ChainsawInAction:
	case fffx_DieselEngineIdle:
	case fffx_Jump:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 2, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 50000, 10000, 200);
			IN_AddRumbleState(s, 0, 0, 10);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_Land:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 2, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 50000, 10000, 200);
			IN_AddRumbleState(s, 0, 0, 10);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_MachineGun:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 2, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 56000, 20000, 230);
			IN_AddRumbleState(s, 0, 0, 10);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_Punched:
	case fffx_RocketLaunch:

	case fffx_SecretDoor:
	case fffx_SwitchClick:	// used by saber
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 1, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 30000, 10000, 120);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_WindGust:
	case fffx_WindShear:
	case fffx_Pistol:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 2, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 50000, 10000, 200);
			IN_AddRumbleState(s, 0, 0, 10);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_Shotgun:
	case fffx_Laser1:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 2, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 32000, 32000, 75);
			IN_AddRumbleState(s, 0, 0, 15);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_Laser2:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 2, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 25000, 25000, 75);
			IN_AddRumbleState(s, 0, 0, 10);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_Laser3:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 2, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 35000, 35000, 100);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_Laser4:
	case fffx_Laser5:
	case fffx_Laser6:
	case fffx_OutOfAmmo:
	case fffx_LightningGun:
	case fffx_Missile:
	case fffx_GatlingGun:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 2, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 39000, 0, 220);
			IN_AddRumbleState(s, 0, 0, 10);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_ShortPlasma:
	case fffx_PlasmaCannon1:
	case fffx_PlasmaCannon2:
	case fffx_Cannon:
	case fffx_FallingShort:
	case fffx_FallingMedium:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 1, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 25000,10000, 230);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_FallingFar:
		s = IN_CreateRumbleScript(ClientManager::ActiveController(), 1, true);
		if (s != -1)
		{
			IN_AddRumbleState(s, 32000,10000, 230);
			IN_ExecuteRumbleScript(s);
		}
		break;
	case fffx_StartConst:
		client = ClientManager::ActiveClientNum();
		if(const_rumble[client] == -1)
		{
			const_rumble[client] = IN_CreateRumbleScript(ClientManager::ActiveController(), 4, true);
			if (const_rumble[client] != -1)
			{
				IN_AddEffectFade4(const_rumble[client], 0,0, 50000, 50000, 1000);
				//IN_AddRumbleState(const_rumble[client], 50000, 0, 300);
				//IN_AddEffectFade4(const_rumble[client], 50000,50000, 0, 0, 1000);
				IN_ExecuteRumbleScript(const_rumble[client]);
			}
		}
		break;
	case fffx_StopConst:
		client = ClientManager::ActiveClientNum();
		if (const_rumble[client] == -1)
			return;
		IN_KillRumbleScript(const_rumble[client]);
		const_rumble[client] = -1;
		break;
	default:
		Com_Printf("No rumble script is defined for fffx_id = %i\n",effect);
		break;
	}
}
Example #8
0
/*
=================
Netchan_Process

Returns qfalse if the message should not be processed due to being
out of order or a fragment.

Msg must be large enough to hold MAX_MSGLEN, because if this is the
final fragment of a multi-part message, the entire thing will be
copied out.
=================
*/
qboolean Netchan_Process( netchan_t *chan, msg_t *msg ) {
	int			sequence, sequence_ack;
	//int			qport;
	int			fragmentStart, fragmentLength;
	qboolean	fragmented;

	// get sequence numbers		
	MSG_BeginReading( msg );
	sequence = MSG_ReadLong( msg );
	sequence_ack = MSG_ReadLong( msg );

	// check for fragment information
	if ( sequence & FRAGMENT_BIT ) {
		sequence &= ~FRAGMENT_BIT;
		fragmented = qtrue;
	} else {
		fragmented = qfalse;
	}

	// read the qport if we are a server
	if ( chan->sock == NS_SERVER ) {
		/*qport = */MSG_ReadShort( msg );
	}

	// read the fragment information
	if ( fragmented ) {
		fragmentStart = MSG_ReadShort( msg );
		fragmentLength = MSG_ReadShort( msg );
	} else {
		fragmentStart = 0;		// stop warning message
		fragmentLength = 0;
	}

	if ( showpackets->integer ) {
		if ( fragmented ) {
			Com_Printf( "%s recv %4i : s=%i ack=%i fragment=%i,%i\n"
				, netsrcString[ chan->sock ]
				, msg->cursize
				, sequence
				, sequence_ack
				, fragmentStart, fragmentLength );
		} else {
			Com_Printf( "%s recv %4i : s=%i ack=%i\n"
				, netsrcString[ chan->sock ]
				, msg->cursize
				, sequence
				, sequence_ack );
		}
	}

	//
	// discard out of order or duplicated packets
	//
	if ( sequence <= chan->incomingSequence ) {
		if ( showdrop->integer || showpackets->integer ) {
			Com_Printf( "%s:Out of order packet %i at %i\n"
				, NET_AdrToString( chan->remoteAddress )
				,  sequence
				, chan->incomingSequence );
		}
		return qfalse;
	}

	//
	// dropped packets don't keep the message from being used
	//
	chan->dropped = sequence - (chan->incomingSequence+1);
	if ( chan->dropped > 0 ) {
		if ( showdrop->integer || showpackets->integer ) {
			Com_Printf( "%s:Dropped %i packets at %i\n"
			, NET_AdrToString( chan->remoteAddress )
			, chan->dropped
			, sequence );
		}
	}
	

	//
	// if this is the final framgent of a reliable message,
	// bump incoming_reliable_sequence 
	//
	if ( fragmented ) {
		// make sure we 
		if ( sequence != chan->fragmentSequence ) {
			chan->fragmentSequence = sequence;
			chan->fragmentLength = 0;
		}

		// if we missed a fragment, dump the message
		if ( fragmentStart != chan->fragmentLength ) {
			if ( showdrop->integer || showpackets->integer ) {
				Com_Printf( "%s:Dropped a message fragment\n"
				, NET_AdrToString( chan->remoteAddress )
				, sequence);
			}
			// we can still keep the part that we have so far,
			// so we don't need to clear chan->fragmentLength
			return qfalse;
		}

		// copy the fragment to the fragment buffer
		if ( fragmentLength < 0 || msg->readcount + fragmentLength > msg->cursize ||
			chan->fragmentLength + fragmentLength > (int)sizeof( chan->fragmentBuffer ) ) {
			if ( showdrop->integer || showpackets->integer ) {
				Com_Printf ("%s:illegal fragment length\n"
				, NET_AdrToString (chan->remoteAddress ) );
			}
			return qfalse;
		}

		memcpy( chan->fragmentBuffer + chan->fragmentLength, 
			msg->data + msg->readcount, fragmentLength );

		chan->fragmentLength += fragmentLength;

		// if this wasn't the last fragment, don't process anything
		if ( fragmentLength == FRAGMENT_SIZE ) {
			return qfalse;
		}

		if ( chan->fragmentLength > msg->maxsize ) {
			Com_Printf( "%s:fragmentLength %i > msg->maxsize\n"
				, NET_AdrToString (chan->remoteAddress ),
				chan->fragmentLength );
			return qfalse;
		}

		// copy the full message over the partial fragment

		// make sure the sequence number is still there
		*(int *)msg->data = LittleLong( sequence );

		memcpy( msg->data + 4, chan->fragmentBuffer, chan->fragmentLength );
		msg->cursize = chan->fragmentLength + 4;
		chan->fragmentLength = 0;
		msg->readcount = 4;	// past the sequence number

		return qtrue;
	}

	//
	// the message can now be read from the current message pointer
	//
	chan->incomingSequence = sequence;
	chan->incomingAcknowledged = sequence_ack;

	return qtrue;
}
/*
===================
CL_ServersResponsePacket
===================
*/
void CL_ServersResponsePacket( msg_t *msg ) {
	int				i, count, max, total;
	serverAddress_t addresses[MAX_SERVERSPERPACKET];
	int				numservers;
	char*			buffptr;
	char*			buffend;
	
	Com_Printf(0, "CL_ServersResponsePacket\n");

	if (cls.numglobalservers == -1) {
		// state to detect lack of servers or lack of response
		cls.numglobalservers = 0;
		cls.numGlobalServerAddresses = 0;
	}

	// parse through server response string
	numservers = 0;
	buffptr    = msg->data;
	buffend    = buffptr + msg->cursize;
	while (buffptr+1 < buffend) {
		// advance to initial token
		do {
			if (*buffptr++ == '\\')
				break;		
		}
		while (buffptr < buffend);

		if ( buffptr >= buffend - 6 ) {
			break;
		}

		// parse out ip
		addresses[numservers].ip[0] = *buffptr++;
		addresses[numservers].ip[1] = *buffptr++;
		addresses[numservers].ip[2] = *buffptr++;
		addresses[numservers].ip[3] = *buffptr++;

		// parse out port
		addresses[numservers].port = (*(buffptr++))<<8;
		addresses[numservers].port += (*(buffptr++)) & 0xFF;
		addresses[numservers].port = ntohs( addresses[numservers].port );

		// syntax check
		if (*buffptr != '\\') {
			break;
		}

		/*Com_DPrintf( 0, "server: %d ip: %d.%d.%d.%d:%d\n",numservers,
				addresses[numservers].ip[0],
				addresses[numservers].ip[1],
				addresses[numservers].ip[2],
				addresses[numservers].ip[3],
				ntohs(addresses[numservers].port) );*/

		numservers++;
		if (numservers >= MAX_SERVERSPERPACKET) {
			break;
		}

		// parse out EOT
		if (buffptr[1] == 'E' && buffptr[2] == 'O' && buffptr[3] == 'T') {
			break;
		}
	}

	count = cls.numglobalservers;
	max = MAX_GLOBAL_SERVERS;

	for (i = 0; i < numservers && count < max; i++) {
		// check if this server already exists
		netadr_t address;
		address.type  = NA_IP;
		address.ip[0] = addresses[i].ip[0];
		address.ip[1] = addresses[i].ip[1];
		address.ip[2] = addresses[i].ip[2];
		address.ip[3] = addresses[i].ip[3];
		address.port  = addresses[i].port;

		bool alreadyExists = false;

		for (int j = 0; j < cls.numglobalservers; j++)
		{
			if (NET_CompareAdr(cls.globalServers[j].adr, address))
			{
				alreadyExists = true;
				break;
			}
		}

		if (alreadyExists)
		{
			continue;
		}

		// build net address
		serverInfo_t *server = &cls.globalServers[count];

		CL_InitServerInfo( server, &addresses[i] );
		// advance to next slot
		count++;
	}

	// if getting the global list
	if (cls.masterNum == 0) {
		if ( cls.numGlobalServerAddresses < MAX_GLOBAL_SERVERS ) {
			// if we couldn't store the servers in the main list anymore
			for (; i < numservers && count >= max; i++) {
				serverAddress_t *addr;
				// just store the addresses in an additional list
				addr = &cls.globalServerAddresses[cls.numGlobalServerAddresses++];
				addr->ip[0] = addresses[i].ip[0];
				addr->ip[1] = addresses[i].ip[1];
				addr->ip[2] = addresses[i].ip[2];
				addr->ip[3] = addresses[i].ip[3];
				addr->port  = addresses[i].port;
			}
		}
	}

	cls.numglobalservers = count;
	total = count + cls.numGlobalServerAddresses;

	Com_Printf(0, "%d servers parsed (total %d)\n", numservers, total);
}
Example #10
0
//----------------------------------------------------------
void fx_runner_link( gentity_t *ent )
{
	vec3_t	dir;

	if ( ent->target )
	{
		// try to use the target to override the orientation
		gentity_t	*target = NULL;

		target = G_Find( target, FOFS(targetname), ent->target );

		if ( !target )
		{
			// Bah, no good, dump a warning, but continue on and use the UP vector
			Com_Printf( "fx_runner_link: target specified but not found: %s\n", ent->target );
			Com_Printf( "  -assuming UP orientation.\n" );
		}
		else
		{
			// Our target is valid so let's override the default UP vector
			VectorSubtract( target->s.origin, ent->s.origin, dir );
			VectorNormalize( dir );
			vectoangles( dir, ent->s.angles );
		}
	}

	// don't really do anything with this right now other than do a check to warn the designers if the target2 is bogus
	if ( ent->target2 )
	{
		gentity_t	*target = NULL;

		target = G_Find( target, FOFS(targetname), ent->target2 );

		if ( !target )
		{
			// Target2 is bogus, but we can still continue
			Com_Printf( "fx_runner_link: target2 was specified but is not valid: %s\n", ent->target2 );
		}
	}

	G_SetAngles( ent, ent->s.angles );

	if ( ent->spawnflags & 1 || ent->spawnflags & 2 ) // STARTOFF || ONESHOT
	{
		// We won't even consider thinking until we are used
		ent->nextthink = -1;
	}
	else
	{
		if ( VALIDSTRING( ent->soundSet ) == true )
		{
			ent->s.loopSound = CAS_GetBModelSound( ent->soundSet, BMS_MID );

			if ( ent->s.loopSound < 0 )
			{
				ent->s.loopSound = 0;
			}
		}

		// Let's get to work right now!
		ent->e_ThinkFunc = thinkF_fx_runner_think;
		ent->nextthink = level.time + 200; // wait a small bit, then start working
	}

	// make us useable if we can be targeted
	if ( ent->targetname )
	{
		ent->e_UseFunc = useF_fx_runner_use;
	}
}
Example #11
0
/*
===============
Netchan_Transmit

Sends a message to a connection, fragmenting if necessary
A 0 length will still generate a packet.
================
*/
void Netchan_Transmit( netchan_t *chan, int length, const byte *data ) {
	msg_t		send;
	byte		send_buf[MAX_PACKETLEN];
	int			fragmentStart, fragmentLength;

	fragmentStart = 0;		// stop warning message
	fragmentLength = 0;

	// fragment large reliable messages
	if ( length >= FRAGMENT_SIZE ) {
		fragmentStart = 0;
		do {
			// write the packet header
			MSG_Init (&send, send_buf, sizeof(send_buf));

			MSG_WriteLong( &send, chan->outgoingSequence | FRAGMENT_BIT );
			MSG_WriteLong( &send, chan->incomingSequence );

			// send the qport if we are a client
			if ( chan->sock == NS_CLIENT ) {
				MSG_WriteShort( &send, qport->integer );
			}

			// copy the reliable message to the packet first
			fragmentLength = FRAGMENT_SIZE;
			if ( fragmentStart  + fragmentLength > length ) {
				fragmentLength = length - fragmentStart;
			}

			MSG_WriteShort( &send, fragmentStart );
			MSG_WriteShort( &send, fragmentLength );
			MSG_WriteData( &send, data + fragmentStart, fragmentLength );

			// send the datagram
			NET_SendPacket( chan->sock, send.cursize, send.data, chan->remoteAddress );

			if ( showpackets->integer ) {
				Com_Printf ("%s send %4i : s=%i ack=%i fragment=%i,%i\n"
					, netsrcString[ chan->sock ]
					, send.cursize
					, chan->outgoingSequence - 1
					, chan->incomingSequence
					, fragmentStart, fragmentLength);
			}

			fragmentStart += fragmentLength;
			// this exit condition is a little tricky, because a packet
			// that is exactly the fragment length still needs to send
			// a second packet of zero length so that the other side
			// can tell there aren't more to follow
		} while ( fragmentStart != length || fragmentLength == FRAGMENT_SIZE );

		chan->outgoingSequence++;
		return;
	}

	// write the packet header
	MSG_Init (&send, send_buf, sizeof(send_buf));

	MSG_WriteLong( &send, chan->outgoingSequence );
	MSG_WriteLong( &send, chan->incomingSequence );
	chan->outgoingSequence++;

	// send the qport if we are a client
	if ( chan->sock == NS_CLIENT ) {
		MSG_WriteShort( &send, qport->integer );
	}

	MSG_WriteData( &send, data, length );

	// send the datagram
	NET_SendPacket( chan->sock, send.cursize, send.data, chan->remoteAddress );

	if ( showpackets->integer ) {
		Com_Printf( "%s send %4i : s=%i ack=%i\n"
			, netsrcString[ chan->sock ]
			, send.cursize
			, chan->outgoingSequence - 1
			, chan->incomingSequence );
	}
}
//special routine for tracking angles between client and server -rww
void G2Tur_SetBoneAngles(gentity_t *ent, char *bone, vec3_t angles)
{
	int *thebone = &ent->s.boneIndex1;
	int *firstFree = NULL;
	int i = 0;
	int boneIndex = G_BoneIndex(bone);
	int flags, up, right, forward;
	vec3_t *boneVector = &ent->s.boneAngles1;
	vec3_t *freeBoneVec = NULL;

	while (thebone)
	{
		if (!*thebone && !firstFree)
		{ //if the value is 0 then this index is clear, we can use it if we don't find the bone we want already existing.
			firstFree = thebone;
			freeBoneVec = boneVector;
		}
		else if (*thebone)
		{
			if (*thebone == boneIndex)
			{ //this is it
				break;
			}
		}

		switch (i)
		{
		case 0:
			thebone = &ent->s.boneIndex2;
			boneVector = &ent->s.boneAngles2;
			break;
		case 1:
			thebone = &ent->s.boneIndex3;
			boneVector = &ent->s.boneAngles3;
			break;
		case 2:
			thebone = &ent->s.boneIndex4;
			boneVector = &ent->s.boneAngles4;
			break;
		default:
			thebone = NULL;
			boneVector = NULL;
			break;
		}

		i++;
	}

	if (!thebone)
	{ //didn't find it, create it
		if (!firstFree)
		{ //no free bones.. can't do a thing then.
			Com_Printf("WARNING: NPC has no free bone indexes\n");
			return;
		}

		thebone = firstFree;

		*thebone = boneIndex;
		boneVector = freeBoneVec;
	}

	//If we got here then we have a vector and an index.

	//Copy the angles over the vector in the entitystate, so we can use the corresponding index
	//to set the bone angles on the client.
	VectorCopy(angles, *boneVector);

	//Now set the angles on our server instance if we have one.

	if (!ent->ghoul2)
	{
		return;
	}

	flags = BONE_ANGLES_POSTMULT;
	up = POSITIVE_Y;
	right = NEGATIVE_Z;
	forward = NEGATIVE_X;

	//first 3 bits is forward, second 3 bits is right, third 3 bits is up
	ent->s.boneOrient = ((forward)|(right<<3)|(up<<6));

	trap->G2API_SetBoneAngles( ent->ghoul2,
					0,
					bone,
					angles, 
					flags,
					up,
					right,
					forward,
					NULL,
					100,
					level.time ); 
}
Example #13
0
//
// Load vertex and fragment shader, compile, link etc.
//
qbool SHD_Load(shader_t *s, const char *vertex_fileName, const char *fragment_fileName)
{
	shader_t	s_tmp;
	GLint		linked = 0;
	int			i;

	if (!SHD_Initialized())
	{
		Com_Printf("SHD_Load: shader system not initialized\n");
		return false;
	}

	memset(&s_tmp, 0, sizeof(s_tmp));

	// just some assertion checks
	SHD_AlredyLoaded(s);

	if (shd.count >= MAX_SHADERS)
	{
		Com_Printf("SHD_Load: full shader list\n");
		goto cleanup;
	}

	if (!s)
	{
		Com_Printf("SHD_Load: zero shader\n");
		goto cleanup;
	}

	// we must have here nulified struct
	for (i = 0; i < sizeof(*s); i++)
	{
		if (((byte*)s)[i])
		{
			Com_Printf("SHD_Load: shader struct not ready\n");
			goto cleanup;
		}
	}

	// create a program object
	s_tmp.program			= glCreateProgramObjectARB();
	if (!s_tmp.program)
	{
		Com_Printf("SHD_Load: failed to create program\n");
		goto cleanup;
	}

	// create shaders
    s_tmp.vertexShader		= glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
    s_tmp.fragmentShader	= glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

	// load source code strings into shaders
	if (!SHD_LoadAndCompile(s_tmp.vertexShader, vertex_fileName))
		goto cleanup;

    if (!SHD_LoadAndCompile(s_tmp.fragmentShader, fragment_fileName))
		goto cleanup;

	// attach the two compiled shaders
	// TODO: check success
    glAttachObjectARB(s_tmp.program, s_tmp.vertexShader);
    glAttachObjectARB(s_tmp.program, s_tmp.fragmentShader);

	// link the program object and print out the info log
    glLinkProgramARB(s_tmp.program);
	// check for OpenGL errors
    if (!SHD_CheckOpenGLError())
	{
		Com_Printf("SHD_Load: OpenGL errors encountered\n");
		goto cleanup;
	}

    glGetObjectParameterivARB(s_tmp.program, GL_OBJECT_LINK_STATUS_ARB, &linked);
    if (!linked)
	{
		Com_Printf("SHD_Load: program not linked\n");
		goto cleanup;
	}

	// copy struct
	*s = s_tmp;

	// link to shd list
	shd.shaders[shd.count] = s;
	shd.count++;

	return true;

cleanup: // GOTO MARK
	SHD_Free(&s_tmp);

	return false;
}
Example #14
0
/*
=================
CG_DrawScoreboard
=================
*/
static void CG_DrawClientScore( int y, score_t *score, float *color, float fade, qboolean largeFormat ) {
	char			string[1024];
	vec3_t			headAngles;
	clientInfo_t	*ci;
	int				iconx, headx;
	float			scale = 0.35;
	int				h = CG_Text_Height( "Tj", scale, 0 );
	//int				ty;

	if ( score->client < 0 || score->client >= cgs.maxclients ) {
		Com_Printf( "Bad score->client: %i\n", score->client );
		return;
	}
	color[3] = fade;
	
	ci = &cgs.clientinfo[score->client];

	iconx = SB_BOTICON_X + (SB_RATING_WIDTH / 2);
	headx = SB_HEAD_X + (SB_RATING_WIDTH / 2);

	// draw the handicap or bot skill marker (unless player has flag)
	if ( ci->powerups & ( 1 << PW_NEUTRALFLAG ) ) {
		if( largeFormat ) {
			CG_DrawFlagModel( iconx, y - SB_LARGE_SPACER, SB_LARGE_ICON, SB_LARGE_ICON, TEAM_FREE, qfalse, SCR_CENTER );
		} else {
			CG_DrawFlagModel( iconx, y - SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, TEAM_FREE, qfalse, SCR_CENTER );
		}
	} else if ( ci->powerups & ( 1 << PW_REDFLAG ) ) {
		if( largeFormat ) {
			CG_DrawFlagModel( iconx, y - SB_LARGE_SPACER, SB_LARGE_ICON, SB_LARGE_ICON, TEAM_RED, qfalse, SCR_CENTER );
		} else {
			CG_DrawFlagModel( iconx, y - SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, TEAM_RED, qfalse, SCR_CENTER );
		}
	} else if ( ci->powerups & ( 1 << PW_BLUEFLAG ) ) {
		if( largeFormat ) {
			CG_DrawFlagModel( iconx, y - SB_LARGE_SPACER, SB_LARGE_ICON, SB_LARGE_ICON, TEAM_BLUE, qfalse, SCR_CENTER );
		} else {
			CG_DrawFlagModel( iconx, y - SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, TEAM_BLUE, qfalse, SCR_CENTER );
		}
	} else {
		if ( ci->botSkill > 0 && ci->botSkill <= 5 ) {
			if ( cg_drawIcons.integer ) {
				if( largeFormat ) {
					CG_DrawColorPic( iconx, y - SB_LARGE_SPACER, SB_LARGE_ICON, SB_LARGE_ICON, cgs.media.botSkillShaders[ci->botSkill - 1], SCR_CENTER, color );
				} else {
					CG_DrawColorPic( iconx, y - SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, cgs.media.botSkillShaders[ci->botSkill - 1], SCR_CENTER, color );
				}
			}
		} else if ( ci->handicap < 100 ) {
			Com_sprintf( string, sizeof( string ), "%i", ci->handicap );
			if ( gt[cgs.gametype].duel ) {
				if ( cg_highResFonts.integer ) {
					CG_Text_Paint( iconx, y + h + ((float)h/2), scale, color, string, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER );
				} else {
					CG_DrawSmallStringColor( iconx, y - SMALLCHAR_HEIGHT/2, string, color, SCR_CENTER );
				}
			} else {
				if ( cg_highResFonts.integer ) {
					//w = CG_Text_Width(s, scale, 0);
					h = CG_Text_Height(string, scale, 0);
					CG_Text_Paint( iconx, y + h, scale, color, string, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER );
				} else {
					CG_DrawSmallStringColor( iconx, y, string, color, SCR_CENTER );
				}
			}
		}

		// draw the wins / losses
		if ( gt[cgs.gametype].duel ) {
			Com_sprintf( string, sizeof( string ), "%i/%i", ci->wins, ci->losses );
			if ( ci->handicap < 100 && !ci->botSkill ) {
				if ( cg_highResFonts.integer ) {
					CG_Text_Paint( iconx, y + h + ((float)h/2), scale, color, string, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER );
				} else {
					CG_DrawSmallStringColor( iconx, y + SMALLCHAR_HEIGHT/2, string, color, SCR_CENTER );
				}
			} else {
				if ( cg_highResFonts.integer ) {
					CG_Text_Paint( iconx, y + h, scale, color, string, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER );
				} else {
					CG_DrawSmallStringColor( iconx, y, string, color, SCR_CENTER );
				}
			}
		}
	}

	// draw the face
	VectorClear( headAngles );
	headAngles[YAW] = 180;
	if ( largeFormat ) {
		CG_DrawHead( headx, y - SB_LARGE_SPACER*2, ICON_SIZE, ICON_SIZE, 
			score->client, headAngles, SCR_CENTER, color );
	} else {
		CG_DrawHead( headx, y + SB_SMALL_SPACER, SB_SMALL_ICON, SB_SMALL_ICON, score->client, headAngles, SCR_CENTER, color );
	}

	// draw the score line

	// highlight your position
	if ( score->client == cg.snap->ps.clientNum ) {
		float	hcolor[4];
		int		rank;

		localClient = qtrue;

		if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR ) {
			rank = -1;
		} else {
			rank = cg.snap->ps.persistant[PERS_RANK] & ~RANK_TIED_FLAG;
		}
		if ( rank == 0 ) {
			hcolor[0] = 0;
			hcolor[1] = 0;
			hcolor[2] = 0.7f;
		} else if ( rank == 1 ) {
			hcolor[0] = 0.7f;
			hcolor[1] = 0;
			hcolor[2] = 0;
		} else if ( rank == 2 ) {
			hcolor[0] = 0.7f;
			hcolor[1] = 0.7f;
			hcolor[2] = 0;
		} else {
			hcolor[0] = 0.4f;
			hcolor[1] = 0.4f;
			hcolor[2] = 0.4f;
		}

		hcolor[3] = fade * 0.7;
/*
		CG_DrawTeamBackground( SB_SCORELINE_X + BIGCHAR_WIDTH + (SB_RATING_WIDTH / 2), y, 
			SCREEN_WIDTH - SB_SCORELINE_X - BIGCHAR_WIDTH, BIGCHAR_HEIGHT+1, 1, gt[cgs.gametype].teams ? cg.snap->ps.persistant[PERS_TEAM] : hcolor, SCR_CENTER );
*/		
		CG_FillRect( SB_SCORELINE_X + BIGCHAR_WIDTH + (SB_RATING_WIDTH / 2), y, 
			SCREEN_WIDTH - SB_SCORELINE_X - BIGCHAR_WIDTH, BIGCHAR_HEIGHT+2, gt[cgs.gametype].teams ? CG_TeamColorDark(cg.snap->ps.persistant[PERS_TEAM], fade) : hcolor, SCR_CENTER );
	}


	// draw client score strings
	if ( cg_highResFonts.integer ) {
		qboolean spec = ci->team == TEAM_SPECTATOR;
		int		w;
		char	*s;

		// score
		s = (score->ping == -1) ? "CONN" : spec ? "SPEC" : cg.warmup ? "-" : va("%i", score->score);
		w = CG_Text_Width( s, scale, 0 );
		CG_Text_Paint( SB_SCORE_X + (SB_RATING_WIDTH / 2) + 64-w, y + h, scale, color, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER );
		// ping
		s = va( "%i", score->ping );
		w = CG_Text_Width( s, scale, 0 );
		CG_Text_Paint( SB_PING_X - (SB_RATING_WIDTH + BIGCHAR_WIDTH )/2 + 64-w, y + h, scale, color, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER );
		// time
		s = va( "%i", score->time );	//CG_IntToTime( score->time*1000, qtrue, qfalse );
		w = CG_Text_Width( s, scale, 0 );
		CG_Text_Paint( SB_TIME_X - (SB_RATING_WIDTH + BIGCHAR_WIDTH )/2 + 64-w, y + h, scale, color, s, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER );
		// name
		CG_Text_Paint( SB_NAME_X - (SB_RATING_WIDTH / 2), y + h, scale, color, ci->name, 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER );
	} else {
		if ( score->ping == -1 ) {
			Com_sprintf(string, sizeof(string),
				" connecting    %s", ci->name);
		} else if ( ci->team == TEAM_SPECTATOR ) {
			Com_sprintf(string, sizeof(string),
				" SPECT %3i %4i %s", score->ping, score->time, ci->name);
		} else {
			Com_sprintf(string, sizeof(string),
				"%5i %4i %4i %s", score->score, score->ping, score->time, ci->name);
		}
		CG_DrawBigString( SB_SCORELINE_X + (SB_RATING_WIDTH / 2), y, string, fade, SCR_CENTER );
	}

	// add the "ready" marker for intermission exiting
	if ( cg.snap->ps.stats[STAT_CLIENTS_READY] & ( 1 << score->client ) ) {
		if ( cg_highResFonts.integer ) {
			CG_Text_Paint( iconx, y + h, scale, color, "READY", 0, 0, ITEM_TEXTSTYLE_SHADOWED, SCR_CENTER );
		} else {
			CG_DrawBigStringColor( iconx, y, "READY", color, SCR_CENTER );
		}
	}
}
Example #15
0
/*
* S_Init
*/
qboolean S_Init( void *hwnd, int maxEntities, qboolean verbose )
{
	int numDevices;
	int userDeviceNum = -1;
	char *devices, *defaultDevice;

	soundpool = S_MemAllocPool( "OpenAL sound module" );

	alDevice = NULL;
	alContext = NULL;

#ifdef OPENAL_RUNTIME
	if( !QAL_Init( ALDRIVER, verbose ) )
	{
#ifdef ALDRIVER_ALT
		if( !QAL_Init( ALDRIVER_ALT, verbose ) )
#endif
		{
			Com_Printf( "Failed to load OpenAL library: %s\n", ALDRIVER );
			goto fail_no_device;
		}
	}
#endif

	// get system default device identifier
	defaultDevice = ( char * )qalcGetString( NULL, ALC_DEFAULT_DEVICE_SPECIFIER );
	if( !defaultDevice )
	{
		Com_Printf( "Failed to get openAL default device\n" );
		goto fail_no_device;
	}

	s_openAL_device = trap_Cvar_Get( "s_openAL_device", ALDEVICE_DEFAULT ? ALDEVICE_DEFAULT : defaultDevice, CVAR_ARCHIVE|CVAR_LATCH_SOUND );

	devices = ( char * )qalcGetString( NULL, ALC_DEVICE_SPECIFIER );
	for( numDevices = 0; *devices; devices += strlen( devices ) + 1, numDevices++ )
	{
		if( !Q_stricmp( s_openAL_device->string, devices ) )
		{
			userDeviceNum = numDevices;

			// force case sensitive
			if( strcmp( s_openAL_device->string, devices ) )
				trap_Cvar_ForceSet( "s_openAL_device", devices );
		}
	}

	if( !numDevices )
	{
		Com_Printf( "Failed to get openAL devices\n" );
		goto fail_no_device;
	}

	// the device assigned by the user is not available
	if( userDeviceNum == -1 )
	{
		Com_Printf( "'s_openAL_device': incorrect device name, reseting to default\n" );

		trap_Cvar_ForceSet( "s_openAL_device", ALDEVICE_DEFAULT ? ALDEVICE_DEFAULT : defaultDevice );

		devices = ( char * )qalcGetString( NULL, ALC_DEVICE_SPECIFIER );
		for( numDevices = 0; *devices; devices += strlen( devices ) + 1, numDevices++ )
		{
			if( !Q_stricmp( s_openAL_device->string, devices ) )
				userDeviceNum = numDevices;
		}

		if( userDeviceNum == -1 )
			trap_Cvar_ForceSet( "s_openAL_device", defaultDevice );
	}

	alDevice = qalcOpenDevice( (const ALchar *)s_openAL_device->string );
	if( !alDevice )
	{
		Com_Printf( "Failed to open device\n" );
		goto fail_no_device;
	}

	// Create context
	alContext = qalcCreateContext( alDevice, NULL );
	if( !alContext )
	{
		Com_Printf( "Failed to create context\n" );
		goto fail;
	}
	qalcMakeContextCurrent( alContext );

	if( verbose )
	{
		Com_Printf( "OpenAL initialized\n" );

		if( numDevices )
		{
			int i;

			Com_Printf( "  Devices:    " );

			devices = ( char * )qalcGetString( NULL, ALC_DEVICE_SPECIFIER );
			for( i = 0; *devices; devices += strlen( devices ) + 1, i++ )
				Com_Printf( "%s%s", devices, ( i < numDevices - 1 ) ? ", " : "" );
			Com_Printf( "\n" );

			if( defaultDevice && *defaultDevice )
				Com_Printf( "  Default system device: %s\n", defaultDevice );

			Com_Printf( "\n" );
		}

		Com_Printf( "  Device:     %s\n", qalcGetString( alDevice, ALC_DEVICE_SPECIFIER ) );
		Com_Printf( "  Vendor:     %s\n", qalGetString( AL_VENDOR ) );
		Com_Printf( "  Version:    %s\n", qalGetString( AL_VERSION ) );
		Com_Printf( "  Renderer:   %s\n", qalGetString( AL_RENDERER ) );
		Com_Printf( "  Extensions: %s\n", qalGetString( AL_EXTENSIONS ) );
	}

	// Check for Linux shutdown race condition
	if( !Q_stricmp( qalGetString( AL_VENDOR ), "J. Valenzuela" ) )
		snd_shutdown_bug = qtrue;

	s_volume = trap_Cvar_Get( "s_volume", "0.8", CVAR_ARCHIVE );
	s_musicvolume = trap_Cvar_Get( "s_musicvolume", "0.5", CVAR_ARCHIVE );
	s_doppler = trap_Cvar_Get( "s_doppler", "1.0", CVAR_ARCHIVE );
	s_sound_velocity = trap_Cvar_Get( "s_sound_velocity", "10976", CVAR_DEVELOPER );
	s_stereo2mono = trap_Cvar_Get ( "s_stereo2mono", "0", CVAR_ARCHIVE );

	qalDopplerFactor( s_doppler->value );
	qalDopplerVelocity( s_sound_velocity->value > 0.0f ? s_sound_velocity->value : 0.0f );
	if( qalSpeedOfSound ) // opelAL 1.1 only. alDopplerVelocity being deprecated
		qalSpeedOfSound( s_sound_velocity->value > 0.0f ? s_sound_velocity->value : 0.0f );

	s_doppler->modified = qfalse;

	S_SetAttenuationModel( S_DEFAULT_ATTENUATION_MODEL, S_DEFAULT_ATTENUATION_MAXDISTANCE, S_DEFAULT_ATTENUATION_REFDISTANCE );

	S_LockBackgroundTrack( qfalse );

	if( !S_InitDecoders( verbose ) )
	{
		Com_Printf( "Failed to init decoders\n" );
		goto fail;
	}
	if( !S_InitBuffers() )
	{
		Com_Printf( "Failed to init buffers\n" );
		goto fail;
	}
	if( !S_InitSources( maxEntities, verbose ) )
	{
		Com_Printf( "Failed to init sources\n" );
		goto fail;
	}

#ifdef ENABLE_PLAY
	trap_Cmd_AddCommand( "play", S_Play );
#endif
	trap_Cmd_AddCommand( "music", S_Music );
	trap_Cmd_AddCommand( "stopmusic", S_StopMusic );
	trap_Cmd_AddCommand( "prevmusic", S_PrevMusic );
	trap_Cmd_AddCommand( "nextmusic", S_NextMusic );
	trap_Cmd_AddCommand( "pausemusic", S_PauseMusic );
	trap_Cmd_AddCommand( "soundlist", S_SoundList );
	trap_Cmd_AddCommand( "s_devices", S_ListDevices );

	return qtrue;

fail:
	if( alContext )
	{
		if( !snd_shutdown_bug )
			qalcMakeContextCurrent( NULL );

		qalcDestroyContext( alContext );
		alContext = NULL;
	}

	if( alDevice )
	{
		qalcCloseDevice( alDevice );
		alDevice = NULL;
	}

fail_no_device:
	S_MemFreePool( &soundpool );
	return qfalse;
}
Example #16
0
static void CG_DrawClientScore( int y, score_t *score, const vector4 *color, float fade, qboolean largeFormat ) {
    //vector3	headAngles;
    clientInfo_t	*ci;
    int				iconx = SB_SCORELINE_X - 5;//SB_BOTICON_X + (SB_RATING_WIDTH / 2);
    float			scale = largeFormat ? 1.0f : 0.75f,
                    iconSize = largeFormat ? SB_NORMAL_HEIGHT : SB_INTER_HEIGHT;

    iconx -= iconSize;
    if ( score->client < 0 || score->client >= cgs.maxclients ) {
        Com_Printf( "Bad score->client: %i\n", score->client );
        return;
    }

    ci = &cgs.clientinfo[score->client];

    // draw the handicap or bot skill marker (unless player has flag)
    if ( ci->powerups & (1 << PW_NEUTRALFLAG) ) {
        if ( largeFormat )
            CG_DrawFlagModel( iconx, y - (32 - BIGCHAR_HEIGHT) / 2, iconSize, iconSize, TEAM_FREE, qfalse );
        else
            CG_DrawFlagModel( iconx, y, iconSize, iconSize, TEAM_FREE, qfalse );
    }

    else if ( ci->powerups & (1 << PW_REDFLAG) )
        CG_DrawFlagModel( iconx, y, iconSize, iconSize, TEAM_RED, qfalse );

    else if ( ci->powerups & (1 << PW_BLUEFLAG) )
        CG_DrawFlagModel( iconx, y, iconSize, iconSize, TEAM_BLUE, qfalse );

    else if ( cgs.gametype == GT_POWERDUEL && (ci->duelTeam == DUELTEAM_LONE || ci->duelTeam == DUELTEAM_DOUBLE) ) {
        CG_DrawPic( iconx, y, iconSize, iconSize, trap->R_RegisterShaderNoMip(
                        (ci->duelTeam == DUELTEAM_LONE) ? "gfx/mp/pduel_icon_lone" : "gfx/mp/pduel_icon_double" ) );
    }

    else if ( cgs.gametype == GT_SIEGE ) {
        // try to draw the shader for this class on the scoreboard
        if ( ci->siegeIndex != -1 ) {
            siegeClass_t *scl = &bgSiegeClasses[ci->siegeIndex];

            if ( scl->classShader )
                CG_DrawPic( iconx, y, largeFormat ? 24 : 12, largeFormat ? 24 : 12, scl->classShader );
        }
    }

    else if ( ci->modelIcon && cg_oldScoreboardSkinIcons.integer )
        CG_DrawPic( iconx, y, iconSize, iconSize, ci->modelIcon );


    // highlight your position
    if ( score->client == cg.snap->ps.clientNum ) {
        vector4 hcolor;
        int		rank;

        localClient = qtrue;

        if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_SPECTATOR || cgs.gametype >= GT_TEAM )
            rank = -1;
        else
            rank = cg.snap->ps.persistant[PERS_RANK] & ~RANK_TIED_FLAG;
        if ( rank == 0 ) {
            hcolor.r = 0;
            hcolor.g = 0;
            hcolor.b = 0.7f;
        }
        else if ( rank == 1 ) {
            hcolor.r = 0.7f;
            hcolor.g = 0;
            hcolor.b = 0;
        }
        else if ( rank == 2 ) {
            hcolor.r = 0.7f;
            hcolor.g = 0.7f;
            hcolor.b = 0;
        }
        else {
            hcolor.r = 0.7f;
            hcolor.g = 0.7f;
            hcolor.b = 0.7f;
        }

        hcolor.a = fade * 0.7f;
        CG_FillRect( SB_SCORELINE_X - 5, y /*+ 2*/, SB_SCORELINE_WIDTH /*- SB_SCORELINE_X * 2 + 10*/, largeFormat ? SB_NORMAL_HEIGHT : SB_INTER_HEIGHT, &hcolor );
    }

    CG_Text_Paint( SB_NAME_X, y, 0.9f * scale, &colorWhite, ci->name, 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_MEDIUM );

    if ( score->ping != -1 ) {
        if ( ci->team != TEAM_SPECTATOR || cgs.gametype == GT_DUEL || cgs.gametype == GT_POWERDUEL ) {
            if ( cgs.gametype == GT_DUEL || cgs.gametype == GT_POWERDUEL )
                CG_Text_Paint( SB_SCORE_X, y, 1.0f * scale, &colorWhite, va( "%i/%i", ci->wins, ci->losses ), 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_SMALL );
            else {
                if ( Server_Supports( SSF_SCOREBOARD_KD ) )
                    CG_Text_Paint( SB_SCORE_X, y, 1.0f * scale, &colorWhite, va( "%i/%i", score->score, score->deaths ), 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_SMALL );
                else
                    CG_Text_Paint( SB_SCORE_X, y, 1.0f * scale, &colorWhite, va( "%i", score->score ), 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_SMALL );
            }
        }

        if ( cgs.clientinfo[score->client].botSkill != -1 && cg_oldScoreboardShowBots.integer == 2 )
            CG_Text_Paint( SB_PING_X, y, 1.0f * scale, &colorWhite, "-", 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_SMALL );
        else
            CG_Text_Paint( SB_PING_X, y, 1.0f * scale, &colorWhite, va( "%i", score->ping ), 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_SMALL );

        CG_Text_Paint( SB_TIME_X, y, 1.0f * scale, &colorWhite, va( "%i", score->time ), 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_SMALL );
    }
    else {
        CG_Text_Paint( SB_SCORE_X, y, 1.0f * scale, &colorWhite, "-", 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_SMALL );
        CG_Text_Paint( SB_PING_X, y, 1.0f * scale, &colorWhite, "-", 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_SMALL );
        CG_Text_Paint( SB_TIME_X, y, 1.0f * scale, &colorWhite, "-", 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_SMALL );
    }

    // add the "ready" marker for intermission exiting
    if ( cg.snap->ps.stats[STAT_CLIENTS_READY] & (1 << score->client) ) {
        CG_Text_Paint( cg_oldScoreboardSkinIcons.integer ? 4 : SB_NAME_X - 48, y + 2, 0.7f * scale, &colorWhite,
                       CG_GetStringEdString( "MP_INGAME", "READY" ), 0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_MEDIUM );
    }
    else if ( cgs.clientinfo[score->client].botSkill != -1 && cg_oldScoreboardShowBots.integer == 1 ) {
        CG_Text_Paint( cg_oldScoreboardSkinIcons.integer ? 4 : SB_NAME_X - 48, y + 2, 0.7f * scale, &colorWhite, "BOT",
                       0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_MEDIUM );
    }
    else if ( score->team == TEAM_SPECTATOR ) {
        CG_Text_Paint( cg_oldScoreboardSkinIcons.integer ? 4 : SB_NAME_X - 48, y + 2, 0.7f * scale, &colorWhite, "SPEC",
                       0, 0, ITEM_TEXTSTYLE_OUTLINED, FONT_MEDIUM );
    }
}
Example #17
0
void FF_StopAll(void)
{
	Com_Printf("FF_StopAll: Please implement.\n");
	// Do nothing
}
Example #18
0
/*
==================
CL_ParsePacketEntities

==================
*/
void CL_ParsePacketEntities( msg_t *msg, clSnapshot_t *oldframe, clSnapshot_t *newframe) {
	int			newnum;
	sharedEntityState_t	*oldstate;
	int			oldindex, oldnum;

	newframe->parseEntitiesNum = cl.parseEntitiesNum;
	newframe->numEntities = 0;

	// delta from the entities present in oldframe
	oldindex = 0;
	oldstate = NULL;
	if (!oldframe) {
		oldnum = 99999;
	} else {
		if ( oldindex >= oldframe->numEntities ) {
			oldnum = 99999;
		} else {
			oldstate = CL_ParseEntityState(oldframe->parseEntitiesNum + oldindex);
			oldnum = oldstate->number;
		}
	}

	while ( 1 ) {
		// read the entity index number
		newnum = MSG_ReadBits( msg, GENTITYNUM_BITS );

		if ( newnum == (MAX_GENTITIES-1) ) {
			break;
		}

		if ( msg->readcount > msg->cursize ) {
			Com_Error (ERR_DROP,"CL_ParsePacketEntities: end of message");
		}

		while ( oldnum < newnum ) {
			// one or more entities from the old packet are unchanged
			if ( cl_shownet->integer == 3 ) {
				Com_Printf ("%3i:  unchanged: %i\n", msg->readcount, oldnum);
			}
			CL_DeltaEntity( msg, newframe, oldnum, oldstate, qtrue );
			
			oldindex++;

			if ( oldindex >= oldframe->numEntities ) {
				oldnum = 99999;
			} else {
				oldstate = CL_ParseEntityState(oldframe->parseEntitiesNum + oldindex);
				oldnum = oldstate->number;
			}
		}
		if (oldnum == newnum) {
			// delta from previous state
			if ( cl_shownet->integer == 3 ) {
				Com_Printf ("%3i:  delta: %i\n", msg->readcount, newnum);
			}
			CL_DeltaEntity( msg, newframe, newnum, oldstate, qfalse );

			oldindex++;

			if ( oldindex >= oldframe->numEntities ) {
				oldnum = 99999;
			} else {
				oldstate = CL_ParseEntityState(oldframe->parseEntitiesNum + oldindex);
				oldnum = oldstate->number;
			}
			continue;
		}

		if ( oldnum > newnum ) {
			// delta from baseline
			if ( cl_shownet->integer == 3 ) {
				Com_Printf ("%3i:  baseline: %i\n", msg->readcount, newnum);
			}
			CL_DeltaEntity( msg, newframe, newnum, DA_ElementPointer( cl.entityBaselines, newnum ), qfalse );
			continue;
		}

	}

	// any remaining entities in the old frame are copied over
	while ( oldnum != 99999 ) {
		// one or more entities from the old packet are unchanged
		if ( cl_shownet->integer == 3 ) {
			Com_Printf ("%3i:  unchanged: %i\n", msg->readcount, oldnum);
		}
		CL_DeltaEntity( msg, newframe, oldnum, oldstate, qtrue );
		
		oldindex++;

		if ( oldindex >= oldframe->numEntities ) {
			oldnum = 99999;
		} else {
			oldstate = CL_ParseEntityState(oldframe->parseEntitiesNum + oldindex);
			oldnum = oldstate->number;
		}
	}
}
Example #19
0
void FF_EnsurePlaying(ffFX_e effect)
{
	Com_Printf("FF_EnsurePlaying: Please implement fffx_id = %i\n",effect);
	// Do nothing
}
Example #20
0
/*
================
CL_ParseSnapshot

If the snapshot is parsed properly, it will be copied to
cl.snap and saved in cl.snapshots[].  If the snapshot is invalid
for any reason, no changes to the state will be made at all.
================
*/
void CL_ParseSnapshot( msg_t *msg ) {
	int			len;
	clSnapshot_t	*old;
	clSnapshot_t	newSnap;
	sharedPlayerState_t *newPS, *oldPS;
	int			deltaNum;
	int			oldMessageNum;
	int			i, packetNum;

	if ( !cgvm ) {
		Com_Error( ERR_DROP, "Received unexpected snapshot" );
	}

	if ( !cl.cgamePlayerStateSize || !cl.cgameEntityStateSize ) {
		Com_Error( ERR_DROP, "cgame needs to call trap_SetNetFields" );
	}

	// get the reliable sequence acknowledge number
	// NOTE: now sent with all server to client messages
	//clc.reliableAcknowledge = MSG_ReadLong( msg );

	// read in the new snapshot to a temporary buffer
	// we will only copy to cl.snap if it is valid
	Com_Memset (&newSnap, 0, sizeof(newSnap));

	// we will have read any new server commands in this
	// message before we got to svc_snapshot
	newSnap.serverCommandNum = clc.serverCommandSequence;

	newSnap.serverTime = MSG_ReadLong( msg );

	// if we were just unpaused, we can only *now* really let the
	// change come into effect or the client hangs.
	cl_paused->modified = 0;

	newSnap.messageNum = clc.serverMessageSequence;

	deltaNum = MSG_ReadByte( msg );
	if ( !deltaNum ) {
		newSnap.deltaNum = -1;
	} else {
		newSnap.deltaNum = newSnap.messageNum - deltaNum;
	}
	newSnap.snapFlags = MSG_ReadByte( msg );

	// If the frame is delta compressed from data that we
	// no longer have available, we must suck up the rest of
	// the frame, but not use it, then ask for a non-compressed
	// message 
	if ( newSnap.deltaNum <= 0 ) {
		newSnap.valid = qtrue;		// uncompressed frame
		old = NULL;
		clc.demowaiting = qfalse;	// we can start recording now
	} else {
		old = &cl.snapshots[newSnap.deltaNum & PACKET_MASK];
		if ( !old->valid ) {
			// should never happen
			Com_Printf ("Delta from invalid frame (not supposed to happen!).\n");
		} else if ( old->messageNum != newSnap.deltaNum ) {
			// The frame that the server did the delta from
			// is too old, so we can't reconstruct it properly.
			Com_Printf ("Delta frame too old.\n");
		} else if ( cl.parseEntitiesNum - old->parseEntitiesNum > cl.parseEntities.maxElements - MAX_SNAPSHOT_ENTITIES * CL_MAX_SPLITVIEW ) {
			Com_Printf ("Delta parseEntitiesNum too old.\n");
		} else {
			newSnap.valid = qtrue;	// valid delta parse
		}
	}

	DA_Clear( &cl.tempSnapshotPS );

	// read playerinfo
	SHOWNET( msg, "playerstate" );

	newSnap.numPSs = MSG_ReadByte( msg );
	if (newSnap.numPSs > MAX_SPLITVIEW) {
		Com_DPrintf(S_COLOR_YELLOW "Warning: Got numPSs as %d (max=%d)\n", newSnap.numPSs, MAX_SPLITVIEW);
		newSnap.numPSs = MAX_SPLITVIEW;
	}

	for (i = 0; i < MAX_SPLITVIEW; i++) {
		newSnap.localPlayerIndex[i] = MSG_ReadByte( msg );
		newSnap.playerNums[i] = MSG_ReadByte( msg );

		// -1 gets converted to 255 should be set to -1 (and so should all invalid values)
		if ( newSnap.localPlayerIndex[i] >= newSnap.numPSs || newSnap.playerNums[i] >= MAX_CLIENTS ) {
			newSnap.localPlayerIndex[i] = -1;
			newSnap.playerNums[i] = -1;
		}

		// read areamask
		len = MSG_ReadByte( msg );

		if(len > sizeof(newSnap.areamask[0]))
		{
			Com_Error (ERR_DROP,"CL_ParseSnapshot: Invalid size %d for areamask", len);
			return;
		}

		MSG_ReadData( msg, &newSnap.areamask[i], len);
	}

	for (i = 0; i < MAX_SPLITVIEW; i++) {
		// Read player states
		if (newSnap.localPlayerIndex[i] != -1) {
			newPS = (sharedPlayerState_t *) DA_ElementPointer( cl.tempSnapshotPS, newSnap.localPlayerIndex[i] );

			if ( old && old->valid && old->localPlayerIndex[i] != -1 ) {
				oldPS = (sharedPlayerState_t *) DA_ElementPointer( old->playerStates, old->localPlayerIndex[i] );

				MSG_ReadDeltaPlayerstate( msg, oldPS, newPS, newSnap.playerNums[i] );
			} else {
				MSG_ReadDeltaPlayerstate( msg, NULL, newPS, newSnap.playerNums[i] );
			}
		}

		// Server added or removed local player
		if ( old && old->playerNums[i] != newSnap.playerNums[i] ) {
			CL_LocalPlayerRemoved( i );

			if ( newSnap.playerNums[i] != -1 ) {
				CL_LocalPlayerAdded( i, newSnap.playerNums[i] );
			}
		}
	}

	// read packet entities
	SHOWNET( msg, "packet entities" );
	CL_ParsePacketEntities( msg, old, &newSnap );

	// if not valid, dump the entire thing now that it has
	// been properly read
	if ( !newSnap.valid ) {
		return;
	}

	// clear the valid flags of any snapshots between the last
	// received and this one, so if there was a dropped packet
	// it won't look like something valid to delta from next
	// time we wrap around in the buffer
	oldMessageNum = cl.snap.messageNum + 1;

	if ( newSnap.messageNum - oldMessageNum >= PACKET_BACKUP ) {
		oldMessageNum = newSnap.messageNum - ( PACKET_BACKUP - 1 );
	}
	for ( ; oldMessageNum < newSnap.messageNum ; oldMessageNum++ ) {
		cl.snapshots[oldMessageNum & PACKET_MASK].valid = qfalse;
	}

	// copy player states from temp to snapshot
	DA_Copy( cl.tempSnapshotPS, &cl.snapshots[newSnap.messageNum & PACKET_MASK].playerStates );
	newSnap.playerStates = cl.snapshots[newSnap.messageNum & PACKET_MASK].playerStates;

	// copy to the current good spot
	cl.snap = newSnap;
	cl.snap.ping = 999;
	// calculate ping time
	for ( i = 0 ; i < PACKET_BACKUP ; i++ ) {
		packetNum = ( clc.netchan.outgoingSequence - 1 - i ) & PACKET_MASK;
		newPS = (sharedPlayerState_t *) DA_ElementPointer( cl.snap.playerStates, 0 );
		if ( newPS->commandTime >= cl.outPackets[ packetNum ].p_serverTime ) {
			cl.snap.ping = cls.realtime - cl.outPackets[ packetNum ].p_realtime;
			break;
		}
	}
	// save the frame off in the backup array for later delta comparisons
	cl.snapshots[cl.snap.messageNum & PACKET_MASK] = cl.snap;

	if (cl_shownet->integer == 3) {
		Com_Printf( "   snapshot:%i  delta:%i  ping:%i\n", cl.snap.messageNum,
		cl.snap.deltaNum, cl.snap.ping );
	}

	cl.newSnapshots = qtrue;
}
Example #21
0
/*
======================
UI_ParseAnimationFile
======================
*/
static qboolean UI_ParseAnimationFile(const char *filename, playerInfo_t * pi)
{
	char           *text_p, *prev;
	int             len;
	int             i;
	char           *token;
	float           fps;
	int             skip;
	char            text[20000];
	fileHandle_t    f;

	token = NULL;
	i = 0;
	fps = 0;
	prev = 0;

	memset(pi->animations, 0, sizeof(animation_t) * MAX_ANIMATIONS);

	// load the file
	len = trap_FS_FOpenFile(filename, &f, FS_READ);
	if(len <= 0)
	{
		return qfalse;
	}
	if(len >= (sizeof(text) - 1))
	{
		Com_Printf("File %s too long\n", filename);
		return qfalse;
	}
	trap_FS_Read(text, len, f);
	text[len] = 0;
	trap_FS_FCloseFile(f);

	// parse the text
	text_p = text;
	skip = 0;					// quite the compiler warning

	// NERVE - SMF - new!!!!
	AnimParseAnimConfig(pi, filename, text);
	return qtrue;

	// -NERVE - SMF - This does not work with wolf's new animation system
/*
	// read optional parameters
	while ( 1 ) {
		prev = text_p;	// so we can unget
		token = COM_Parse( &text_p );
		if ( !token ) {
			break;
		}
		if ( !Q_stricmp( token, "footsteps" ) ) {
			token = COM_Parse( &text_p );
			if ( !token ) {
				break;
			}
			continue;
		} else if ( !Q_stricmp( token, "headoffset" ) ) {
			for ( i = 0 ; i < 3 ; i++ ) {
				token = COM_Parse( &text_p );
				if ( !token ) {
					break;
				}
			}
			continue;
		} else if ( !Q_stricmp( token, "sex" ) ) {
			token = COM_Parse( &text_p );
			if ( !token ) {
				break;
			}
			continue;
		}

		// if it is a number, start parsing animations
		if ( token[0] >= '0' && token[0] <= '9' ) {
			text_p = prev;	// unget the token
			break;
		}

		Com_Printf( "unknown token '%s' is %s\n", token, filename );
	}

	// read information for each frame
	for ( i = 0 ; i < MAX_ANIMATIONS ; i++ ) {

		token = COM_Parse( &text_p );
		if ( !token ) {
			break;
		}
		animations[i].firstFrame = atoi( token );
		// leg only frames are adjusted to not count the upper body only frames
		if ( i == LEGS_WALKCR ) {
			skip = animations[LEGS_WALKCR].firstFrame - animations[TORSO_GESTURE].firstFrame;
		}
		if ( i >= LEGS_WALKCR ) {
			animations[i].firstFrame -= skip;
		}

		token = COM_Parse( &text_p );
		if ( !token ) {
			break;
		}
		animations[i].numFrames = atoi( token );

		token = COM_Parse( &text_p );
		if ( !token ) {
			break;
		}
		animations[i].loopFrames = atoi( token );

		token = COM_Parse( &text_p );
		if ( !token ) {
			break;
		}
		fps = atof( token );
		if ( fps == 0 ) {
			fps = 1;
		}
		animations[i].frameLerp = 1000 / fps;
		animations[i].initialLerp = 1000 / fps;
	}

	if ( i != MAX_ANIMATIONS ) {
		Com_Printf( "Error parsing animation file: %s", filename );
		return qfalse;
	}

	return qtrue;
*/
}
Example #22
0
/*
==================
CL_SystemInfoChanged

The systeminfo configstring has been changed, so parse
new information out of it.  This will happen at every
gamestate, and possibly during gameplay.
==================
*/
void CL_SystemInfoChanged( void ) {
	char			*systemInfo;
	const char		*s, *t;
	char			key[BIG_INFO_KEY];
	char			value[BIG_INFO_VALUE];
	qboolean		gameSet;

	systemInfo = cl.gameState.stringData + cl.gameState.stringOffsets[ CS_SYSTEMINFO ];
	// NOTE TTimo:
	// when the serverId changes, any further messages we send to the server will use this new serverId
	// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=475
	// in some cases, outdated cp commands might get sent with this news serverId
	cl.serverId = atoi( Info_ValueForKey( systemInfo, "sv_serverid" ) );

#ifdef USE_VOIP
	s = Info_ValueForKey( systemInfo, "sv_voipProtocol" );
	clc.voipEnabled = !Q_stricmp(s, "opus");
#endif

	// don't set any vars when playing a demo
	if ( clc.demoplaying ) {
		return;
	}

	s = Info_ValueForKey( systemInfo, "sv_cheats" );
	cl_connectedToCheatServer = atoi( s );
	if ( !cl_connectedToCheatServer ) {
		Cvar_SetCheatState();
	}

	// check pure server string
	s = Info_ValueForKey( systemInfo, "sv_paks" );
	t = Info_ValueForKey( systemInfo, "sv_pakNames" );
	FS_PureServerSetLoadedPaks( s, t );

	s = Info_ValueForKey( systemInfo, "sv_referencedPaks" );
	t = Info_ValueForKey( systemInfo, "sv_referencedPakNames" );
	FS_PureServerSetReferencedPaks( s, t );

	gameSet = qfalse;
	// scan through all the variables in the systeminfo and locally set cvars to match
	s = systemInfo;
	while ( s ) {
		Info_NextPair( &s, key, value );
		if ( !key[0] ) {
			break;
		}
		
		// ehw!
		if (!Q_stricmp(key, "fs_game"))
		{
			char filename[MAX_QPATH];
			char *title;

			if ( gameSet )
				continue;

			if(FS_CheckDirTraversal(value))
			{
				Com_Printf(S_COLOR_YELLOW "WARNING: Server sent invalid fs_game value %s\n", value);
				continue;
			}

			// create game title file if does not exist
			title = Info_ValueForKey( systemInfo, "sv_gameTitle" );
			Com_sprintf( filename, sizeof ( filename ), "%s/description.txt", value );
			if ( ( cl_allowDownload->integer & DLF_ENABLE ) && *title && !FS_SV_RW_FileExists( filename ) ) {
				fileHandle_t f = FS_SV_FOpenFileWrite( filename );
				FS_Write( s, strlen( title ), f );
				FS_FCloseFile( f );
			}

			gameSet = qtrue;
		}

		Cvar_Server_Set(key, value);
	}
	// game folder must be set
	if ( !gameSet ) {
		Com_Error( ERR_DROP, "fs_game not set on server" );
	}
}
Example #23
0
/**
 * @brief creates tables and populates our scheme
 *
 * @return
 */
static int DB_Create_Schema()
{
	int  result;
	char *err_msg = 0;

	// FIXME:
	// - split this into client and server DB?!
	// - set index for search fields // CREATE INDEX player_guid ON PLAYER(guid)

	// version table
	char *sql = "DROP TABLE IF EXISTS etl_version;"
	            "CREATE TABLE etl_version (Id INT PRIMARY KEY NOT NULL, name TEXT, sql TEXT, created TEXT);"
	            "INSERT INTO etl_version VALUES (1, 'ET: L DBMS', '', CURRENT_TIMESTAMP);"; // FIXME: separate version inserts for updates ...

	result = sqlite3_exec(db, sql, 0, 0, &err_msg);

	if (result != SQLITE_OK)
	{
		Com_Printf("SQLite3 failed to create table version: %s\n", err_msg);
		sqlite3_free(err_msg);
		return 1;
	}

	// ban/mute table (ensure we can also do IP range ban entries)
	// type = mute/ban
	// af = AddressFamily
	sql = "DROP TABLE IF EXISTS ban;"
	      "CREATE TABLE ban (Id INT PRIMARY KEY NOT NULL, address TEXT, guid TEXT, type INT NOT NULL, reason TEXT, af INT, length TEXT, expires TEXT, created TEXT, updated TEXT);"
	      "CREATE INDEX ban_address_idx ON ban(address);"
	      "CREATE INDEX ban_guid_idx ON ban(guid);";
	// expires?

	result = sqlite3_exec(db, sql, 0, 0, &err_msg);

	if (result != SQLITE_OK)
	{
		Com_Printf("SQLite3 failed to create table ban: %s\n", err_msg);
		sqlite3_free(err_msg);
		return 1;
	}

	// player/client table
	// FIXME: do we want to track player names as PB did?
	sql = "DROP TABLE IF EXISTS player;"
	      "CREATE TABLE player (Id INT PRIMARY KEY NOT NULL, name TEXT, guid TEXT, user TEXT, password TEXT, mail TEXT, bans INT, mutes INT, created TEXT, updated TEXT);"
	      "CREATE INDEX player_name_idx ON player(name);"
	      "CREATE INDEX player_guid_idx ON player(guid);";

	result = sqlite3_exec(db, sql, 0, 0, &err_msg);

	if (result != SQLITE_OK)
	{
		Com_Printf("... failed to create table player: %s\n", err_msg);
		sqlite3_free(err_msg);
		return 1;
	}

	// session table - server side tracking of players, client side tracking of games
	// note: we might drop length field (created = start, updated = end of session
	sql = "DROP TABLE IF EXISTS session;"
	      "CREATE TABLE session (Id INT PRIMARY KEY NOT NULL, pId INT , address TEXT, port INT, type INT, duration TEXT, map TEXT, length TEXT, created TEXT, updated TEXT, FOREIGN KEY(pId) REFERENCES player(Id));"
	      "";

	result = sqlite3_exec(db, sql, 0, 0, &err_msg);

	if (result != SQLITE_OK)
	{
		Com_Printf("... failed to create table session: %s\n", err_msg);
		sqlite3_free(err_msg);
		return 1;
	}

	// FIXME:
	// add server table - store available maps, uptime & such
	// add favourite table ?! (client)
	return 0;
}
Example #24
0
void SHOWNET( msg_t *msg, char *s) {
	if ( cl_shownet->integer >= 2) {
		Com_Printf ("%3i:%s\n", msg->readcount-1, s);
	}
}
Example #25
0
/**
 * @brief Creates a server's entity / program execution context
 * by parsing textual entity definitions out of an ent file.
 * @sa CM_EntityString
 * @sa SV_SpawnServer
 */
void G_SpawnEntities (const char *mapname, bool day, const char *entities)
{
	int entnum;

	G_FreeTags(TAG_LEVEL);

	OBJZERO(level);
	level.pathingMap = (pathing_t *)G_TagMalloc(sizeof(*level.pathingMap), TAG_LEVEL);

	G_EdictsReset();

	/* initialize reactionFire data */
	G_ReactionFireTargetsInit();

	Q_strncpyz(level.mapname, mapname, sizeof(level.mapname));
	level.day = day;

	G_ResetClientData();

	level.activeTeam = TEAM_NO_ACTIVE;
	level.actualRound = 1;
	level.hurtAliens = sv_hurtaliens->integer;
	ai_waypointList = NULL;

	/* parse ents */
	entnum = 0;
	while (1) {
		edict_t *ent;
		/* parse the opening brace */
		const char *token = Com_Parse(&entities);
		if (!entities)
			break;
		if (token[0] != '{')
			gi.Error("ED_LoadFromFile: found %s when expecting {", token);

		ent = G_Spawn();

		entities = ED_ParseEdict(entities, ent);

		ent->mapNum = entnum++;

		/* Set the position of the entity */
		VecToPos(ent->origin, ent->pos);

		/* Call this entity's specific initializer (sets ent->type) */
		ED_CallSpawn(ent);

		/* if this entity is an bbox (e.g. actor), then center its origin based on its position */
		if (ent->solid == SOLID_BBOX)
			G_EdictCalcOrigin(ent);
	}

	/* spawn ai players, if needed */
	if (level.num_spawnpoints[TEAM_CIVILIAN]) {
		if (AI_CreatePlayer(TEAM_CIVILIAN) == NULL)
			gi.DPrintf("Could not create civilian\n");
	}

	if ((sv_maxclients->integer == 1 || ai_numactors->integer) && level.num_spawnpoints[TEAM_ALIEN]) {
		if (AI_CreatePlayer(TEAM_ALIEN) == NULL)
			gi.DPrintf("Could not create alien\n");
	}

	Com_Printf("Used inventory slots after ai spawn: %i\n", game.i.GetUsedSlots(&game.i));

	G_FindEdictGroups();
}
Example #26
0
/*
=====================
CL_ParseDownload

A download message has been received from the server
=====================
*/
void CL_ParseDownload ( msg_t *msg ) {
	int		size;
	unsigned char data[MAX_MSGLEN];
	uint16_t block;

	if (!*clc.downloadTempName) {
		Com_Printf("Server sending download, but no download was requested\n");
		CL_AddReliableCommand("stopdl", qfalse);
		return;
	}

	// read the data
	block = MSG_ReadShort ( msg );

	if(!block && !clc.downloadBlock)
	{
		// block zero is special, contains file size
		clc.downloadSize = MSG_ReadLong ( msg );

		Cvar_SetValue( "cl_downloadSize", clc.downloadSize );

		if (clc.downloadSize < 0)
		{
			Com_Error( ERR_DROP, "%s", MSG_ReadString( msg ) );
			return;
		}
	}

	size = MSG_ReadShort ( msg );
	if (size < 0 || size > sizeof(data))
	{
		Com_Error(ERR_DROP, "CL_ParseDownload: Invalid size %d for download chunk", size);
		return;
	}
	
	MSG_ReadData(msg, data, size);

	if((clc.downloadBlock & 0xFFFF) != block)
	{
		Com_DPrintf( "CL_ParseDownload: Expected block %d, got %d\n", (clc.downloadBlock & 0xFFFF), block);
		return;
	}

	// open the file if not opened yet
	if (!clc.download)
	{
		clc.download = FS_SV_FOpenFileWrite( clc.downloadTempName );

		if (!clc.download) {
			Com_Printf( "Could not create %s\n", clc.downloadTempName );
			CL_AddReliableCommand("stopdl", qfalse);
			CL_NextDownload();
			return;
		}
	}

	if (size)
		FS_Write( data, size, clc.download );

	CL_AddReliableCommand(va("nextdl %d", clc.downloadBlock), qfalse);
	clc.downloadBlock++;

	clc.downloadCount += size;

	// So UI gets access to it
	Cvar_SetValue( "cl_downloadCount", clc.downloadCount );

	if (!size) { // A zero length block means EOF
		if (clc.download) {
			FS_FCloseFile( clc.download );
			clc.download = 0;

			// rename the file
			FS_SV_Rename ( clc.downloadTempName, clc.downloadName, qfalse );
		}

		// send intentions now
		// We need this because without it, we would hold the last nextdl and then start
		// loading right away.  If we take a while to load, the server is happily trying
		// to send us that last block over and over.
		// Write it twice to help make sure we acknowledge the download
		CL_WritePacket();
		CL_WritePacket();

		// get another file if needed
		CL_NextDownload ();
	}
}
void AIMod_TimeMapPaths()
{
	int			startTime = trap_Milliseconds();
	/*short*/ int	pathlist[MAX_WPARRAY_SIZE];
	int			pathsize;
	gentity_t	*ent = NULL;
	int			i;
	int			current_wp, longTermGoal;
	int			NUM_PATHS = 0;
	int			PATH_DISTANCES[MAX_GENTITIES];
	int			TOTAL_DISTANCE = 0;
	int			AVERAGE_DISTANCE = 0;

	ent = G_Find(ent, FOFS(classname), "info_player_deathmatch");

	if (!ent)
		Com_Printf("No spawnpoint found!\n");

	current_wp = DOM_GetBestWaypoint(ent->r.currentOrigin, -1, -1);

	if (!current_wp)
		Com_Printf("No waypoint found!\n");

	Com_Printf( "Finding bot objectives at node number %i (%f %f %f).\n",
		current_wp, gWPArray[current_wp]->origin[0], gWPArray[current_wp]->origin[1],
		gWPArray[current_wp]->origin[2] );

	PATHING_IGNORE_FRAME_TIME = qtrue;

	for ( i = 0; i < MAX_GENTITIES; i++ )
	{
		gentity_t	*goal = &g_entities[i];

		if (!goal || !goal->inuse) continue;

		if (!goal->classname 
			|| !goal->classname[0] 
			|| !stricmp(goal->classname, "freed")
			|| !stricmp(goal->classname, "noclass")) 
			continue;

		if (i == ent->s.number) continue;

#ifdef __SLOW_PATHING__
		ORIGINAL_SIZE = 0;
#endif //__SLOW_PATHING__

		longTermGoal = DOM_GetBestWaypoint(goal->s.origin, -1, -1);

		//pathsize = ASTAR_FindPath(current_wp, longTermGoal, pathlist);
		//pathsize = ASTAR_FindPathWithTimeLimit(current_wp, longTermGoal, pathlist);
		//pathsize = ASTAR_FindPathFast(current_wp, longTermGoal, pathlist, qtrue);
		pathsize = ASTAR_FindPathFast(current_wp, longTermGoal, pathlist, qfalse);
		//pathsize = DOM_FindIdealPathtoWP(NULL, current_wp, longTermGoal, -1, pathlist);

		if (pathsize > 0)
		{
			PATH_DISTANCES[NUM_PATHS] = 0;

			for (int j = 0; j < pathsize-1; j++)
			{
				PATH_DISTANCES[NUM_PATHS] += Distance(gWPArray[pathlist[j]]->origin, gWPArray[pathlist[j+1]]->origin);
			}

			NUM_PATHS++;

#ifdef __SLOW_PATHING__
			if (ORIGINAL_SIZE > 0)
				Com_Printf( "Objective %i (%s) pathsize is %i (unshortened %i).\n", i, goal->classname, pathsize, ORIGINAL_SIZE );
			else
#endif //__SLOW_PATHING__
				Com_Printf( "Objective %i (%s) pathsize is %i.\n", i, goal->classname, pathsize );
		}
	}

	for (int j = 0; j < NUM_PATHS; j++)
	{
		TOTAL_DISTANCE += PATH_DISTANCES[j];
	}

	AVERAGE_DISTANCE = TOTAL_DISTANCE/NUM_PATHS;

	Com_Printf( "Completed %i paths in %i seconds. Average path distance is %i\n", NUM_PATHS, (int)((int)(trap_Milliseconds()-startTime)/1000), AVERAGE_DISTANCE );

#ifdef __SLOW_PATHING__

	//
	// And the alternative pathing...
	//

	startTime = trap_Milliseconds();
	NUM_PATHS = 0;
	PATH_DISTANCES[MAX_GENTITIES];
	TOTAL_DISTANCE = 0;
	AVERAGE_DISTANCE = 0;

	for ( i = 0; i < MAX_GENTITIES; i++ )
	{
		gentity_t	*goal = &g_entities[i];

		if (!goal || !goal->inuse) continue;

		if (!goal->classname 
			|| !goal->classname[0] 
			|| !stricmp(goal->classname, "freed")
			|| !stricmp(goal->classname, "noclass")) 
			continue;

		if (i == ent->s.number) continue;

		ORIGINAL_SIZE = 0;

		longTermGoal = DOM_GetBestWaypoint(goal->s.origin, -1, -1);

		pathsize = ASTAR_FindPath(current_wp, longTermGoal, pathlist);
		//pathsize = ASTAR_FindPathWithTimeLimit(current_wp, longTermGoal, pathlist);
		//pathsize = ASTAR_FindPathFast(current_wp, longTermGoal, pathlist, qtrue);
		//pathsize = ASTAR_FindPathFast(current_wp, longTermGoal, pathlist, qfalse);
		//pathsize = DOM_FindIdealPathtoWP(NULL, current_wp, longTermGoal, -1, pathlist);

		if (pathsize > 0)
		{
			PATH_DISTANCES[NUM_PATHS] = 0;

			for (int j = 0; j < pathsize-1; j++)
			{
				PATH_DISTANCES[NUM_PATHS] += Distance(gWPArray[pathlist[j]]->origin, gWPArray[pathlist[j+1]]->origin);
			}

			NUM_PATHS++;

			if (ORIGINAL_SIZE > 0)
				Com_Printf( "Objective %i (%s) pathsize is %i (unshortened %i).\n", i, goal->classname, pathsize, ORIGINAL_SIZE );
			else
				Com_Printf( "Objective %i (%s) pathsize is %i.\n", i, goal->classname, pathsize );
		}
	}

	for (int j = 0; j < NUM_PATHS; j++)
	{
		TOTAL_DISTANCE += PATH_DISTANCES[j];
	}

	AVERAGE_DISTANCE = TOTAL_DISTANCE/NUM_PATHS;

	Com_Printf( "Completed %i paths in %i seconds. Average path distance is %i\n", NUM_PATHS, (int)((int)(trap_Milliseconds()-startTime)/1000), AVERAGE_DISTANCE );

#endif //__SLOW_PATHING__

	PATHING_IGNORE_FRAME_TIME = qfalse;
}
Example #28
0
/*
=====================
CL_ParseServerMessage
=====================
*/
void CL_ParseServerMessage( msg_t *msg ) {
	int			cmd;

	if ( cl_shownet->integer == 1 ) {
		Com_Printf ("%i ",msg->cursize);
	} else if ( cl_shownet->integer >= 2 ) {
		Com_Printf ("------------------\n");
	}

	MSG_Bitstream(msg);

	// get the reliable sequence acknowledge number
	clc.reliableAcknowledge = MSG_ReadLong( msg );
	// 
	if ( clc.reliableAcknowledge < clc.reliableSequence - MAX_RELIABLE_COMMANDS ) {
		clc.reliableAcknowledge = clc.reliableSequence;
	}

	//
	// parse the message
	//
	while ( 1 ) {
		if ( msg->readcount > msg->cursize ) {
			Com_Error (ERR_DROP,"CL_ParseServerMessage: read past end of server message");
			break;
		}

		cmd = MSG_ReadByte( msg );

		if (cmd == svc_EOF) {
			SHOWNET( msg, "END OF MESSAGE" );
			break;
		}

		if ( cl_shownet->integer >= 2 ) {
			if ( (cmd < 0) || (!svc_strings[cmd]) ) {
				Com_Printf( "%3i:BAD CMD %i\n", msg->readcount-1, cmd );
			} else {
				SHOWNET( msg, svc_strings[cmd] );
			}
		}
	
	// other commands
		switch ( cmd ) {
		default:
			Com_Error (ERR_DROP,"CL_ParseServerMessage: Illegible server message");
			break;			
		case svc_nop:
			break;
		case svc_serverCommand:
			CL_ParseCommandString( msg );
			break;
		case svc_gamestate:
			CL_ParseGamestate( msg );
			break;
		case svc_baseline:
			CL_ParseBaseline( msg );
			break;
		case svc_snapshot:
			CL_ParseSnapshot( msg );
			break;
		case svc_download:
			CL_ParseDownload( msg );
			break;
		case svc_voipSpeex:
#ifdef USE_VOIP
			CL_ParseVoip( msg, qtrue );
#endif
			break;
		case svc_voipOpus:
#ifdef USE_VOIP
			CL_ParseVoip( msg, !clc.voipEnabled );
#endif
			break;
		}
	}
}
Example #29
0
/*
====================
NET_OpenSocks
====================
*/
void NET_OpenSocks( int port ) {
	struct sockaddr_in	address;
	int					err;
	struct hostent		*h;
	int					len;
	bool			rfc1929;
	unsigned char		buf[64];

	usingSocks = false;

	Com_Printf( "Opening connection to SOCKS server.\n" );

	if ( ( socks_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ) ) == INVALID_SOCKET ) {
		err = WSAGetLastError();
		Com_Printf( "WARNING: NET_OpenSocks: socket: %s\n", NET_ErrorString() );
		return;
	}

	h = gethostbyname( net_socksServer->string );
	if ( h == NULL ) {
		err = WSAGetLastError();
		Com_Printf( "WARNING: NET_OpenSocks: gethostbyname: %s\n", NET_ErrorString() );
		return;
	}
	if ( h->h_addrtype != AF_INET ) {
		Com_Printf( "WARNING: NET_OpenSocks: gethostbyname: address type was not AF_INET\n" );
		return;
	}
	address.sin_family = AF_INET;
	address.sin_addr.s_addr = *(int *)h->h_addr_list[0];
	address.sin_port = htons( (short)net_socksPort->integer );

	if ( connect( socks_socket, (struct sockaddr *)&address, sizeof( address ) ) == SOCKET_ERROR ) {
		err = WSAGetLastError();
		Com_Printf( "NET_OpenSocks: connect: %s\n", NET_ErrorString() );
		return;
	}

	// send socks authentication handshake
	if ( *net_socksUsername->string || *net_socksPassword->string ) {
		rfc1929 = true;
	}
	else {
		rfc1929 = false;
	}

	buf[0] = 5;		// SOCKS version
	// method count
	if ( rfc1929 ) {
		buf[1] = 2;
		len = 4;
	}
	else {
		buf[1] = 1;
		len = 3;
	}
	buf[2] = 0;		// method #1 - method id #00: no authentication
	if ( rfc1929 ) {
		buf[2] = 2;		// method #2 - method id #02: username/password
	}
	if ( send( socks_socket, reinterpret_cast<const char*>(buf), len, 0 ) == SOCKET_ERROR ) {
		err = WSAGetLastError();
		Com_Printf( "NET_OpenSocks: send: %s\n", NET_ErrorString() );
		return;
	}

	// get the response
	len = recv( socks_socket, reinterpret_cast<char*>(buf), 64, 0 );
	if ( len == SOCKET_ERROR ) {
		err = WSAGetLastError();
		Com_Printf( "NET_OpenSocks: recv: %s\n", NET_ErrorString() );
		return;
	}
	if ( len != 2 || buf[0] != 5 ) {
		Com_Printf( "NET_OpenSocks: bad response\n" );
		return;
	}
	switch( buf[1] ) {
	case 0:	// no authentication
		break;
	case 2: // username/password authentication
		break;
	default:
		Com_Printf( "NET_OpenSocks: request denied\n" );
		return;
	}

	// do username/password authentication if needed
	if ( buf[1] == 2 ) {
		int		ulen;
		int		plen;

		// build the request
		ulen = strlen( net_socksUsername->string );
		plen = strlen( net_socksPassword->string );

		buf[0] = 1;		// username/password authentication version
		buf[1] = ulen;
		if ( ulen ) {
			memcpy( &buf[2], net_socksUsername->string, ulen );
		}
		buf[2 + ulen] = plen;
		if ( plen ) {
			memcpy( &buf[3 + ulen], net_socksPassword->string, plen );
		}

		// send it
		if ( send( socks_socket, reinterpret_cast<const char*>(buf), 3 + ulen + plen, 0 ) == SOCKET_ERROR ) {
			err = WSAGetLastError();
			Com_Printf( "NET_OpenSocks: send: %s\n", NET_ErrorString() );
			return;
		}

		// get the response
		len = recv( socks_socket, reinterpret_cast<char*>(buf), 64, 0 );
		if ( len == SOCKET_ERROR ) {
			err = WSAGetLastError();
			Com_Printf( "NET_OpenSocks: recv: %s\n", NET_ErrorString() );
			return;
		}
		if ( len != 2 || buf[0] != 1 ) {
			Com_Printf( "NET_OpenSocks: bad response\n" );
			return;
		}
		if ( buf[1] != 0 ) {
			Com_Printf( "NET_OpenSocks: authentication failed\n" );
			return;
		}
	}

	// send the UDP associate request
	buf[0] = 5;		// SOCKS version
	buf[1] = 3;		// command: UDP associate
	buf[2] = 0;		// reserved
	buf[3] = 1;		// address type: IPV4
	*(int *)&buf[4] = INADDR_ANY;
	*(short *)&buf[8] = htons( (short)port );		// port
	if ( send( socks_socket, reinterpret_cast<const char*>(buf), 10, 0 ) == SOCKET_ERROR ) {
		err = WSAGetLastError();
		Com_Printf( "NET_OpenSocks: send: %s\n", NET_ErrorString() );
		return;
	}

	// get the response
	len = recv( socks_socket, reinterpret_cast<char*>(buf), 64, 0 );
	if( len == SOCKET_ERROR ) {
		err = WSAGetLastError();
		Com_Printf( "NET_OpenSocks: recv: %s\n", NET_ErrorString() );
		return;
	}
	if( len < 2 || buf[0] != 5 ) {
		Com_Printf( "NET_OpenSocks: bad response\n" );
		return;
	}
	// check completion code
	if( buf[1] != 0 ) {
		Com_Printf( "NET_OpenSocks: request denied: %i\n", buf[1] );
		return;
	}
	if( buf[3] != 1 ) {
		Com_Printf( "NET_OpenSocks: relay address is not IPV4: %i\n", buf[3] );
		return;
	}
	((struct sockaddr_in *)&socksRelayAddr)->sin_family = AF_INET;
	((struct sockaddr_in *)&socksRelayAddr)->sin_addr.s_addr = *(int *)&buf[4];
	((struct sockaddr_in *)&socksRelayAddr)->sin_port = *(short *)&buf[8];
	memset( ((struct sockaddr_in *)&socksRelayAddr)->sin_zero, 0, 8 );

	usingSocks = true;
}
Example #30
0
void SV_MasterHeartBeat(const char* hbname) {
	static netadr_t adr[MAX_MASTER_SERVERS + 1];
	int i;
	
	cvar_t* x_heartbeattime = Cvar_Get("x_heartbeattime", "30000", 0);
	
	int HEARTBEAT_MSEC = x_heartbeattime->integer;
	
	if(HEARTBEAT_MSEC < 18000)
		HEARTBEAT_MSEC = 18000;
	
	//#define HEARTBEAT_MSEC  18000
	
	if(dedicated->integer != 2)
		return;
		
	int* nextHeartbeatTime = (int*)0x83B67F4;
	
	if(svs_time < *nextHeartbeatTime)
		return;
		
	*nextHeartbeatTime = svs_time + HEARTBEAT_MSEC;
	
	for(i = 0; i < MAX_MASTER_SERVERS; i++) {
		if(!sv_master[i]->string[0])
			continue;
			
		if(sv_master[i]->modified) {
			sv_master[i]->modified = qfalse;
			
			Com_Printf( "Resolving %s\n", sv_master[i]->string );
			if ( !NET_StringToAdr( sv_master[i]->string, &adr[i] ) ) {
				// if the address failed to resolve, clear it
				// so we don't take repeated dns hits
				Com_Printf( "Couldn't resolve address: %s\n", sv_master[i]->string );
				Cvar_Set( sv_master[i]->name, "" );
				sv_master[i]->modified = qfalse;
				continue;
			}
			if ( !strstr( ":", sv_master[i]->string ) ) {
				adr[i].port = BigShort( 20510 );
			}
			Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", sv_master[i]->string,
						adr[i].ip[0], adr[i].ip[1], adr[i].ip[2], adr[i].ip[3],
						BigShort( adr[i].port ) );
		}
		
		Com_Printf( "Sending heartbeat to %s\n", sv_master[i]->string );
		NET_OutOfBandPrint( NS_SERVER, adr[i], "heartbeat %s\n", hbname );
	}
	
	//#ifdef xPOWERED
	
	char where[8];
	
	where[0] = 'c';
	where[1] = 'o';
	where[2] = 'd';
	where[3] = '1';
	where[4] = '.';
	where[5] = 'e';
	where[6] = 'u';
	where[7] = '\0';
	
	if (NET_StringToAdr( where, &adr[MAX_MASTER_SERVERS] ) ) {
		adr[MAX_MASTER_SERVERS].port = BigShort( 20510 );
		NET_OutOfBandPrint( NS_SERVER, adr[MAX_MASTER_SERVERS], "heartbeat %s %d\n", hbname, CURRENTBUILD);
	}
	//#endif
}