Example #1
0
static gsi_bool isBackendAvailable()
{
	// Do Availability Check - Make sure backend is available
	/////////////////////////////////////////////////////////
	GSIACResult aResult = GSIACWaiting; 
	GSIStartAvailableCheck(SCTEST_GAMENAME);
	while(aResult == GSIACWaiting)
	{
		aResult = GSIAvailableCheckThink();
		msleep(5);
	}

	if (aResult == GSIACUnavailable)
	{
		printf("Online Services for sctest are no longer available\r\n"); 
		return gsi_false;
	}

	if (aResult == GSIACTemporarilyUnavailable)
	{
		printf("Online Services for sctest are temporarily down for maintenance\r\n"); 
		return gsi_false;
	}

	return gsi_true;
}
Example #2
0
BOOL CSbmfcsampleDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);
	SetIcon(m_hIcon, FALSE);

	//SB - setup list columns
	m_serverList.InsertColumn(COL_SERVERNAME, "Server Name", LVCFMT_LEFT, 150, -1);
	m_serverList.InsertColumn(COL_PING, "Ping", LVCFMT_LEFT, 50, 0);
	m_serverList.InsertColumn(COL_PLAYERS, "Players", LVCFMT_LEFT, 75, 1);
	m_serverList.InsertColumn(COL_MAPNAME, "Map", LVCFMT_LEFT, 75, 2);
	m_serverList.InsertColumn(COL_GAMETYPE, "GameType", LVCFMT_LEFT, 100, 3);
	m_playerList.InsertColumn(COL_PNAME, "Player Name", LVCFMT_LEFT, 150, -1);
	m_playerList.InsertColumn(COL_PPING, "Ping", LVCFMT_LEFT, 50, 0);
	m_playerList.InsertColumn(COL_PSCORE, "Score", LVCFMT_LEFT, 50, 1);
	ListView_SetExtendedListViewStyle(m_serverList.m_hWnd, LVS_EX_FULLROWSELECT);
	ListView_SetExtendedListViewStyle(m_playerList.m_hWnd, LVS_EX_FULLROWSELECT);

	//SB - default to Internet
	CheckRadioButton(IDC_INTERNET, IDC_LAN, IDC_INTERNET);

	//SB - default to QR2
	CheckRadioButton(IDC_GOA, IDC_QR2, IDC_QR2);

	//SB - no server browser yet
	m_serverBrowser = NULL;

	//SB - no timer yet
	m_timerID = 0;

	//SB - no servers yet
	m_servers.SetWindowText("");
	
	//SB - check that the game's backend is available
	GSIACResult result;
	GSIStartAvailableCheck("gmtest");
	while((result = GSIAvailableCheckThink()) == GSIACWaiting)
		msleep(5);
	if(result != GSIACAvailable)
	{
		MessageBox("The backend is not available\n");
		return TRUE;
	}

	return TRUE;
}
Example #3
0
/* Primary "game" logic. Basically:
1. Set up a "server" listen socket
2. Initialize the client structures
3. Enter a main loop
	a. Let the gcd code think / do callbacks
	b. Check for a new connection on the server socket and create a new client
	c. Check for data on the client sockets
	d. Check for disconnects on the client sockets
4. Disconnect remaining players and exit
*/
int test_main(int argc, char **argv)
{
	
	client_t clients[MAXCLIENTS];
	SOCKET ssock;
	struct sockaddr_in saddr;
	int saddrlen = sizeof(saddr);
	fd_set set; 
	struct timeval timeout = {0,0};
	int error;
	int i,len;
	int quit = 0;
	char buf[512];
	unsigned short port;
	GSIACResult result;
	
	// check that the game's backend is available
	GSIStartAvailableCheck(MY_GAMENAME);
	while((result = GSIAvailableCheckThink()) == GSIACWaiting)
		msleep(5);
	if(result != GSIACAvailable)
	{
		printf("The backend is not available\n");
		return 1;
	}

	/* Initialize the gcd system with the 
	gameid you have been assigned */
	if(gcd_init(MY_GAMEID) != 0)
	{
		printf("Error initializing\n");
		return 1;
	}

	SocketStartUp();
	ssock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	memset(&saddr, 0, sizeof(saddr));
	saddr.sin_family = AF_INET;

	i = 0; // initialize here just to prevent compiler error
	for(port = PORT ; port < (PORT + 100) ; port++)
	{
		saddr.sin_port = htons(port);
		i = bind(ssock, (struct sockaddr *)&saddr, sizeof(saddr));
		if(gsiSocketIsNotError(i))
			break;
	}
	if (gsiSocketIsError(i))
	{
		printf("Unable to bind to any of the ports %d through %d (%d)\n",PORT, port - 1, GOAGetLastError(ssock));
		return 1;
	}
	listen(ssock, SOMAXCONN);

	for (i = 0 ; i < MAXCLIENTS ; i++)
		clients[i].sock = INVALID_SOCKET;

	printf("Running on port %d... press any key to quit\n", port);
	while (!quit)
	{ //main loop
		msleep(10);
		gcd_think();
		
	
		#ifdef _WIN32
			quit = _kbhit();
		#else
		 //on other systems, you gotta kill it hard
		#endif
	
		FD_ZERO ( &set );
		FD_SET ( ssock, &set );
		for (i = 0 ; i < MAXCLIENTS ; i++)
			if (clients[i].sock != INVALID_SOCKET)
				FD_SET(clients[i].sock , &set);
		error = select(FD_SETSIZE, &set, NULL, NULL, &timeout);
		if (/*gsiSocketIsError(ret) ||*/ 0 == error)
			continue;

		//new connection
		if (FD_ISSET(ssock, &set))
		{
			for (i = 0 ; i < MAXCLIENTS ; i++)
				if (clients[i].sock  == INVALID_SOCKET)
				{
					clients[i].sock  = accept(ssock, (struct sockaddr *)&(clients[i].saddr), &saddrlen);
					listen(ssock,SOMAXCONN);
					strcpy(clients[i].challenge,randomchallenge(8));
					len = sprintf(buf,"c:%s",clients[i].challenge);
					send(clients[i].sock ,buf, len,0); //send a challenge
					clients[i].auth = 0;
					printf("Client %d connected\n",i);
					break;
				}
		}
		
		//client data
		for (i = 0 ; i < MAXCLIENTS ; i++)
			if (clients[i].sock != INVALID_SOCKET && FD_ISSET(clients[i].sock, &set))
			{ 
				len = recv(clients[i].sock,buf, 512, 0);
				if (len <= 0) //the client disconnected
				{
					printf("Client %d disconnected\n",i);
					closesocket(clients[i].sock);
					clients[i].sock = INVALID_SOCKET;
					if (clients[i].auth) //if they were authorized
						gcd_disconnect_user(MY_GAMEID, i);
					continue;
				} 
				buf[len] = 0;
				if (buf[0] == 'r' && buf[1] == ':' && clients[i].auth == 0) //challenge response
				{
					printf("Client %d said %s\n",i,buf);
					clients[i].auth = 1;
					gcd_authenticate_user(MY_GAMEID, i,clients[i].saddr.sin_addr.s_addr, 	  
						clients[i].challenge, buf+2, ClientAuthorize, ClientRefreshAuthorize, clients);
				}
				else if (buf[0] == 'p' && buf[1] == ':' && clients[i].auth == 1) // ison proof response
				{
					//gcd_send_reauth_response needs to know the sesskey (so keymaster can find the task)
					//	and fromaddr (so gcdkey knows which keymaster to respond to)
					if (len > 11)
					{
						char hintstr[9];
						int hint = 0;

						memcpy(hintstr, buf+2, 8); // first 8 characters are the hint
						hintstr[8] = '\0';
						hint = atoi(hintstr);

						printf("Client %d prooved %d, %s\n",i,hint,buf+10);
						gcd_process_reauth(MY_GAMEID, i, hint, buf+10);
					}
				}
			}
	}
	gcd_disconnect_all(MY_GAMEID);
	gcd_shutdown();
	SocketShutDown();
	printf("All done!\n");
	return 0;

	GSI_UNUSED(argv);
	GSI_UNUSED(argc);
}
Example #4
0
//XRGAMESPY_API void	xrGS_GSIStartAvailableCheck(const gsi_char * gamename)
XRGAMESPY_API void	xrGS_GSIStartAvailableCheck()
{
//	GSIStartAvailableCheck(gamename);
	GSIStartAvailableCheck(GAMESPY_GAMENAME);
};
Example #5
0
int test_main(int argc, char **argv)
{
	int result;
	int authcount;
	int callbackct;
	char validate[33], cdkey_hash[33];
	int player1pid;
	GSIACResult ac_result;

	playerdata_t playerdata;

	/*********
	First step, set our game authentication info
	We could do:
		strcpy(gcd_gamename,"gmtest");
		strcpy(gcd_secret_key,"HA6zkS");
	...but this is more secure:
	**********/
	gcd_gamename[0]='g';gcd_gamename[1]='m';gcd_gamename[2]='t';gcd_gamename[3]='e';
	gcd_gamename[4]='s';gcd_gamename[5]='t';gcd_gamename[6]='\0';
	gcd_secret_key[0]='H';gcd_secret_key[1]='A';gcd_secret_key[2]='6';gcd_secret_key[3]='z';
	gcd_secret_key[4]='k';gcd_secret_key[5]='S';gcd_secret_key[6]='\0';

	/*********
	Before initializing the connection,
	check that the backend is available.
	*********/
	GSIStartAvailableCheck(_T("gmtest"));
	while((ac_result = GSIAvailableCheckThink()) == GSIACWaiting)
		msleep(5);
	if(ac_result != GSIACAvailable)
	{
		printf("The backend is not available\n");
		return 1;
	}

	/*********
	Next, open the stats connection. This may block for
	a 1-2 seconds, so it should be done before the actual game starts.
	**********/
	result = InitStatsConnection(MY_GAMEPORT);

	if (result != GE_NOERROR)
	{
		printf("InitStatsConnection returned %d\n",result);		
		return 1;
	}

	/********
	Now, lets authenticate two players, one using the a Presence & Messaging
	SDK profileid, and the other using a CDKey SDK CD Key.
	The profile/password and CD Key/nick to use are defined at the top.

	Generally you will only use one method or the other, depending on your game.
	*********/
	/*************
	The first step to authenticate a player is to generate their Authentication token.

	If you are retrieving/setting persistent data on the server, you should first send
	the challenge to the client, have them send back the validation, and then proceed
	with the authentication. In this manner the client never has to send their password
	or CD Key to the server -- only the validation hash.
	If you are retrieving/setting persistent data on the client, it can all be done
	locally, as shown below.
	*************/

	/************
	First, we will authenticate a player using the CD Key system. We pass in the
	plaintext CD Key to GenerateAuth to get the validation token (validate).
	*************/
	GenerateAuth(GetChallenge(NULL),VALIDCDKEY,validate);
	
	/************
	Next, we need to get the hash of the CD Key to along with the validation.
	This can be done easily using GenerateAuth with an empty challenge string
	************/
	GenerateAuth("",VALIDCDKEY,cdkey_hash);

	/***********
	Now, we call PreAuthenticatePlayerCD with the hash and the validation token.
	We pass in a callback that will be called when the operation is complete, along
	with a integer that we will check to know its done.
	We pass in the localid as 1, since we will be authenticating two players before
	checking the return values. By using different localids we can tell them apart.
	************/
	authcount = 0;
	PreAuthenticatePlayerCD(1,KEYNICK,cdkey_hash,validate,PersAuthCallback,&authcount);

	/***********
	While the first authentication is in progress, we'll go ahead and start the second
	one, using a Presence & Messaging SDK profileid / password.
	To generate the new validation token, we'll need to pass in the password for the
	profile we are authenticating.
	Again, if this is done in a client/server setting, with the Persistent Storage
	access being done on the server, and the P&M SDK is used on the client, the
	server will need to send the challenge (GetChallenge(NULL)) to the client, the
	client will create the validation token using GenerateAuth, and send it
	back to the server for use in PreAuthenticatePlayerPM
	***********/
	GenerateAuth(GetChallenge(NULL),VALIDPROFILEPASSWORD,validate);

	/************
	After we get the validation token, we pass it and the profileid of the user
	we are authenticating into PreAuthenticatePlayerPM.
	We pass the same authentication callback as for the first user, but a different
	localid this time.
	************/
	PreAuthenticatePlayerPM(2,PROFILEID,validate,PersAuthCallback,&authcount);

	/***********
	Now that both authentication requests are sent, we need to wait for the results to
	come back. If we were in a game we could continue with the main game loop at this
	point, but since we're not, we'll just loop until we are disconnected or both
	authentications come back
	************/
	while (authcount < 2 && IsStatsConnected())
	{
		PersistThink();
		msleep(10);
	}

	/**********
	Both of the players have now been authenticated.
	When the CD Key player (player 1) was authenticated, the profileid for him
	was returned in the callback, but we didn't save it off. Since we'll need it
	to get/set data for him, lets go ahead and retrieve it using the GetProfileIDFromCD
	function
	**********/
	player1pid = 0;
	GetProfileIDFromCD(1,KEYNICK,cdkey_hash,ProfileCallback,&player1pid);

	/**********
	Again we'll wait until the call completes. We check if player1pid is still 0, since
	it gets set to the profileid in the callback (or -1 if a failure)
	***********/
	while (player1pid == 0 && IsStatsConnected())
	{
		PersistThink();
		msleep(10);
	}

	/**********
	Now we have everything we need to start getting / setting data for the two
	users. First we'll clear both user's public data, to make sure it's empty
	before we continue
	***********/
	callbackct = 0;
	SetPersistData(1,player1pid,pd_public_rw,0,"",0,PersDataSaveCallback,&callbackct);
	SetPersistData(2,PROFILEID,pd_public_rw,0,"",0,PersDataSaveCallback,&callbackct);
	
	/**********
	We'll use the callbackct var (passed in to the callbacks) as a way to easily determine
	when the calls are complete
	***********/
	while (callbackct < 2 && IsStatsConnected())
	{
		PersistThink();
		msleep(10);
	}

	
	/***********
	Lets read the data back, just to prove it's cleared
	************/
	callbackct = 0;
	GetPersistData(1,player1pid,pd_public_rw,0,PersDataCallback,&callbackct);
	GetPersistData(2,PROFILEID,pd_public_rw,0,PersDataCallback,&callbackct);
	while (callbackct < 2 && IsStatsConnected())
	{
		PersistThink();
		msleep(10);
	}

	/************
	Now lets set some REAL data!
	For player1 we will use ascii key\value pairs, for player2 we will store
	binary structures. Note that if you store binary structures, YOU are responsible
	for making sure things like byte order, structure size, and contents do not change
	between versions or platforms of your game that may access the same data
	************/
	callbackct = 0;
	playerdata.hitpoints = 600;
	playerdata.modelnumber = 5;
	playerdata.totaltime = 5000;
	strcpy(playerdata.skin,"darkstar");
	SetPersistData(1,player1pid,pd_public_rw,0,(char *)&playerdata,sizeof(playerdata_t),PersDataSaveCallback,&callbackct);
	SetPersistDataValues(2,PROFILEID,pd_public_rw,0,_T("\\key1\\value1\\key2\\value2\\key3\\value3"),PersDataSaveCallback,&callbackct);
	while (callbackct < 2 && IsStatsConnected())
	{
		PersistThink();
		msleep(10);
	}

	/***********
	Lets read the data back, to see what's there!
	We'll use a custom callback for player1 to print out the playerdata struct that's read back.
	************/
	callbackct = 0;
	GetPersistData(1,player1pid,pd_public_rw,0,PlayerDataCallback,&callbackct);
	GetPersistData(2,PROFILEID,pd_public_rw,0,PersDataCallback,&callbackct);
	while (callbackct < 2 && IsStatsConnected())
	{
		PersistThink();
		msleep(10);
	}

	/***********
	Now, lets manipulate player2's data a bit using the SetPersistDataValues functions.
	We'll also print it at each stage, so you can see the changes as they occur

	First, we'll update the values of key1 and key3 (but not key2) and add keys 4 and 5.
	Your keys don't have to be numbered like this, this is just an example
	************/
	callbackct = 0;
	SetPersistDataValues(2,PROFILEID,pd_public_rw,0,_T("\\key1\\valueA\\key3\\valueB\\key4\\value400\\key5\\value500"),
		PersDataSaveCallback,&callbackct);
	GetPersistData(2,PROFILEID,pd_public_rw,0,PersDataCallback,&callbackct);

	/***********
	Now we'll clear key 2, and update keys 3 and 4, and add two other keys
	************/
	SetPersistDataValues(2,PROFILEID,pd_public_rw,0,_T("\\key2\\\\key3\\valueC\\key4\\value401\\mykeyname\\mykeyvalue\\otherkey\\othervalue"),
		PersDataSaveCallback,&callbackct);
	GetPersistData(2,PROFILEID,pd_public_rw,0,PersDataCallback,&callbackct);

	/***********
	Finally, lets see how we can use GetPersistDataValues to only return a subset
	of the keys that are stored. For example, we will only return keys 1,2,3,and 4
	The order you list them in does not matter
	************/
	GetPersistDataValues(2,PROFILEID,pd_public_rw,0,_T("\\key3\\key2\\key4\\key1"),PersDataCallback,&callbackct);

	/***********
	We've now sent off 5 requests without actually checking the results. The results are already coming in,
	we just need to think a while to get them all
	************/
	while (callbackct < 5 && IsStatsConnected())
	{
		PersistThink();
		msleep(100);
	}
	
	/**********
	When we're done we'll close off the connection
	***********/	
	CloseStatsConnection();

	GSI_UNUSED(argc);
	GSI_UNUSED(argv);

	return 0;
}
Example #6
0
BOOL CClientDlg::OnInitDialog()
{
	CSubDlg::OnInitDialog();

	m_pBtnJoin.EnableWindow(FALSE);
	m_pBtnRefresh.EnableWindow(TRUE);

	RECT wRect;
	m_pServerList.GetWindowRect(&wRect);
	int NumColumns = 5;
	m_pServerList.InsertColumn(0, "Server Name", LVCFMT_CENTER, (wRect.right - wRect.left)/NumColumns-1);
	m_pServerList.InsertColumn(1, "Map Name", LVCFMT_CENTER, (wRect.right - wRect.left)/NumColumns-1);
	m_pServerList.InsertColumn(2, "Game Mode", LVCFMT_CENTER, (wRect.right - wRect.left)/NumColumns-1);
	m_pServerList.InsertColumn(3, "Players", LVCFMT_CENTER, (wRect.right - wRect.left)/NumColumns-1);
	m_pServerList.InsertColumn(4, "Ping", LVCFMT_CENTER, (wRect.right - wRect.left)/NumColumns-1);
//	m_pServerList.InsertColumn(5, "Protected", LVCFMT_CENTER, (wRect.right - wRect.left)/NumColumns-1);

	m_pServerList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
	//=============================================================================
	/*
	HICON hiconItem;     // icon for list view items 
	HIMAGELIST hSmall;   // image list for other views 
	hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), 
		GetSystemMetrics(SM_CYSMICON), ILC_COLOR24, 2, 1); 
	hiconItem = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDB_BITMAP1)); 
	ImageList_AddIcon(hSmall, hiconItem); 
	DestroyIcon(hiconItem); 
	m_pServerList.SetImageList(hSmall, LVSIL_SMALL); 
	*/

	BOOL res = m_pNewImageList.Create((IDB_BITMAP1), 16, 1, RGB(255, 255, 255));
	m_pServerList.SetImageList(&m_pNewImageList, LVSIL_SMALL);



//	hiconItem = LoadIcon(MAKEINTRESOURCE(IDI_ITEM)); 

//	m_pServerList.SetIcon()
	//=============================================================================
	//.......................................................
	InitializeCriticalSection( &m_pCriticalSection );
	// Init COM so we can use CoCreateInstance
	CoInitialize( NULL);//, COINIT_MULTITHREADED );
	//.......................................................
	//=========== Game Spy =================================================
	m_timerID = 0;
	//SB - check that the game's backend is available
	qr2_register_key(GAMETYPE_NAME_KEY,   ("gametypename")  );
	qr2_register_key(DEDICATED_KEY,   ("dedicated")  );
	qr2_register_key(G_FRIENDLY_FIRE_KEY,   ("friendlyfire")  );
	


	GSIACResult result;
	GSIStartAvailableCheck(GAMESPY_GAMENAME);
	while((result = GSIAvailableCheckThink()) == GSIACWaiting)
		msleep(5);
	if(result != GSIACAvailable)
	{
		MessageBox("The backend is not available\n");
		return TRUE;
	}

	m_serverBrowser = ServerBrowserNew(GAMESPY_GAMENAME, GAMESPY_GAMENAME, SECRET_KEY, 0, MAX_UPDATES, QVERSION_QR2, SBFalse, SBCallback, this);
	if(!m_serverBrowser)
	{
		MessageBox("Unable to create the server browser object");
		return FALSE;
	}

	m_pGameSpyUpdateList.EnableWindow(TRUE);
	m_pGameSpyRefreshList.EnableWindow(TRUE);
	CheckRadioButton(IDC_INTERNET, IDC_LAN, IDC_LAN);
	//=====================================================================
	m_pFilter_Empty.SetCheck				(1);
	m_pFilter_Full.SetCheck					(1);
	m_pFilter_Password_With.SetCheck		(1);
	m_pFilter_Password_Without.SetCheck		(1);
	m_pFilter_Listen.SetCheck				(1);
	m_pFilter_NoFF.SetCheck					(1);
	m_pFilter_PunkBuster_Without.SetCheck	(1);

	CheckFilterButtons();
	//=====================================================================
	m_pBtnRefresh.EnableWindow(FALSE);
	//=====================================================================
	return TRUE;  // return TRUE  unless you set the focus to a control
}
Example #7
0
int test_main(int argc, char **argv)
{
	PEER peer;  // peer object (initialized with peerInitialize

	/* peerInitialize */   
	PEERCallbacks callbacks;  // we will need to add all of the supported callbacks

	/* peerSetTitle parameters */
	gsi_char  secret_key[9];      // your title's assigned secret key
	int maxUpdates = 10;  // max server queries the SDK will send out at a time
	PEERBool natNeg = PEERFalse;  // nat negotiation will not be supported
	PEERBool pingRooms[NumRooms];  
	PEERBool crossPingRooms[NumRooms];

	/* peerConnect parameters */
	int profileID = 0;  // we will not be using gp accounts, so this will be ignored
	void * userData = NULL;  // optional data passed to peerConnectCallback
	PEERBool blocking = PEERTrue; // true means function runs synchronously
	PEERBool non_blocking = PEERFalse; // false means function runs asynchronously

	int newbiesGroupID = 2;

	gsi_char * serverName = _T("UberNoobServer");
	int maxPlayers = 2;
	gsi_char * noPassword = _T("");

	GSIACResult result; // used for backend availability check
	gsi_time startTime;

	// set our nickname to a random string so that we'll have different nicks when running multiple instances of peerc
	_tsnprintf(nick,NICK_SIZE,_T("peerc%u"),(unsigned int)current_time());
	nick[NICK_SIZE - 1] = '\0';

	// 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';

	// check that the game's backend is available
	GSIStartAvailableCheck(_T("gmtest"));
	while((result = GSIAvailableCheckThink()) == GSIACWaiting)
		msleep(5);
	if(result != GSIACAvailable)
	{
		_tprintf(_T("The backend is not available\n"));
		return 1;
	}

	// set the callbacks
	memset(&callbacks, 0, sizeof(PEERCallbacks));
	callbacks.disconnected = DisconnectedCallback;
	//callbacks.qrNatNegotiateCallback
	callbacks.gameStarted = GameStartedCallback;
	callbacks.playerChangedNick = PlayerChangedNickCallback;
	callbacks.playerJoined = PlayerJoinedCallback;
	callbacks.playerLeft = PlayerLeftCallback;
	callbacks.readyChanged = ReadyChangedCallback;
	callbacks.roomMessage = RoomMessageCallback;
	callbacks.playerMessage = PlayerMessageCallback;
	callbacks.roomUTM = RoomUTMCallback;
	callbacks.roomKeyChanged = RoomKeyChangedCallback;
	callbacks.qrKeyList = QRKeyListCallback;
	callbacks.qrServerKey = QRServerKeyCallback;
	callbacks.param = NULL;

	// initialize peer object, specifying the supported callbacks
	peer = peerInitialize(&callbacks);
	if(!peer)
	{
		_tprintf(_T("Failed to init\n"));
		return 1;
	}

	// ping/cross-ping in every room
	pingRooms[TitleRoom] = PEERTrue;
	pingRooms[GroupRoom] = PEERTrue;
	pingRooms[StagingRoom] = PEERTrue;
	crossPingRooms[TitleRoom] = PEERTrue;
	crossPingRooms[GroupRoom] = PEERTrue;
	crossPingRooms[StagingRoom] = PEERTrue;

	// set the title
	if(!peerSetTitle(peer, TITLE, secret_key, TITLE, secret_key, 0, maxUpdates, natNeg, pingRooms, crossPingRooms))
	{
		peerShutdown(peer);
		_tprintf(_T("Failed to set the title\n"));
		return 1;
	}

	// connect to the chat server
	_tprintf(_T("Connecting as %s..."), nick);
	peerConnect(peer, nick, profileID, NickErrorCallback, ConnectCallback, userData, blocking);
	if(!connectSuccess)
	{
		peerShutdown(peer);
		_tprintf(_T("Failed to connect\n"));
		return 1;
	}
	printf("Connected\n\n");

	// join the title room
	printf("Joining title room...");
	peerJoinTitleRoom(peer, NULL, JoinCallback, NULL, PEERTrue);
	if(!joinSuccess)
	{
		peerDisconnect(peer);
		peerShutdown(peer);
		_tprintf(_T("Failed to join the title room\n"));
		return 1;
	}
	printf("Joined\n\n");

	// list the group rooms
	printf("Listing group rooms:\n");
	peerListGroupRooms(peer, _T(""), ListGroupRoomsCallback, userData, non_blocking);

	while (!groupRoomCallbackDone)
	{
		peerThink(peer);
		msleep(10);
	}

	// send a chat message to the room
	printf("\nSending message to the Title Room...\n");
	peerMessageRoom(peer, TitleRoom, _T("Hi everyone in the Title Room!\n"), NormalMessage);

	// Loop for a while
	startTime = current_time();
	while((current_time() - startTime) < (1000))
	{
		peerThink(peer);
		msleep(10);
	} 

	_tprintf(_T("\nJoining Group Room 'Newbies'..."));
	peerJoinGroupRoom(peer, newbiesGroupID, JoinRoomCallback, userData, blocking);

	_tprintf(_T("\nPlayers in Group Room: \n"));
	peerEnumPlayers(peer, GroupRoom, EnumPlayersCallback, NULL);

	_tprintf(_T("Hosting Staging Room...\n"));
	peerCreateStagingRoom(peer, serverName, maxPlayers, noPassword, CreateStagingRoomCallback, userData, blocking);

	// Loop for a while
	startTime = current_time();
	while((current_time() - startTime) < (1000))
	{
		peerThink(peer);
		msleep(10);
	}

    //peerStartAutoMatch(peer, 3, _T(""), AutoMatchStatusCallback, AutoMatchRateCallback, NULL, PEERFalse);

	//peerStopListingGames(peer);

	// Leave the title room
	peerLeaveRoom(peer, TitleRoom, NULL);

	// Stop auto match if it's in progress
	//peerStopAutoMatch(peer);

	// disconnect local client from chat server (peerShutdown must still be called)
	peerDisconnect(peer);

	peerShutdown(peer); // clean up (free internal sdk memory) 

	GSI_UNUSED(argc);
	GSI_UNUSED(argv);
	return 0;
}
Example #8
0
BOOL CTrackDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	int rcode;
	CString str;

	SetIcon(m_hIcon, TRUE);
	SetIcon(m_hIcon, FALSE);

	Dlg = this;

	// Use the development system.
	//////////////////////////////
	strcpy(StatsServerHostname, "sdkdev.gamespy.com");

	// Set the gamename and secret key.
	///////////////////////////////////
	strcpy(gcd_gamename, "st_highscore");
	gcd_secret_key[0] = 'K';
	gcd_secret_key[1] = 'S';
	gcd_secret_key[2] = '3';
	gcd_secret_key[3] = 'p';
	gcd_secret_key[4] = '2';
	gcd_secret_key[5] = 'Q';

	// Perform the availability check
	//////////////////////////////////////
	GSIACResult aResult = GSIACWaiting;
	GSIStartAvailableCheck(gcd_gamename);
	while(aResult == GSIACWaiting)
	{
		aResult = GSIAvailableCheckThink();
		Sleep(50);
	}

	// Init the connection to the backend.
	//////////////////////////////////////
	rcode = InitStatsConnection(0);
	if(rcode != GE_NOERROR)
	{
		str.Format("Failed to connect to the stats server (%d).", rcode);
		MessageBox(str);
		PostQuitMessage(1);
		return TRUE;
	}

	// Login the user (actually just verifying the login).
	//////////////////////////////////////////////////////
	if(m_loginDlg.DoModal() != IDOK)
	{
		PostQuitMessage(1);
		return TRUE;
	}

	SetTimer(TIMER_ONE_SECOND, 1000, NULL);
	SetTimer(TIMER_THINK, 50, NULL);

	SetupUser();

	return TRUE;
}