Jump to content
  • Advertisement
Sign in to follow this  
Butterman

Annoying Problem

This topic is 4115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive been stuck with this for about a week. Im almost certain im setting a variable to '1'. Yet it seems to stay at '0'.
void Networking::LogIn(char *user, char *pass)
{
	if(Connected == 0)
	{
		Connected = 1;
		char *version = "first";
		server_sock=SDLNet_TCP_Open(&server_ip);

		if(!server_sock) 
		{
			Connected = 0;
			fprintf(stdout, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
		}

		if(Connected == 1)
		{
			int version = 001;
			putMsg(server_sock,mformat("dcscs",version,'|',user,'|',pass));
			Connected = 1;
			
		}
	}
}

void Networking::CheckMessages()
{
	
	char *buffer = NULL;
	if(Authenticated == false)
	{
		printf("%d",Connected);
		if(Connected == 1)
		{
			printf("Waiting for message\n");
			if(getMsg(server_sock,&buffer))
			{
				printf("Got Message\n");
				printf("s%\n",buffer);
				if(strcmp(buffer,"LOG|OK") == 0)
				{
					Authenticated = true;
					printf("Connected\n");
				}
			}
		}

	}

}



CheckMessages() is run on every loop. And im certain LogIn() is run because the server recieves the message sent here:
putMsg(server_sock,mformat("dcscs",version,'|',user,'|',pass));
Yet the whole time. Connected is set to 0. (Im sure of this because printf() outputs 0. Help me! This is driving me crazzzyyy!

Share this post


Link to post
Share on other sites
Advertisement
Have you stepped through the code in a debugger yet? If not do that. It'll reveal your bug pretty quickly.

Othewise I don't see anything that would be setting it to zero unless this code block is getting executed:


if(!server_sock)
{
Connected = 0;
fprintf(stdout, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
}




Just as a comment there's no reason to be setting Connected to 1 again inside this block:


if(Connected == 1)
{
int version = 001;
putMsg(server_sock,mformat("dcscs",version,'|',user,'|',pass));

//this line is redundant. we wouldn't be in this code block unless
//Connected is already 1
Connected = 1;
}


Share this post


Link to post
Share on other sites
Yea i know. But im getting soo pissed off i put it there anyway. Ive been trying everything. Irritatingly SDL realy does not like my VSC debugger, it just crashes on start.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!