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
And the receive_chat function
Thanks,
Orion
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