Beispiel #1
0
void send_one_c4a_scores(int timeout_sec,int timeout_dec)
{
    switch (spNetC4AGetStatus())
    {
    case SP_C4A_PROGRESS:
        switch (score_col)
        {
        case 0:
            sprintf(c4aStatus,"Commit points scores. %i.%is",timeout_sec,timeout_dec);
            break;
        case 1:
            sprintf(c4aStatus,"Commit survival scores. %i.%is",timeout_sec,timeout_dec);
            break;
        case 2:
            sprintf(c4aStatus,"Commit race scores. %i.%is",timeout_sec,timeout_dec);
            break;
        }
        break;
    case SP_C4A_ERROR:
        sprintf(c4aStatus,"Error with connection");
        c4aErrorTimeOut = 20000;
        c4aState = -1;
        break;
    case SP_C4A_TIMEOUT:
        sprintf(c4aStatus,"Connection timeout");
        c4aErrorTimeOut = 20000;
        c4aState = -1;
        break;
    case SP_C4A_OK:
        c4aState = 0;
        break;
    }
}
Beispiel #2
0
void quit_c4a()
{
    int status = spNetC4AGetStatus();
    if (status != SP_C4A_OK && status != SP_C4A_ERROR)
        spNetC4ACancelTask();
    if (profile == NULL)
        return;
    spNetC4AFreeProfile(profile);
    spNetC4ADeleteScores(&pointsScore);
    spNetC4ADeleteScores(&survivalScore);
    spNetC4ADeleteScores(&raceScore);
}
Beispiel #3
0
void updateScores()
{
    if (profile == NULL)
        return;
    int status = spNetC4AGetStatus();
    if (status > 0)
        spNetC4ACancelTask();
    spNetC4ADeleteScores(&pointsScore);
    spNetC4ADeleteScores(&survivalScore);
    spNetC4ADeleteScores(&raceScore);
    c4aState = 1; //update
    spNetC4AGetScore(&pointsScore,profile,"puzzletube_points",TIME_OUT);
}
Beispiel #4
0
void draw_account(spFontPointer font,spFontPointer font_small,spFontPointer font_very_small)
{
	SDL_Surface* screen = spGetWindowSurface();
	spFontDrawRight( screen->w-2, 2, 0, "[X] Back", font_very_small );
	if (spGetVirtualKeyboardState() == SP_VIRTUAL_KEYBOARD_ALWAYS)	
		spFontDrawMiddle( screen->w*2/3, 2, 0, "[B] Enter letter", font_very_small );
	if (spGetVirtualKeyboardState() == SP_VIRTUAL_KEYBOARD_ALWAYS)
		spFontDraw( 2, 2, 0, "[L] & [R]: Select Row", font_very_small );
	else
		spFontDraw( 2, 2, 0, SP_PAD_NAME": Select Row", font_very_small );
	switch (mode)
	{
		case 0:
			spFontDrawMiddle( 2*screen->w/3, 1*screen->h/9, 0, ">>> Account Creating <<<", font);
			spFontDrawMiddle( 2*screen->w/3, 2*screen->h/11, 0, "Press [S] to create the account", font_small);
			break;		
		case 1:
			spFontDrawMiddle( 2*screen->w/3, 1*screen->h/9, 0, ">>> Account Editing <<<", font);
			spFontDrawMiddle( 2*screen->w/3, 2*screen->h/11, 0, "Press [S] to save the changes", font_small);
			spFontDrawMiddle( 2*screen->w/3, 2*screen->h/8, 0, "Press [E] to delete the account", font_small);
			break;		
	}
	
	char* mom_line = NULL;
	switch (line)
	{
		case 0: mom_line = shortName; break;
		case 1: mom_line = longName; break;
		case 2: mom_line = password; break;
		case 3: mom_line = mail; break;
	}
	spLine( 2*screen->w/3 + spFontWidth(mom_line,font)/2+1, (line*2+6)*screen->h/18, 0,
	        2*screen->w/3 + spFontWidth(mom_line,font)/2+1, (line*2+7)*screen->h/18, 0, ((blink/512)&1)?0:65535);
	
	spFontDrawRight( screen->w/3, 3*screen->h/9, 0, "3 Letter Nick:", font);
	spFontDrawMiddle( 2*screen->w/3, 3*screen->h/9, 0, shortName, font);
	spLine( screen->w/3+10, 7*screen->h/18, 0, screen->w-10, 7*screen->h/18,0,65535);
	spFontDrawMiddle( 2*screen->w/3, 7*screen->h/18, 0, "(e.g. JHN)", font_very_small);

	spFontDrawRight( screen->w/3, 4*screen->h/9, 0, "Display Nick:", font);
	spFontDrawMiddle( 2*screen->w/3, 4*screen->h/9, 0, longName, font);
	spLine( screen->w/3+10, 9*screen->h/18, 0, screen->w-10, 9*screen->h/18,0,65535);
	spFontDrawMiddle( 2*screen->w/3, 9*screen->h/18, 0, "(e.g. JohnSmith)", font_very_small);

	spFontDrawRight( screen->w/3, 5*screen->h/9, 0, "Password:"******"(alphanumeric, e.g. aBc123)", font_very_small);

	spFontDrawRight( screen->w/3, 6*screen->h/9, 0, "E-Mail address:", font);
	spFontDrawMiddle( 2*screen->w/3, 6*screen->h/9, 0, mail, font);
	spLine( screen->w/3+10, 13*screen->h/18, 0, screen->w-10, 13*screen->h/18,0,65535);
	spFontDrawMiddle( 2*screen->w/3, 13*screen->h/18, 0, "(for score being beaten notification)", font_very_small);
	if (spIsKeyboardPolled() && spGetVirtualKeyboardState() == SP_VIRTUAL_KEYBOARD_ALWAYS)
		spBlitSurface(screen->w/2,screen->h-spGetVirtualKeyboard()->h/2,0,spGetVirtualKeyboard());
	
	switch (askMode)
	{
		case 1:
			spInterpolateTargetToColor(0,3*SP_ONE/4);
			spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "Are you sure to delete your profile forever?", font);
			spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, "[S] Yes...     [X] Hell No!", font);
			break;
		case 2:
			spInterpolateTargetToColor(0,3*SP_ONE/4);
			spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "Your 3 Letter Nick needs 3 alphanumeric letters.", font);
			spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, "[B] Okay...", font);
			break;
		case 3:
			spInterpolateTargetToColor(0,3*SP_ONE/4);
			spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "Only numbers and characters are allowed for your Nick!", font);
			spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, "[B] Uuups...", font);
			break;
		case 4:
			spInterpolateTargetToColor(0,3*SP_ONE/4);
			spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "Only numbers and characters are allowed for passwords!", font);
			spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, "[B] Okay...", font);
			break;
		case 5:
			spInterpolateTargetToColor(0,3*SP_ONE/4);
			spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "IF you enter a e-mail, make sure it contains an @.", font);
			spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, "[B] Okay...", font);
			break;
		case 6:
			spInterpolateTargetToColor(0,3*SP_ONE/4);
			spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "Couldn't connect to Server! Check your connection.", font);
			spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, "[B] Ok", font);
			break;
		case 7:
			spInterpolateTargetToColor(0,3*SP_ONE/4);
			spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "Account created successfully", font);
			spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, "[B] Ok", font);
			break;
		case 8:
			spInterpolateTargetToColor(0,3*SP_ONE/4);
			spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "Account edited successfully", font);
			spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, "[B] Ok", font);
			break;
		case 9:
			spInterpolateTargetToColor(0,3*SP_ONE/4);
			spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "Account deleted successfully", font);
			spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, "[B] Ok", font);
			break;
	}	
	if (spNetC4AGetStatus() > 0)
	{
		spInterpolateTargetToColor(0,3*SP_ONE/4);
		spFontDrawMiddle( screen->w/2, screen->h/2-font->maxheight/2, 0, "Connecting to server...", font);
		char buffer[256];
		sprintf(buffer,"Timeout in %i.%i",spNetC4AGetTimeOut()/1000,(spNetC4AGetTimeOut()/100)%10);
		spFontDrawMiddle( screen->w/2, screen->h/2+font->maxheight/2, 0, buffer, font);
	}
}
Beispiel #5
0
int calc_account(Uint32 steps)
{
	blink+=steps;
	if (spNetC4AGetStatus() > 0)
	{
		right_after_status = 1;
		return 0;
	}
	if (right_after_status)
	{
		if (spNetC4AGetTaskResult() == 0)
		{
			mode = nextMode;
			askMode = last_task+7;
		}
		else
		{
			askMode = 6;
			spStopKeyboardInput();
		}
			
	}
	right_after_status = 0;
	if (askMode)
	{
		switch ( askMode )
		{
			case 1:
				if ( spGetInput()->button[SP_BUTTON_START_NOWASD] )
				{
					spGetInput()->button[SP_BUTTON_START_NOWASD] = 0;
					if (spNetC4ADeleteAccount(&profile,1,TIME_OUT) == 0)
					{
						right_after_status = 1;
						last_task = 2;
					}
					nextMode = 0;
					sprintf(longName,"");
					sprintf(shortName,"");
					sprintf(password,"");
					sprintf(mail,"");
					askMode = 0;
					switch (line)
					{
						case 0: spPollKeyboardInput(shortName,3,SP_PRACTICE_OK_NOWASD_MASK); break;
						case 1: spPollKeyboardInput(longName,256,SP_PRACTICE_OK_NOWASD_MASK); break;
						case 2: spPollKeyboardInput(password,256,SP_PRACTICE_OK_NOWASD_MASK); break;
						case 3: spPollKeyboardInput(mail,256,SP_PRACTICE_OK_NOWASD_MASK); break;
					}
				}
				if ( spGetInput()->button[SP_PRACTICE_CANCEL_NOWASD] )
				{
					spGetInput()->button[SP_PRACTICE_CANCEL_NOWASD] = 0;
					askMode = 0;
					switch (line)
					{
						case 0: spPollKeyboardInput(shortName,3,SP_PRACTICE_OK_NOWASD_MASK); break;
						case 1: spPollKeyboardInput(longName,256,SP_PRACTICE_OK_NOWASD_MASK); break;
						case 2: spPollKeyboardInput(password,256,SP_PRACTICE_OK_NOWASD_MASK); break;
						case 3: spPollKeyboardInput(mail,256,SP_PRACTICE_OK_NOWASD_MASK); break;
					}
				}
				break;
			default:
				if ( spGetInput()->button[SP_PRACTICE_OK_NOWASD] )
				{
					spGetInput()->button[SP_PRACTICE_OK_NOWASD] = 0;
					askMode = 0;
					switch (line)
					{
						case 0: spPollKeyboardInput(shortName,3,SP_PRACTICE_OK_NOWASD_MASK); break;
						case 1: spPollKeyboardInput(longName,256,SP_PRACTICE_OK_NOWASD_MASK); break;
						case 2: spPollKeyboardInput(password,256,SP_PRACTICE_OK_NOWASD_MASK); break;
						case 3: spPollKeyboardInput(mail,256,SP_PRACTICE_OK_NOWASD_MASK); break;
					}
				}
		}
		return 0;
	}
	if ( spGetInput()->button[SP_PRACTICE_CANCEL_NOWASD] )
	{
		spGetInput()->button[SP_PRACTICE_CANCEL_NOWASD] = 0;
		spStopKeyboardInput();
		return 1;
	}
	
	int i;
	for (i = 0; shortName[i] != 0; i++)
	{
		if ('a' <= shortName[i] && shortName[i] <= 'z')
			shortName[i] += 'A'-'a';
	}
		
	if ((spGetVirtualKeyboardState() == SP_VIRTUAL_KEYBOARD_ALWAYS && spGetInput()->button[SP_BUTTON_R_NOWASD]) ||
	    (spGetVirtualKeyboardState() != SP_VIRTUAL_KEYBOARD_ALWAYS && spGetInput()->axis[1] > 0))
	{
		line = (line + 1) % 4;
		spGetInput()->button[SP_BUTTON_R_NOWASD] = 0;
		if (spGetVirtualKeyboardState() != SP_VIRTUAL_KEYBOARD_ALWAYS)
			spGetInput()->axis[1] = 0;
		blink = 0;
		switch (line)
		{
			case 0: spPollKeyboardInput(shortName,3,SP_PRACTICE_OK_NOWASD_MASK); break;
			case 1: spPollKeyboardInput(longName,256,SP_PRACTICE_OK_NOWASD_MASK); break;
			case 2: spPollKeyboardInput(password,256,SP_PRACTICE_OK_NOWASD_MASK); break;
			case 3: spPollKeyboardInput(mail,256,SP_PRACTICE_OK_NOWASD_MASK); break;
		}
	}
	if ((spGetVirtualKeyboardState() == SP_VIRTUAL_KEYBOARD_ALWAYS && spGetInput()->button[SP_BUTTON_L_NOWASD]) ||
	    (spGetVirtualKeyboardState() != SP_VIRTUAL_KEYBOARD_ALWAYS && spGetInput()->axis[1] < 0))
	{
		line = (line + 3) % 4;
		spGetInput()->button[SP_BUTTON_L_NOWASD] = 0;
		if (spGetVirtualKeyboardState() != SP_VIRTUAL_KEYBOARD_ALWAYS)
			spGetInput()->axis[1] = 0;
		blink = 0;
		switch (line)
		{
			case 0: spPollKeyboardInput(shortName,3,SP_PRACTICE_OK_NOWASD_MASK); break;
			case 1: spPollKeyboardInput(longName,256,SP_PRACTICE_OK_NOWASD_MASK); break;
			case 2: spPollKeyboardInput(password,256,SP_PRACTICE_OK_NOWASD_MASK); break;
			case 3: spPollKeyboardInput(mail,256,SP_PRACTICE_OK_NOWASD_MASK); break;
		}
	}
	if ( spGetInput()->button[SP_BUTTON_START_NOWASD] )
	{
		spGetInput()->button[SP_BUTTON_START_NOWASD] = 0;
		if (check_shortname())
		{
			askMode = 2;
			spStopKeyboardInput();
		}
		else
		if (check_longname())
		{
			askMode = 3;
			spStopKeyboardInput();
		}
		else
		if (check_password())
		{
			askMode = 4;
			spStopKeyboardInput();
		}
		else
		if (check_mail())
		{
			askMode = 5;
			spStopKeyboardInput();
		}
		else
		{
			if (mode == 0)
			{
				if (spNetC4ACreateProfile(&profile,longName,shortName,password,mail,TIME_OUT) == 0)
				{
					right_after_status = 1;
					last_task = 0;
				}
				nextMode = 1;
			}
			else
			{
				if (spNetC4AEditProfile(&profile,longName,shortName,password,mail,TIME_OUT) == 0)
				{
					right_after_status = 1;
					last_task = 1;
				}
				nextMode = 1;
			}
		}
	}
	if ( mode == 1 && spGetInput()->button[SP_BUTTON_SELECT_NOWASD] )
	{
		 spGetInput()->button[SP_BUTTON_SELECT_NOWASD] = 0;
		 askMode = 1;
		 spStopKeyboardInput();
	}
	return 0;
}
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;
}
Beispiel #7
0
void calc_c4a(int steps)
{
    int timeout_sec;
    int timeout_dec;
    if (c4aErrorTimeOut > 0)
        c4aErrorTimeOut -= steps;
    if (profile == NULL)
        return;
    if (c4aState > 0)
    {
        timeout_sec = spNetC4AGetTimeOut() / 1000;
        timeout_dec = (spNetC4AGetTimeOut() / 100) % 10;
    }
    switch (c4aState)
    {
    case 1:
        switch (spNetC4AGetStatus())
        {
        case SP_C4A_PROGRESS:
            sprintf(c4aStatus,"Loading points highscore. %i.%is",timeout_sec,timeout_dec);
            break;
        case SP_C4A_ERROR:
            sprintf(c4aStatus,"Error with connection");
            c4aErrorTimeOut = 20000;
            c4aState = -1;
            break;
        case SP_C4A_TIMEOUT:
            sprintf(c4aStatus,"Connection timeout");
            c4aErrorTimeOut = 20000;
            c4aState = -1;
            break;
        case SP_C4A_OK:
            spNetC4AGetScore(&survivalScore,profile,"puzzletube_survival",TIME_OUT);
            c4aState = 2;
            break;
        }
        break;
    case 2:
        switch (spNetC4AGetStatus())
        {
        case SP_C4A_PROGRESS:
            sprintf(c4aStatus,"Loading survival highscore. %i.%is",timeout_sec,timeout_dec);
            break;
        case SP_C4A_ERROR:
            sprintf(c4aStatus,"Error with connection");
            c4aErrorTimeOut = 20000;
            c4aState = -1;
            break;
        case SP_C4A_TIMEOUT:
            sprintf(c4aStatus,"Connection timeout");
            c4aErrorTimeOut = 20000;
            c4aState = -1;
            break;
        case SP_C4A_OK:
            spNetC4AGetScore(&raceScore,profile,"puzzletube_race",TIME_OUT);
            c4aState = 3;
            break;
        }
        break;
    case 3:
        switch (spNetC4AGetStatus())
        {
        case SP_C4A_PROGRESS:
            sprintf(c4aStatus,"Loading race highscore. %i.%is",timeout_sec,timeout_dec);
            break;
        case SP_C4A_ERROR:
            sprintf(c4aStatus,"Error with connection");
            c4aErrorTimeOut = 20000;
            c4aState = -1;
            break;
        case SP_C4A_TIMEOUT:
            sprintf(c4aStatus,"Connection timeout");
            c4aErrorTimeOut = 20000;
            c4aState = -1;
            break;
        case SP_C4A_OK:
            score_row = 0;
            score_col = 0;
            init_score_commit();
            c4aState = 4;
            break;
        }
        break;
    case 4:
        send_c4a_scores(timeout_sec,timeout_dec);
        break;
    case 5:
        send_one_c4a_scores(timeout_sec,timeout_dec);
        break;
    }
}