示例#1
0
文件: c4a.c 项目: theZiz/puzzletube
void init_c4a()
{
    spInitNet();
    profile = spNetC4AGetProfile();
    if (profile == NULL)
    {
        sprintf(c4aStatus,"C4A-Manager or Mini-C4A not installed.");
        c4aErrorTimeOut = 20000;
        c4aState = -3;
    }
    updateScores();
}
示例#2
0
void start_account()
{
	spPollKeyboardInput(shortName,3,SP_PRACTICE_OK_NOWASD_MASK);
	mode = 0;
	line = 0;
	profile = spNetC4AGetProfile();
	if (profile)
	{
		memcpy(longName,profile->longname,256);
		memcpy(shortName,profile->shortname,4);
		memcpy(password,profile->password,256);
		memcpy(mail,profile->email,256);
		mode = 1;
	}	
}
int main( int argc, char **argv )
{
	spInitNet();
	printf("Init spNet\n");

	//C4A Example
	spNetC4AScorePointer score;
	spNetC4AProfilePointer profile = spNetC4AGetProfile();
	if (profile)
	{
		printf("Your profile:\n");
		printf("Long Name: %s\n",profile->longname);
		printf("Short Name: %s\n",profile->shortname);
		printf("E-Mail: %s\n",profile->email);
		printf("Password: %s\n",profile->password);
	}
	else
		printf("No profile found. Put it to this folder or create it with compo4all!\n");
	
	//spNetC4AGetScoreOfMonth(&score,profile,"puzzletube_points",2013,6);
	printf("Getting Scores serial:\n");
	int i;
	int result = 0;
	for (i = 0; i < 2; i++)
	{
		switch (i)
		{
			case 0:
				result = spNetC4AGetScore(&score,profile,"snowman_hard",10000);
				printf("Highscore of Snowman Hard (with profile if available):\n");
				break;
			case 1:
				result = spNetC4AGetScore(&score,NULL,"snowman_easy",10000);
				printf("Highscore of Snowman Easy (wihtout profile):\n");
				break;
		}
		if (result == 0)
			while (spNetC4AGetStatus() == SP_C4A_PROGRESS)
			#ifdef WIN32
				Sleep(1);
			#else
				usleep(200);
			#endif
		if (result == 0 && spNetC4AGetStatus() == SP_C4A_OK)
		{
			spNetC4AScorePointer mom = score;
			while (mom)
			{
				struct tm * local = localtime (&(mom->commitTime));
				printf("  %2i: %2i.%2i.%i - %2i:%02i: %s (%s) - %i\n",mom->rank,local->tm_mday,local->tm_mon+1,local->tm_year+1900,local->tm_hour,local->tm_min,mom->longname,mom->shortname,mom->score);
				mom = mom->next;
			}
			printf("  Same with every player just once:\n");
			spNetC4AMakeScoresUnique(&score);
			mom = score;
			while (mom)
			{
				struct tm * local = localtime (&(mom->commitTime));
				printf("  %2i: %2i.%2i.%i - %2i:%02i: %s (%s) - %i\n",mom->rank,local->tm_mday,local->tm_mon+1,local->tm_year+1900,local->tm_hour,local->tm_min,mom->longname,mom->shortname,mom->score);
				mom = mom->next;
			}
			spNetC4ADeleteScores(&score);
		}
		else
		if (result == 1)
			printf("Fetshing Highscore failed with error code: %i\n",result);
		else
			printf("Fetshing Highscore failed with status code: %i\n",spNetC4AGetStatus());
	}




	printf("Getting Scores parallel:\n");
	spNetC4AScorePointer score1;
	spNetC4AScorePointer score2;
	spNetC4AScorePointer score3;
	spNetC4ATaskPointer p1 = spNetC4AGetScoreParallel(&score1,profile,"puzzletube_points",10000);
	spNetC4ATaskPointer p2 = spNetC4AGetScoreParallel(&score2,NULL,"puzzletube_race",10000);
	spNetC4ATaskPointer p3 = spNetC4AGetScoreParallel(&score3,NULL,"puzzletube_survival",10000);
	if (p1 && p2 && p3)
	while (spNetC4AGetStatusParallel(p1) == SP_C4A_PROGRESS ||
			spNetC4AGetStatusParallel(p2) == SP_C4A_PROGRESS ||
			spNetC4AGetStatusParallel(p3) == SP_C4A_PROGRESS)
	#ifdef WIN32
		Sleep(1);
	#else
		usleep(200);
	#endif
	for (i = 0; i < 3; i++)
	{
		spNetC4ATaskPointer p;
		switch (i)
		{
			case 0:
				printf("Highscore of Puzzletube Points (with profile if available):\n");
				p = p1;
				score = score1;
				break;
			case 1:
				printf("Highscore of Puzzletube Race (wihtout profile):\n");
				p = p2;
				score = score2;
				break;
			case 2:
				printf("Highscore of Puzzletube Survival (without profile):\n");
				p = p3;
				score = score3;
				break;
		}
		if (p && spNetC4AGetStatusParallel(p) == SP_C4A_OK)
		{
			spNetC4AScorePointer mom = score;
			while (mom)
			{
				struct tm * local = localtime (&(mom->commitTime));
				printf("  %2i: %2i.%2i.%i - %2i:%02i: %s (%s) - %i\n",mom->rank,local->tm_mday,local->tm_mon+1,local->tm_year+1900,local->tm_hour,local->tm_min,mom->longname,mom->shortname,mom->score);
				mom = mom->next;
			}
			spNetC4ADeleteScores(&score);
		}
		else
		if (p == NULL)
			printf("Fetshing Highscore failed with error code: 0\n");
		else
			printf("Fetshing Highscore failed with status code: %i\n",spNetC4AGetStatusParallel(p));
		spNetC4ADeleteTask(p);
	}
	//Client setup
	spNetIP ip;
	if (argc < 2)
	{
		ip = spNetResolve("localhost",12345);
		printf("Connection to localhost\nUse ./testnet.sh SERVER to specify another server to connect to!\n");
	}
	else
	{
		printf("Connecting to %s\n",argv[1]);
		ip = spNetResolve(argv[1],12345);
	}
	client_connection = spNetOpenClientTCP(ip);
	if (client_connection == NULL)
		printf("No client_connection! I will crash!\n");
	
	do_stuff();
	
	spNetCloseTCP(client_connection);
	
	//After the loop because spNetC4AGetScore works in the background. ;)

	spQuitNet();
	return 0;
}