This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Changed end of line char from \n to \0

Discussion of Eggdrop's code and module programming in C.
Post Reply
N
NetRider
Voice
Posts: 2
Joined: Tue May 17, 2005 7:30 pm

Changed end of line char from \n to \0

Post by NetRider »

Hey,
I installed my own version of undernet ircu server.
In order to allow a flash chat client to connect, I had to change the end of line character from \n to \0
It now looks like:
mb->msg[mb->length++] = '\r'; /* add \r\n to buffer */
mb->msg[mb->length++] = '\0';
mb->msg[mb->length++] = '\n';
mb->msg[mb->length] = '\0'; /* not strictly necessary */

The bold line was added by me, and now mirc works fine, and the flash client works fine. but eggdrop has problems.

I enabled raw log in eggdrop, and saw that eggdrop receive all data, it can see a user joining, parting and also joins its own channels.

But it still shows its not on a channel. also it doesnt react on any text sent from the server. no modes, no join parts and so on.

Could someone help me modify eggdrop to react on these, or maybe a fix to the server code I submitted, so it can allow both flash clients and eggdrop.

thanks
G
Galadhrim
Op
Posts: 123
Joined: Fri Apr 11, 2003 8:38 am
Location: Netherlands, Enschede

Post by Galadhrim »

i would say that the fault is in the Flash client rather than the IRCu code, since mIRC and eggdrop both work with the original code.

I don't see how your code adds anything as the \r\n is meant to be together rather than separated. \r is a carriage return and \n new line. Separating these will work under Windows but not under Linux I guess. Seeing as the snippit you gave already had a line with \0 in it I cannot see how the first \0 works.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

okay my guess:
if I correctly remeber my programming times, \0 indicates the end of a string. Sooo, lets see, your buffer ending will look like:
0D 00 0A 00

however, for eggdrop the end of a line is 0A, but the bot will stop phrasing the string at the first 00... its the end of the string !!! so it will never phrase 0A (\n) so it never sees the EOL and probably just discards the string :).
solution: remove the first 00 again. try to remove the 0D instead, mIRC should even work with 0A line ends. Or try to add a double 00 at the end or switch 0D and 0A in your orignal version. Meaning try these:

\r \n \0 (maybe it was something else, verification makes wise)
\n \0
\n \0 \r \0
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
G
Galadhrim
Op
Posts: 123
Joined: Fri Apr 11, 2003 8:38 am
Location: Netherlands, Enschede

Post by Galadhrim »

\0 means null in a string :) often used to make sure that memory space is really empty.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

Galadhrim wrote:\0 means null in a string :) often used to make sure that memory space is really empty.
just for I took out my old C book, and it clearly says that strings REQUIRE to be terminated with \0!

Im triing to translate (im too lazy to write better english ^^):
It seems that in the above array while saving the string "Zeichenkette" one array element - the 13th - keeps unused. But actually you need for saving strings not only 12, but 13 array elements, because in the diffrence to data objects of other types strings must be terminated wtih a special character. This character which marks the end of a string is the zero character '\0', ...
So just give it a try... :).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
G
Galadhrim
Op
Posts: 123
Joined: Fri Apr 11, 2003 8:38 am
Location: Netherlands, Enschede

Post by Galadhrim »

strange book... I learned that \0 is not needed but can prevent certain unwanted "features".
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

hm.. maybe not for strings with fixed length, but it is definitely needed for strings with varying length.
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

arcane wrote:hm.. maybe not for strings with fixed length, but it is definitely needed for strings with varying length.
a string with a fixed length is called "constant" and isn't saved in a "variable" (or better a char array), is it? :)

but seems it's either working or he has lost intrest in it ;).

PS: the book is 10 years old, but I somehow doubt C has changed that much since then.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

De Kus wrote:
arcane wrote:hm.. maybe not for strings with fixed length, but it is definitely needed for strings with varying length.
a string with a fixed length is called "constant" and isn't saved in a "variable" (or better a char array), is it? :)
no. a "constant" is basically a variable with unchanging content. a "variable" is basically everything, you can store values in.
as for C: unless you don't use a special "string" class, every string is a char array (well, in that string class as well, but you don't see that while coding ;)).
De Kus wrote:PS: the book is 10 years old, but I somehow doubt C has changed that much since then.
doubt that as well ;)
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

If you have an array of 20 elements (char string), this array can take for example 19 characters and the last element would be \0 (but you don't need to put it). So if you want to check the end of the string you can check if it's equal to \0.
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

yes, but
Sir_Fz wrote:(but you don't need to put it)
let's say "you don't always need to put it" ;)
there are some functions that require a string to be "null-terminated".
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
N
NetRider
Voice
Posts: 2
Joined: Tue May 17, 2005 7:30 pm

Post by NetRider »

Thanks for the help guys.

I found it would be easier to write a simle proxy in perl, which would just remove the \0 from the string sent by the server, rather than experimenting with the eggdrop code.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

from RFC1459 (Internet Relay Chat protocol):
IRC messages are always lines of characters terminated with a CR-LF
(Carriage Return - Line Feed) pair, and these messages shall not
exceed 512 characters in length, counting all characters including
the trailing CR-LF. Thus, there are 510 characters maximum allowed
for the command and its parameters. There is no provision for
continuation message lines.
i.e. your server is no longer compliant with the IRC protocol, whereas eggdrop tries to be (compliant)
Post Reply