Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (firecrest, AndrewAMD), 387 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[ENET] - Chat problems #319754
04/17/10 15:09
04/17/10 15:09
Joined: Jan 2006
Posts: 29
O
oriongu Offline OP
Newbie
oriongu  Offline OP
Newbie
O

Joined: Jan 2006
Posts: 29
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

Re: [ENET] - Chat problems [Re: oriongu] #319772
04/17/10 16:29
04/17/10 16:29
Joined: Jun 2008
Posts: 428
Rasch Offline
Senior Member
Rasch  Offline
Senior Member

Joined: Jun 2008
Posts: 428
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

Re: [ENET] - Chat problems [Re: Rasch] #319778
04/17/10 17:15
04/17/10 17:15
Joined: Jan 2006
Posts: 29
O
oriongu Offline OP
Newbie
oriongu  Offline OP
Newbie
O

Joined: Jan 2006
Posts: 29
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?

Re: [ENET] - Chat problems [Re: oriongu] #319779
04/17/10 17:18
04/17/10 17:18
Joined: Jun 2008
Posts: 428
Rasch Offline
Senior Member
Rasch  Offline
Senior Member

Joined: Jun 2008
Posts: 428
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

Re: [ENET] - Chat problems [Re: Rasch] #319780
04/17/10 17:40
04/17/10 17:40
Joined: Jan 2006
Posts: 29
O
oriongu Offline OP
Newbie
oriongu  Offline OP
Newbie
O

Joined: Jan 2006
Posts: 29
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?

Re: [ENET] - Chat problems [Re: oriongu] #319782
04/17/10 17:57
04/17/10 17:57
Joined: Jun 2008
Posts: 428
Rasch Offline
Senior Member
Rasch  Offline
Senior Member

Joined: Jun 2008
Posts: 428
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);
	}
}



Re: [ENET] - Chat problems [Re: Rasch] #319791
04/17/10 20:01
04/17/10 20:01
Joined: Jan 2006
Posts: 29
O
oriongu Offline OP
Newbie
oriongu  Offline OP
Newbie
O

Joined: Jan 2006
Posts: 29
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 !

Re: [ENET] - Chat problems [Re: oriongu] #319792
04/17/10 20:03
04/17/10 20:03
Joined: Jun 2008
Posts: 428
Rasch Offline
Senior Member
Rasch  Offline
Senior Member

Joined: Jun 2008
Posts: 428
check your pm´s

Re: [ENET] - Chat problems [Re: Rasch] #325525
05/27/10 00:48
05/27/10 00:48
Joined: May 2010
Posts: 13
I
IvanOFF Offline
Newbie
IvanOFF  Offline
Newbie
I

Joined: May 2010
Posts: 13
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

Re: [ENET] - Chat problems [Re: IvanOFF] #325727
05/27/10 20:28
05/27/10 20:28
Joined: Jul 2005
Posts: 1,930
Austria
Dark_samurai Offline
Serious User
Dark_samurai  Offline
Serious User

Joined: Jul 2005
Posts: 1,930
Austria
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.


ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)!
get free version

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1