[ENET] - Chat problems

Posted By: oriongu

[ENET] - Chat problems - 04/17/10 15:09

Hey,

I'm having problem with the chat i'm making.

Everything works, the only problem is that the serv/client receives the message 2 times...between 2 clients, it works fine.

The startup function
Code:
function chat_startup()
{
	while(enet_get_connection() == NO_CONNECTION) {wait(1);} //wait until a host is initialized

	// reglages de quelques parametres d'interfaces
	Chat_pan.pos_y = screen_size.y - 155;
	Chat_pan.flags |= VISIBLE;
	chat_txt.pos_y = screen_size.y - 150;
	chat_txt.pos_x = 0;
	chat_txt.flags |= VISIBLE;	
	inkey_chatmsg_text.pos_y = screen_size.y - 45;
	
	while(1)
	{
		//If not server and key [c] is pressed
		if(key_c == ON && enet_get_connection() != SERVER_MODE)
		{
			inkey_chatmsg_text.flags |= VISIBLE; //shows the inputtext
			str_clip(chat_input,str_len(chat_input)); //cleares the input string
			inkey(chat_input); //starts the input
			inkey_chatmsg_text.flags &= ~VISIBLE;
			
			STRING* tmpPlayerName = str_create("#25");
			enet_get_playername(enet_get_clientid(),tmpPlayerName);
			
			STRING* tmpMsg = str_create("#25");
			str_cpy(tmpMsg, "  (");
			str_cat(tmpMsg, getTheTime());
			str_cat(tmpMsg, ") ");
			str_cat(tmpMsg, tmpPlayerName);
			str_cat(tmpMsg, ": ");
			str_cat(tmpMsg, chat_input);
			
			enet_clsend_event(17,tmpMsg,0,BROADCAST); //sends the chat msg to everyone
		}
		wait(1);
	}
}




And the receive_chat function
Code:
function receive_chatmsg(var sender, STRING* msg)
{
	TEXT* entity_text = NULL; //stores the TEXT pointer of the player entity
	STRING* save_string = "#100"; //stores the msg string, because it's only 1 frame available
	str_cpy(save_string,msg);
	str_cpy(strChat0, strChat1);
	str_cpy(strChat1, strChat2);
	str_cpy(strChat2, strChat3);
	str_cpy(strChat3, strChat4);
	str_cpy(strChat4, strChat5);
	str_cpy(strChat5, strChat6);
	str_cpy(strChat6, strChat7);
	str_cpy(strChat7, strChat8);
	str_cpy(strChat8, strChat9);
	str_cpy(strChat9, save_string);
}



Thanks,
Orion
Posted By: Rasch

Re: [ENET] - Chat problems - 04/17/10 16:29

receive_chatmsg

maybe it is a problem with the definiton. Is ist a sv_ or a cl_ event? Maybe you have both server and client events for the same one.

enet_svset_event(17,"receive_chatmsg");
enet_clset_event(17,"receive_chatmsg");

? laugh
Posted By: oriongu

Re: [ENET] - Chat problems - 04/17/10 17:15

Hello, thanks for your reply.

the events are set like this :

enet_svset_event(17,"receive_chatmsg");
enet_clset_event(17,"receive_chatmsg");

Now i understant why a serv/client receives the messages 2 times. But i'm not sure how to correct it. Make a specific function for the server?
Posted By: Rasch

Re: [ENET] - Chat problems - 04/17/10 17:18

If you start as a client/server i think this should be the solution:

delete this one: enet_svset_event(17,"receive_chatmsg");

and just use this one: enet_clset_event(17,"receive_chatmsg");

Because you are also logged in as a client. And the cl event will also start on your pc because your are CLIENT/server.

I hope this helps laugh
Posted By: oriongu

Re: [ENET] - Chat problems - 04/17/10 17:40

Thanks for the help !

We are almost there laugh if i launch as server/client, the messages are sent to all client, but not to himself...

The only i can correct is by adding this code in the startup function :
if(enet_get_connection() != SERVER_MODE)
{
str_cpy(strChat0, strChat1);
str_cpy(strChat1, strChat2);
str_cpy(strChat2, strChat3);
str_cpy(strChat3, strChat4);
str_cpy(strChat4, strChat5);
str_cpy(strChat5, strChat6);
str_cpy(strChat6, strChat7);
str_cpy(strChat7, strChat8);
str_cpy(strChat8, strChat9);
str_cpy(strChat9, tmpMsg);
}

With this code, it's works but it dosnt seems very optimize? i mean it should work whithout in theory no?
Posted By: Rasch

Re: [ENET] - Chat problems - 04/17/10 17:57

The problem is if you send it as BROADCAST it will be send to all client but not to your self. (Read the manual)

How about adding another Event send function just to yourself?

Code:
function chat_startup()
{
	// everything as it was
	
	while(1)
	{
		if(key_c == ON && enet_get_connection() != SERVER_MODE)
		{			
			enet_clsend_event(17,tmpMsg,0,BROADCAST); //sends the chat msg to everyone
			
			if(enet_get_connection() == CLIENT_SERVER_MODE)
			{
				enet_clsend_event(17,tmpMsg,0,enet_get_clientid()); //sends the chat msg to me
			}
		}
		wait(1);
	}
}


Posted By: oriongu

Re: [ENET] - Chat problems - 04/17/10 20:01

That was just about it. I've added an else for the client too.

Code:
if(enet_get_connection() == CLIENT_SERVER_MODE)
{				enet_clsend_event(17,tmpMsg,0,enet_get_clientid()); //sends the chat msg to me
}
else
{				enet_clsend_event(17,tmpMsg,0,enet_get_clientid()); //sends the chat msg to me
}



I now have a sweet chat working laugh

Thanks so much !
Posted By: Rasch

Re: [ENET] - Chat problems - 04/17/10 20:03

check your pmīs
Posted By: IvanOFF

Re: [ENET] - Chat problems - 05/27/10 00:48

inkey_chatmsg_text.flags |= VISIBLE; //shows the inputtext
str_clip(chat_input,str_len(chat_input)); //cleares the input string
inkey(chat_input); //starts the input
inkey_chatmsg_text.flags &= ~VISIBLE;

Problems plz Help! whot is Visimle
Posted By: Dark_samurai

Re: [ENET] - Chat problems - 05/27/10 20:28

Search for the word in a dictionary. In german it means "Sichtbar". So if you set visible you can see it. If you don't set it, you can't see it.
© 2024 lite-C Forums