|
[ANET] Send Username and Password with char
#342135
09/23/10 22:15
09/23/10 22:15
|
Joined: Jun 2008
Posts: 428
Rasch
OP
Senior Member
|
OP
Senior Member
Joined: Jun 2008
Posts: 428
|
Hi, i´m trying to send username and password via char array (hope this is the correct way) my script looks like this. Sending.
function login_start(var sender, STRING* msg)
{
inkey(username);
char sendchr[1];
sendchr[0] = username;
enet_clsend_event(19, sendchr, 1, SERVER);
}
how do i know receive this data? if i use a char pointer i only get annoying signs. Is therwe another way?
|
|
|
Re: [ANET] Send Username and Password with char
[Re: Rasch]
#342146
09/24/10 06:39
09/24/10 06:39
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Why don't you send the whole char array?
function login_start(var sender, STRING* msg)
{
char username[30];
inkey(username);
enet_clsend_event(19, username, str_len(username), SERVER);
}
function ev_username(var sender, STRING* msg, var size)
{
char username[30];
memcpy(username,_CHR(msg),size);
}
But why using a char array and not a String?
function login_start(var sender, STRING* msg)
{
STRING* username = "#30";
inkey(username);
enet_clsend_event(19, username, 0, SERVER);
}
function ev_username(var sender, STRING* msg, var size)
{
error(msg);
}
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: [ANET] Send Username and Password with char
[Re: Dark_samurai]
#342149
09/24/10 08:11
09/24/10 08:11
|
Joined: Jun 2008
Posts: 428
Rasch
OP
Senior Member
|
OP
Senior Member
Joined: Jun 2008
Posts: 428
|
Hi Samurai, thanks for the reply. I forgot soemthign in the script. I can use strings. It works good but i just want to have it easier. This is my real function atm.
function login_start(var sender, STRING* msg)
{
inkey(username);
inkey(password);
STRING* info_send = "";
str_cpy(info_send, username);
str_cat(info_send, ",");
str_cat(info_send, password);
enet_clsend_event(19, info_send, 0, SERVER);
}
I´m sending "username,password" to hte server. THe server receives this. I´m then using a method of str_len, str_trunc, str_clip to cut this info back into username and password. THat works. But is just too much of code. So i wanted it easier. How would it look now if i would send username and password together? (please use my code as example) A last question. What is the memcpy function? I dont have this command. Is it integrated in ANET? Really much thanks for your help
|
|
|
Re: [ANET] Send Username and Password with char
[Re: Rasch]
#342158
09/24/10 08:50
09/24/10 08:50
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
You could make a char array like that: [username][0][password][0] memcpy() is a windows function. It copies the the content of the array of the second parameter into the array of the first parameter. The third parameter determines the size of the content that should be copied. So you could do it like that:
function login_start(var sender, STRING* msg)
{
char temp_array[100];
inkey(username);
inkey(password);
memcpy(temp_array, username, str_len(username)+1); //also copies the zero termination of username
memcpy(&temp_array[str_len(username)], password, str_len(password)+1); //also copies the zero termination of password
enet_clsend_event(19, temp_array, str_len(username)+str_len(password)+2, SERVER);
}
function ev_username(var sender, STRING* msg, var size)
{
char temp_array[100];
char username[30];
char password[30];
memcpy(temp_array,_CHR(msg),size);
str_cpy(username, temp_array); //copies everything to the first zero termination
str_cpy(password, &temp_array[str_len(temp_array)+1]); //copies everything to the second zero termination
}
It's not shorter, but has the advantage that you can use "," in the username and password. Btw. it's not tested, so I can't guarantee that it's working.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: [ANET] Send Username and Password with char
[Re: Dark_samurai]
#342163
09/24/10 08:57
09/24/10 08:57
|
Joined: Jun 2008
Posts: 428
Rasch
OP
Senior Member
|
OP
Senior Member
Joined: Jun 2008
Posts: 428
|
Ok thanks that looks interesting. It´s a little bit shorter. Thats good I´ll try it out later. Thanks
|
|
|
|