2 registered members (AndrewAMD, 7th_zorro),
1,285
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
[ENET] - Chat problems
#319754
04/17/10 15:09
04/17/10 15:09
|
Joined: Jan 2006
Posts: 29
oriongu
OP
Newbie
|
OP
Newbie
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
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
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
Senior Member
|
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"); ?
|
|
|
Re: [ENET] - Chat problems
[Re: oriongu]
#319779
04/17/10 17:18
04/17/10 17:18
|
Joined: Jun 2008
Posts: 428
Rasch
Senior Member
|
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
|
|
|
Re: [ENET] - Chat problems
[Re: Rasch]
#319780
04/17/10 17:40
04/17/10 17:40
|
Joined: Jan 2006
Posts: 29
oriongu
OP
Newbie
|
OP
Newbie
Joined: Jan 2006
Posts: 29
|
Thanks for the help ! We are almost there 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
Senior Member
|
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?
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
oriongu
OP
Newbie
|
OP
Newbie
Joined: Jan 2006
Posts: 29
|
That was just about it. I've added an else for the client too.
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 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
Senior Member
|
Senior Member
Joined: Jun 2008
Posts: 428
|
|
|
|
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
Serious User
|
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
|
|
|
|