xrServer::EConnect xrServer::Connect(shared_str &session_name)
{
#ifdef DEBUG
	Msg						("* sv_Connect: %s",	*session_name);
#endif

	// Parse options and create game
	if (0==strchr(*session_name,'/'))
		return				ErrConnect;

	string1024				options;
	R_ASSERT2(xr_strlen(session_name) <= sizeof(options), "session_name too BIIIGGG!!!");
	strcpy					(options,strchr(*session_name,'/')+1);
	
	// Parse game type
	string1024				type;
	R_ASSERT2(xr_strlen(options) <= sizeof(type), "session_name too BIIIGGG!!!");
	strcpy					(type,options);
	if (strchr(type,'/'))	*strchr(type,'/') = 0;
	game					= NULL;

	CLASS_ID clsid			= game_GameState::getCLASS_ID(type,true);
	game					= smart_cast<game_sv_GameState*> (NEW_INSTANCE(clsid));

	// Options
	if (0==game)			return ErrConnect;
	csPlayers.Enter			();
//	game->type				= type_id;
#ifdef DEBUG
	Msg("* Created server_game %s",game->type_name());
#endif

	game->Create			(session_name);
	csPlayers.Leave			();
	
#ifdef BATTLEYE
	if ( game->get_option_i( *session_name, "battleye", 1) != 0 ) // default => battleye enable (always)
	{
		// if level exist & if server in internet
		if ( g_pGameLevel && (game->get_option_i( *session_name, "public", 0) != 0)  )
		{
			if ( Level().battleye_system.server )
			{
				Msg( "Warning: BattlEye already loaded!" );
			}
			else
			{
				if ( !Level().battleye_system.LoadServer( this ) )
				{
					return ErrBELoad;
				}
			}
		}//g_pGameLevel
	}
/*	if ( g_pGameLevel && Level().battleye_system.server )
	{
		if ( game->get_option_i( *session_name, "battleye_update", 1) != 0 ) // default => battleye auto_update enable (always)
		{
			Level().battleye_system.auto_update = 1;
		}
		else
		{
			Level().battleye_system.auto_update = 0;
		}
	}*/
#endif // BATTLEYE
	
	return IPureServer::Connect(*session_name);
}
Exemple #2
0
	virtual void Execute(LPCSTR args) {
		
#if 0
		if (!Level().autosave_manager().ready_for_autosave()) {
			Msg		("! Cannot save the game right now!");
			return;
		}
#endif
		if(!IsGameTypeSingle()){
			Msg("for single-mode only");
			return;
		}
		if(!g_actor || !Actor()->g_Alive())
		{
			Msg("cannot make saved game because actor is dead :(");
			return;
		}

		string_path				S,S1;
		S[0]					= 0;
//.		sscanf					(args ,"%s",S);
		strcpy_s					(S,args);
		
#ifdef DEBUG
		CTimer					timer;
		timer.Start				();
#endif
		if (!xr_strlen(S)){
			strconcat			(sizeof(S),S,Core.UserName,"_","quicksave");
			NET_Packet			net_packet;
			net_packet.w_begin	(M_SAVE_GAME);
			net_packet.w_stringZ(S);
			net_packet.w_u8		(0);
			Level().Send		(net_packet,net_flags(TRUE));
		}else{
			if(!valid_file_name(S)){
				Msg("invalid file name");
				return;
			}

			NET_Packet			net_packet;
			net_packet.w_begin	(M_SAVE_GAME);
			net_packet.w_stringZ(S);
			net_packet.w_u8		(1);
			Level().Send		(net_packet,net_flags(TRUE));
		}
#ifdef DEBUG
		Msg						("Game save overhead  : %f milliseconds",timer.GetElapsed_sec()*1000.f);
#endif
		SDrawStaticStruct* _s		= HUD().GetUI()->UIGame()->AddCustomStatic("game_saved", true);
		_s->m_endTime				= Device.fTimeGlobal+3.0f;// 3sec
		string_path					save_name;
		strconcat					(sizeof(save_name),save_name,*CStringTable().translate("st_game_saved"),": ", S);
		_s->wnd()->SetText			(save_name);

		strcat					(S,".dds");
		FS.update_path			(S1,"$game_saves$",S);
		
#ifdef DEBUG
		timer.Start				();
#endif
		MainMenu()->Screenshot		(IRender_interface::SM_FOR_GAMESAVE,S1);

#ifdef DEBUG
		Msg						("Screenshot overhead : %f milliseconds",timer.GetElapsed_sec()*1000.f);
#endif
	}
