So I'm working on an IRC plugin of my own.
To make things easier, I made an irc_print() function which formats and prints strings for me:
PHP Code:
public irc_print(msg[], ...) {
new str[513];
vformat(str, charsmax(str), msg, 2);
server_print("[kirc] <- %s", str);
}
In case someone is not familiar with the vformat() function (string.inc):
Quote:
/* Replacement for format_args. Much faster and %L compatible.
* This works exactly like vsnprintf() from C.
* You must pass in the output buffer and its size,
* the string to format, and the number of the FIRST variable
* argument parameter. For example, for:
* function (a, b, c, ...)
* You would pass 4 (a is 1, b is 2, c is 3, et cetera).
* There is no vformatex().
*/
native vformat(buffer[], len, const fmt[], vararg);
|
I call the function via irc_print("%s", str).
(I realize that the whole formatting is unnecessary in this case but I plan to use the function like irc_print("%s asdf %s, strx, stry) in the future.)
Now my irc_recv() function, which receives and splits the raw IRC messages, passes each message to irc_print():
PHP Code:
public irc_recv() {
if (!socket_change(sock)) {
return;
}
new recv[2048], buf[2048];
socket_recv(sock, recv, charsmax(recv));
strcat(sockread, recv, charsmax(sockread));
for (new i=0; i < strlen(sockread); i++) {
if (sockread[i] == '^n') {
server_print("%s", buf);
//irc_print("%s", buf);
buf[0] = 0;
}
else if (sockread[i] != '^r') {
strcat(buf, sockread[i], strlen(buf)+1);
}
}
copy(sockread, charsmax(sockread), buf);
}
(Note: The sockread variable is defined globally at the beginning of the script: new sockread[2048];)
As you can see, my irc_print() call is currently commented out and I'm using the default core function server_print() instead.
That's because, when I do use my irc_print(), it only prints blank lines for some reason:
Quote:
[AMXX] Loaded 5 admins from file
[kirc] ** connecting to irc.server.net:6667
opening socket
[kirc] -> NICK k-kirc
[kirc] -> USER k 8 * :HLDS
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
Executing AMX Mod X Configuration File
couldn't exec listip.cfg
Menu item 17 added to Menus Front-End: "Plugin Cvars" from plugin "pluginmenu.amxx"
Menu item 18 added to Menus Front-End: "Plugin Commands" from plugin "pluginmenu.amxx"
(...) // blank lines here
Connection to Steam servers successful.
VAC secure mode is activated.
(...) // more blank lines here ...
|
Note: The amount of blank lines might resemble the amount of calls to irc_print()/the amount of messages.
Using server_print() works well:
Quote:
[AMXX] Loaded 5 admins from file
[kirc] ** connecting to irc.server.net:6667
opening socket
[kirc] -> NICK k-kirc
[kirc] -> USER k 8 * :HLDS
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
Executing AMX Mod X Configuration File
couldn't exec listip.cfg
Menu item 17 added to Menus Front-End: "Plugin Cvars" from plugin "pluginmenu.amxx"
Menu item 18 added to Menus Front-End: "Plugin Commands" from plugin "pluginmenu.amxx"
:irc.server.net 439 * :Please wait while we process your connection.
:irc.server.net NOTICE AUTH :*** Found your hostname (cached)
:irc.server.net NOTICE AUTH :*** Checking Ident
:irc.server.net NOTICE AUTH :*** Got Ident response
(...)
|
Now When try to print the messages with both functions in this order, i. e.
PHP Code:
server_print("%s", buf);
irc_print("%s", buf);
it results in only the very first message being printed once by server_print(), followed by nothing but blank lines, not even further calls to server_print() still work:
Quote:
[AMXX] Loaded 5 admins from file
[kirc] ** connecting to irc.server.net:6667
opening socket
[kirc] -> NICK k-kirc
[kirc] -> USER k 8 * :HLDS
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
Executing AMX Mod X Configuration File
couldn't exec listip.cfg
Menu item 17 added to Menus Front-End: "Plugin Cvars" from plugin "pluginmenu.amxx"
Menu item 18 added to Menus Front-End: "Plugin Commands" from plugin "pluginmenu.amxx"
:irc.server.net 439 * :Please wait while we process your connection.
(...) // blank lines as of here
|
I checked the length of that first message and it's correct (64), no strange characters in it or anything.
Then I thought, well, maybe there's some issue with my irc_print() in combination with that particular string for whatever reason, so I tried this:
PHP Code:
new wtf[] = ":irc.server.net 439 * :Please wait while we process your connection.";
irc_print("%s", wtf);
And it works well.
I don't get it.
In irc_recv(), server_print() works and irc_print() fails. Manually passing the exact same string to irc_print() works, though.
So I'm seriously lost here.
I'd greatly appreciate it if someone took the time to read this and maybe has some idea. :(
Edit:
So I noticed that even if I remove the server_print() from my irc_print() I still have the same blank lines issue.
And then someone pointed the following line out to me:
PHP Code:
strcat(buf, sockread[i], strlen(buf)+1);
Originally I had put charsmax(buf) as maxlength but then it filled buf with sockread[i] and all the following characters.
I only wanted it to append that one single character to buf, though, so I ended up putting strlen(buf).
But since IRC messages usually cannot be longer than 512 characters anyway, this should be no issue, I just realized.
Anyway, the whole loop in irc_recv() should probably be rewritten anyway to avoid doing things char by char when I only need to look for \r\n and grab everything in front of it.
So I still don't know what the issue is but I'm willing to rewrite that loop tomorrow, I'm still open for ideas.