Anope IRC Services
Anope Development => Modules => Topic started by: Anthony on February 06, 2011, 12:47:13 PM
-
Hello,
I am developing a module for my IRC network and I can't get some of the code to work.
I have the following:
int os_add_member(User *u)
{
char *nick;
buf = moduleGetLastBuffer();
nick = myStrGetToken(buf, ' ', 0);
privmsg(s_NickServ, "#channel", "%s has been added", nick);
}
However when I run the command I like so:
ADDMEMBER John
I get the following as a privmsg:
<NickOP> pµê has been added
<NickOP> @¹ê has been added
<NickOP> ¼ê has been added
As you can see, it appears to be printing the pointer, rather than the string.
I assume that's why it varies each time I run it.
How do I get it to print the value of nick?
Thank you :)
-
is this just an excerpt or is this the whole stuff?
Reason I am asking is that there doesn't seem to be a declaration of the "buf" pointer..
-
Hey Jan,
This in an excerpt. buf is defined as char *buf
Thank you
-
can you post working code that has the issue.. something I could just compile and see it do what you mentioned.
-
Hello Jan,
The only thing missing is the declarations and init function but I am more than happy to post this.
#include "module.h"
#define AUTHOR "Anthony Myatt"
#define VERSION "1.0.0"
#define MODNAME "os_tribefm"
int os_add_member(User *u);
int AnopeInit(int argc, char **argv) {
moduleAddAuthor(AUTHOR);
moduleAddVersion(VERSION);
Command *c1;
c1 = createCommand("ADD_MEMBER", os_add_member, is_services_admin, -1, -1, -1, -1, -1);
moduleAddCommand(OPERSERV, c1, MOD_HEAD);
return MOD_CONT;
}
int os_add_member(User *u) {
char *buf, *nick, *pass, *email;
buf = moduleGetLastBuffer();
nick = myStrGetToken(buf, ' ', 0);
pass = myStrGetToken(buf, ' ', 1);
email = myStrGetToken(buf, ' ', 2);
privmsg(s_NickServ, "#TribeFM", "%s has been added.", nick);
return MOD_STOP;
}
Thank you for your help :)
-
that code looks fine to me, and when loading it, it also works fine... :)
-
Maybe a memory leak? :s
-
/me feels stupid now.
Thank you for your help Jan. Maybe I should post the entire module next time :s
I found out that I was doing free(nick) in a seperate function just before calling the privmsg command in the function I thought was failing.
Working like a charm :D
-
hence why I asked you to post the code with which to reproduce.. posting excerpts is usually utterly useless...