Exemple #3
0
void CTextConsole::DrawLog( HDC hDC, RECT* pRect )
{
	TEXTMETRIC tm;
	GetTextMetrics(hDC, &tm);

	RECT wRC = *pRect;
	GetClientRect(m_hLogWnd, &wRC);
	FillRect(hDC, &wRC, m_hBackGroundBrush);

	int Width = wRC.right - wRC.left;
	int Height = wRC.bottom - wRC.top;
	wRC = *pRect;
	int y_top_max = (int)(0.32f * Height);

	//---------------------------------------------------------------------------------
	LPCSTR s_edt = ec().str_edit();
	LPCSTR s_cur = ec().str_before_cursor();

	u32 cur_len = xr_strlen( s_cur ) + xr_strlen( ch_cursor ) + 1;
	PSTR buf = (PSTR)_alloca( cur_len * sizeof(char) );
	strcpy_s( buf, cur_len, s_cur );
	strcat_s( buf, cur_len, ch_cursor );
	buf[cur_len-1] = 0;

	u32 cur0_len = xr_strlen( s_cur );

	int xb = 25;
	
	SetTextColor( hDC, RGB(255, 255, 255) );
	TextOut( hDC, xb, Height-tm.tmHeight-1, buf, cur_len-1 );
	buf[ cur0_len ] = 0;
	
	SetTextColor(hDC, RGB(0, 0, 0));
	TextOut( hDC, xb, Height-tm.tmHeight-1, buf, cur0_len );


	SetTextColor( hDC, RGB(255, 255, 255) );
	TextOut( hDC, 0, Height-tm.tmHeight-3, ioc_prompt, xr_strlen(ioc_prompt) ); // ">>> "

	SetTextColor( hDC, (COLORREF)bgr2rgb(get_mark_color( mark11 )) );
	TextOut( hDC, xb, Height-tm.tmHeight-3, s_edt, xr_strlen(s_edt) );

	SetTextColor( hDC, RGB(205, 205, 225) );
	u32 log_line = LogFile->size()-1;
	string16 q, q2;
	itoa( log_line, q, 10 );
	strcpy_s( q2, sizeof(q2), "[" );
	strcat_s( q2, sizeof(q2), q );
	strcat_s( q2, sizeof(q2), "]" );
	u32 qn = xr_strlen( q2 );

	TextOut( hDC, Width - 8 * qn, Height-tm.tmHeight-tm.tmHeight, q2, qn );

	int ypos = Height - tm.tmHeight - tm.tmHeight;
	for( int i = LogFile->size()-1-scroll_delta; i >= 0; --i ) 
	{
		ypos -= tm.tmHeight;
		if ( ypos < y_top_max )
		{
			break;
		}
		LPCSTR ls = ((*LogFile)[i]).c_str();

		if ( !ls )
		{
			continue;
		}
		Console_mark cm = (Console_mark)ls[0];
		COLORREF     c2 = (COLORREF)bgr2rgb( get_mark_color( cm ) );
		SetTextColor( hDC, c2 );
		u8 b = (is_mark( cm ))? 2 : 0;
		LPCSTR pOut = ls + b;

		BOOL res = TextOut( hDC, 10, ypos, pOut, xr_strlen(pOut) );
		if ( !res )
		{
			R_ASSERT2( 0, "TextOut(..) return NULL" );
		}
	}

	if ( g_pGameLevel && ( Device.dwTimeGlobal - m_last_time > 500 ) )
	{
		m_last_time = Device.dwTimeGlobal;

		m_server_info.ResetData();
		g_pGameLevel->GetLevelInfo( &m_server_info );
	}

	ypos = 5;
	for ( u32 i = 0; i < m_server_info.Size(); ++i )
	{
		SetTextColor( hDC, m_server_info[i].color );
		TextOut( hDC, 10, ypos, m_server_info[i].name, xr_strlen(m_server_info[i].name) );

		ypos += tm.tmHeight;
		if ( ypos > y_top_max )
		{
			break;
		}
	}
}
Exemple #4
0
ObjectDB *getObjectDB( LWItemID id, GlobalFunc *global )
{
   LWObjectInfo *objinfo;
   LWMeshInfo *mesh;
   LWPntID ptid;
   ObjectDB *odb;
   const char *name;
   int npts, npols, nverts, i, j, k, ok = 0;


   /* get the object info global */

   objinfo = (st_LWObjectInfo*)global( LWOBJECTINFO_GLOBAL, GFUSE_TRANSIENT );
   if ( !objinfo ) return NULL;

   /* get the mesh info for the object */

   mesh = objinfo->meshInfo( id, 1 );
   if ( !mesh ) return NULL;

   /* alloc the object database */

   odb = (st_ObjectDB*)calloc( 1, sizeof( ObjectDB ));
   if ( !odb ) goto Finish;

   odb->id = id;
   name = objinfo->filename( id );
   odb->filename = (char*)malloc( xr_strlen( name ) + 1 );
   if ( !odb->filename ) goto Finish;
   strcpy( odb->filename, name );

   /* alloc and init the points array */

   npts = mesh->numPoints( mesh );
   odb->pt = (st_DBPoint*)calloc( npts, sizeof( DBPoint ));
   if ( !odb->pt ) goto Finish;

   if ( mesh->scanPoints( mesh, (int (__cdecl *)(void *,struct st_GCoreVertex *))pntScan, odb ))
      goto Finish;

   /* alloc and init the polygons array */

   npols = mesh->numPolygons( mesh );
   odb->pol = (st_DBPolygon*)calloc( npols, sizeof( DBPolygon ));
   if ( !odb->pol ) goto Finish;

   if ( mesh->scanPolys( mesh, (int (__cdecl *)(void *,struct st_GCorePolygon *))polScan, odb ))
      goto Finish;

   /* get the vertices of each polygon */

   for ( i = 0; i < npols; i++ ) {
      nverts = mesh->polSize( mesh, odb->pol[ i ].id );
      odb->pol[ i ].v = (st_DBPolVert*)calloc( nverts, sizeof( DBPolVert ));
      if ( !odb->pol[ i ].v ) goto Finish;
      odb->pol[ i ].nverts = nverts;
      for ( j = 0; j < nverts; j++ ) {
         ptid = mesh->polVertex( mesh, odb->pol[ i ].id, j );
         odb->pol[ i ].v[ j ].index = findVert( odb, ptid );
      }
   }

   /* count the number of polygons per point */

   for ( i = 0; i < npols; i++ )
      for ( j = 0; j < odb->pol[ i ].nverts; j++ )
         ++odb->pt[ odb->pol[ i ].v[ j ].index ].npols;

   /* alloc per-point polygon arrays */

   for ( i = 0; i < npts; i++ ) {
      if ( odb->pt[ i ].npols == 0 ) continue;
      odb->pt[ i ].pol = (int*)calloc( odb->pt[ i ].npols, sizeof( int ));
      if ( !odb->pt[ i ].pol ) goto Finish;
      odb->pt[ i ].npols = 0;
   }

   /* fill in polygon array for each point */

   for ( i = 0; i < npols; i++ ) {
      for ( j = 0; j < odb->pol[ i ].nverts; j++ ) {
         k = odb->pol[ i ].v[ j ].index;
         odb->pt[ k ].pol[ odb->pt[ k ].npols ] = i;
         ++odb->pt[ k ].npols;
      }
   }

   /* get the base position of each point */

   for ( i = 0; i < npts; i++ )
      mesh->pntBasePos( mesh, odb->pt[ i ].id, odb->pt[ i ].pos[ 0 ] );

   /* init the point search array */
   /* do this here if you need to search by base pos, or later if you
      need to search by final pos */

   // if ( !initPointSearch( odb, 0 ))
   //    goto Finish;

   /* calculate the base normal of each polygon */

   getPolyNormals( odb, 0 );

   /* get the vmaps */

   if ( !getObjectVMaps( odb, mesh, global ))
      goto Finish;

   /* get the surfaces */

   if ( !getObjectSurfs( odb, mesh, global ))
      goto Finish;

   /* calculate initial vertex normals */

   getVertNormals( odb, 0 );

   /* done */

   ok = 1;

Finish:
   if ( mesh->destroy )
      mesh->destroy( mesh );

   if ( !ok ) {
      freeObjectDB( odb );
      return NULL;
   }

   return odb;
}
Exemple #5
0
void xr_dsa::generate_params()
{
	int counter;
	unsigned long	long_ret;
	string256		random_string;
	xr_sprintf					(random_string, "%I64d_%s", CPU::QPC(), rnd_seed);
	//sprintf_s					(random_string, "%s", rnd_seed);
	unsigned char*	rnd_seed	= static_cast<unsigned char*>((void*)random_string);
	unsigned int	rnd_ssize	= xr_strlen(random_string);
	DSA* tmp_dsa_params	= DSA_generate_parameters(
		key_bit_length,
		rnd_seed,
		rnd_ssize,
		&counter,
		&long_ret,
		dsa_genparams_cb,
		NULL
	);
	DSA_generate_key	(tmp_dsa_params);

	VERIFY				(tmp_dsa_params->p->top * sizeof(u32)		== public_key_length);
	VERIFY				(tmp_dsa_params->q->top * sizeof(u32)		== private_key_length);
	VERIFY				(tmp_dsa_params->g->top * sizeof(u32)		== public_key_length);
	VERIFY				(tmp_dsa_params->pub_key->top * sizeof(u32) == public_key_length);
	VERIFY				(tmp_dsa_params->priv_key->top * sizeof(u32)== private_key_length);
	
	Msg("// DSA params ");
	
	Msg("u8 const p_number[crypto::xr_dsa::public_key_length] = {");
	print_big_number	(tmp_dsa_params->p);
	Msg("};//p_number");

	
	Msg("u8 const q_number[crypto::xr_dsa::private_key_length] = {");
	print_big_number	(tmp_dsa_params->q);
	Msg("};//q_number");
	
	
	Msg("u8 const g_number[crypto::xr_dsa::public_key_length] = {");
	print_big_number	(tmp_dsa_params->g);
	Msg("};//g_number");

	Msg("u8 const public_key[crypto::xr_dsa::public_key_length] = {");
	print_big_number	(tmp_dsa_params->pub_key);
	Msg("};//public_key");

	
	u8	priv_bin[private_key_length];
	BN_bn2bin			(tmp_dsa_params->priv_key, priv_bin);
	Msg("// Private key:");
	for (int i = 0; i < private_key_length; ++i)
	{
		Msg("	m_private_key.m_value[%d]	= 0x%02x;", i, priv_bin[i]);
	}

	u8	debug_digest[]		= "this is a test";
	u8	debug_bad_digest[]	= "this as a test";

	u32		siglen			= DSA_size(tmp_dsa_params);
	u8*		sig				= static_cast<u8*>(_alloca(siglen));

	BIGNUM	bn_sign;
	BN_init					(&bn_sign);
	
	VERIFY	(DSA_sign(0, debug_digest, sizeof(debug_digest), sig, &siglen, tmp_dsa_params) == 1);

	BN_bin2bn				(sig, siglen, &bn_sign);
	shared_str sig_str		= BN_bn2hex(&bn_sign);
	
	BIGNUM*	bn_rsing		= NULL;
	ZeroMemory				(sig, siglen);
	BN_hex2bn				(&bn_rsing, sig_str.c_str());
	BN_bn2bin				(bn_rsing, sig);
	BN_free					(bn_rsing);

	VERIFY	(DSA_verify(0, debug_digest, sizeof(debug_digest), sig, siglen, tmp_dsa_params) == 1);

	VERIFY	(DSA_verify(0, debug_bad_digest, sizeof(debug_bad_digest), sig, siglen, tmp_dsa_params) == 0);

	DSA_free(tmp_dsa_params);
}
void game_cl_Deathmatch::OnVoteStart(NET_Packet& P)
{
	CStringTable st;
	inherited::OnVoteStart(P);

	string1024	Command = "";
	string64	Player = "";
	P.r_stringZ(Command);
	P.r_stringZ(Player);
	m_dwVoteEndTime = Level().timeServer() + P.r_u32();
	
	if(m_game_ui)
	{
		string4096 CmdName = "";
		string1024 NewCmd; xr_strcpy(NewCmd, Command);
		string1024 CmdParams[MAX_VOTE_PARAMS] = {"", "", "", "", ""};
		sscanf	(Command,"%s %s %s %s %s %s", CmdName, CmdParams[0], CmdParams[1], CmdParams[2], CmdParams[3], CmdParams[4]);

		if (!xr_strcmp(CmdName, "restart"))
		{
			xr_sprintf(NewCmd, "%s", 
				*st.translate("mp_restart")
				);
		}
		else if (!xr_strcmp(CmdName, "restart_fast"))
		{
			xr_sprintf(NewCmd, "%s", 
				*st.translate("mp_restart_fast")
				);
		}
		else if (!xr_strcmp(CmdName, "kick"))
		{
			xr_sprintf(NewCmd, "%s %s", 
				*st.translate("mp_kick"), 
				CmdParams[0]
				);
			for (int i=1; i<MAX_VOTE_PARAMS; i++)
			{
				if (xr_strlen(CmdParams[i]))
				{
					xr_strcat(NewCmd, " ");
					xr_strcat(NewCmd, CmdParams[i]);
				}
			}
		}
		else if (!xr_strcmp(CmdName, "ban"))
		{
			xr_sprintf(NewCmd, "%s %s", 
				*st.translate("mp_ban"), 
				CmdParams[0]
				);
			for (int i=1; i<MAX_VOTE_PARAMS; i++)
			{
				if (xr_strlen(CmdParams[i]))
				{
					xr_strcat(NewCmd, " ");
					xr_strcat(NewCmd, CmdParams[i]);
				}
			}
		}
		else if (!xr_strcmp(CmdName, "changemap"))
		{
			xr_sprintf(NewCmd, "%s %s", 
				*st.translate("mp_change_map"), 
				*st.translate(CmdParams[0])
				);
		}
		else if (!xr_strcmp(CmdName, "changeweather"))
		{
			xr_sprintf(NewCmd, "%s %s", 
				*st.translate("mp_change_weather"), 
				*st.translate(CmdParams[0])
				);
		}

		
		string1024 VoteStr;
		xr_sprintf(VoteStr, *st.translate("mp_voting_started"), NewCmd, Player);		
		


		m_game_ui->SetVoteMessage(VoteStr);
		m_game_ui->SetVoteTimeResultMsg("");
		if (!m_pVoteRespondWindow)
            m_pVoteRespondWindow = xr_new<CUIVote>();
		m_pVoteRespondWindow->SetVoting(VoteStr);
	};
};
Exemple #7
0
int CScriptStorage::vscript_log		(ScriptStorage::ELuaMessageType tLuaMessageType, LPCSTR caFormat, va_list marker)
{
#ifndef NO_XRGAME_SCRIPT_ENGINE
#	ifdef DEBUG
	if (!psAI_Flags.test(aiLua) && (tLuaMessageType != ScriptStorage::eLuaMessageTypeError))
		return(0);
#	endif
#endif

#ifndef PRINT_CALL_STACK
	return		(0);
#else // #ifdef PRINT_CALL_STACK
#	ifndef NO_XRGAME_SCRIPT_ENGINE
		if (!psAI_Flags.test(aiLua) && (tLuaMessageType != ScriptStorage::eLuaMessageTypeError))
			return(0);
#	endif // #ifndef NO_XRGAME_SCRIPT_ENGINE

	LPCSTR		S = "", SS = "";
	LPSTR		S1;
	string4096	S2;
	switch (tLuaMessageType) {
		case ScriptStorage::eLuaMessageTypeInfo : {
			S	= "* [LUA] ";
			SS	= "[INFO]        ";
			break;
		}
		case ScriptStorage::eLuaMessageTypeError : {
			S	= "! [LUA] ";
			SS	= "[ERROR]       ";
			break;
		}
		case ScriptStorage::eLuaMessageTypeMessage : {
			S	= "[LUA] ";
			SS	= "[MESSAGE]     ";
			break;
		}
		case ScriptStorage::eLuaMessageTypeHookCall : {
			S	= "[LUA][HOOK_CALL] ";
			SS	= "[CALL]        ";
			break;
		}
		case ScriptStorage::eLuaMessageTypeHookReturn : {
			S	= "[LUA][HOOK_RETURN] ";
			SS	= "[RETURN]      ";
			break;
		}
		case ScriptStorage::eLuaMessageTypeHookLine : {
			S	= "[LUA][HOOK_LINE] ";
			SS	= "[LINE]        ";
			break;
		}
		case ScriptStorage::eLuaMessageTypeHookCount : {
			S	= "[LUA][HOOK_COUNT] ";
			SS	= "[COUNT]       ";
			break;
		}
		case ScriptStorage::eLuaMessageTypeHookTailReturn : {
			S	= "[LUA][HOOK_TAIL_RETURN] ";
			SS	= "[TAIL_RETURN] ";
			break;
		}
		default : NODEFAULT;
	}
	
	strcpy_s	(S2,S);
	S1		= S2 + xr_strlen(S);
	int		l_iResult = vsprintf(S1,caFormat,marker);
	Msg		("%s",S2);
	
	strcpy_s	(S2,SS);
	S1		= S2 + xr_strlen(SS);
	vsprintf(S1,caFormat,marker);
	strcat	(S2,"\r\n");

#ifdef DEBUG
#	ifndef ENGINE_BUILD
	ai().script_engine().m_output.w(S2,xr_strlen(S2)*sizeof(char));
#	endif // #ifdef ENGINE_BUILD
#endif // #ifdef DEBUG

	return	(l_iResult);
#endif // #ifdef PRINT_CALL_STACK
}
Exemple #8
0
void CUITalkWnd::AddQuestion(LPCSTR text, int value)
{
	if(xr_strlen(text) == 0) return;
	UITalkDialogWnd->AddQuestion(*CStringTable().translate(text),value);
}