Exemplo n.º 1
0
XRGAMESPY_API void xrGS_qr2_think(qr2_t qrec)
{
	qr2_think(qrec);
};
Exemplo n.º 2
0
int test_main(int argc, char **argp)
{			
	/* qr2_init parameters */
	gsi_char  secret_key[9];         // your title's assigned secret key
	gsi_char  ip[255];               // to manually set local IP
	const int isPublic = 1;          // set to '0' for a LAN game
	const int isNatNegSupported = 1; // set to '0' if you don't support Nat Negotiation
	gsi_time  aStartTime = 0;        // for sample, so we don't run forever
	void * userData = NULL;          // optional data that will be passed to the callback functions

	// for debug output on these platforms
#if defined (_PS3) || defined (_PS2) || defined (_PSP) || defined(_NITRO)
	#ifdef GSI_COMMON_DEBUG
		// Define GSI_COMMON_DEBUG if you want to view the SDK debug output
		// Set the SDK debug log file, or set your own handler using gsSetDebugCallback
		//gsSetDebugFile(stdout); // output to console
		gsSetDebugCallback(DebugCallback);

		// Set debug levels
		gsSetDebugLevel(GSIDebugCat_All, GSIDebugType_All, GSIDebugLevel_Verbose);
	#endif
#endif

	//set the secret key, in a semi-obfuscated manner
	secret_key[0] = 'H';
	secret_key[1] = 'A';
	secret_key[2] = '6';
	secret_key[3] = 'z';
	secret_key[4] = 'k';
	secret_key[5] = 'S';
	secret_key[6] = '\0';

	// register our custom keys (you do not have to register the reserved standard keys)
	AppDebug("Registering custom keys\n");
	qr2_register_key(GRAVITY_KEY, _T("gravity")    );
	qr2_register_key(RANKINGON_KEY, _T("rankingon"));
	qr2_register_key(TIME__KEY,     _T("time_")    ); // player keys always end with '_'
	qr2_register_key(AVGPING_T_KEY, _T("avgping_t")); // team keys always end with '_t'

	// create some random game data
	init_game();

	// Check if we want to override our IP  (otherwise qr2 will set for us)	
#ifndef GSI_UNICODE
	if (argc>1)
		strcpy(ip, argp[1]);
#else
	if (argc>1)
		AsciiToUCS2String(argp[1], ip);
#endif

	AppDebug("Initializing SDK; server should show up on the master list within 6-10 sec.\n");
	//Call qr_init with the query port number and gamename, default IP address, and no user data
	//Pass NULL for the qrec parameter (first parameter) as long as you're running a single game 
	//server instance per process
	//Reference gt2nat sample for qr2_init_socket implementation
	if (qr2_init(NULL,argc>1?ip:NULL,BASE_PORT,GAME_NAME, secret_key, isPublic, isNatNegSupported,
		serverkey_callback, playerkey_callback, teamkey_callback,
		keylist_callback, count_callback, adderror_callback, userData) != e_qrnoerror)
	{
		printf("Error starting query sockets\n");
		return -1;
	}

	// Set a function to be called when we receive a game specific message
	qr2_register_clientmessage_callback(NULL, cm_callback);

	// Set a function to be called when we receive a nat negotiation request
	qr2_register_natneg_callback(NULL, nn_callback);

	// Set a function to be called when a client has connected
	qr2_register_clientconnected_callback(NULL, cc_callback);

	// Enter the main loop
	AppDebug("Sample will quit after 60 seconds\n");
	aStartTime = current_time();
	while ((current_time() - aStartTime) < 60000)
	{
		gsi_time totalTime = current_time() - aStartTime; // used to change the game state after 30 seconds

		// An actual game would do something between "thinks"
		DoGameStuff(totalTime);

		//check for / process incoming queries
		//should be called every 10-100 ms; quicker calls produce more accurate ping measurements
		qr2_think(NULL);
	}

	AppDebug("Shutting down - server will be removed from the master server list\n");
	//let gamemaster know we are shutting down (removes dead server entry from the list)
	qr2_shutdown(NULL);

	
#ifdef GSI_UNICODE
	// In Unicode mode we must perform additional cleanup
	qr2_internal_key_list_free();
#endif

	// Finished
	return 0;
}