前面在为unrealircd增加mysql连接中涉及到要为unrealircd添加配置项,下面一步一步说明如何操作:
一、打开unraelircd.conf,在最后面加上如下内容:
1
set
{
2
/*
Mysql connect config
*/
3
mysql
-
host
"
localhost
"
;
4
mysql
-
user
"
root
"
;
5
mysql
-
pass
"
123456
"
;
6
mysql
-
database
"
iuircd
"
;
7
};
上面的内容你可以加在文件尾部,也可以找到原来的set项,把这四个变量值加进去。
二、打开unrealircd/include/dynconf.h,在150行左右,修改如下代码:
1 int timesynch_timeout;
2 char *timesynch_server;
3 int pingpong_warning;
4 aNetwork network;
5 //add by oldhawk
6 char *mysql_host;
7 char *mysql_user;
8 char *mysql_pass;
9 char *mysql_database;
10 //add end
11
在270行左右,修改如下代码:
#define TIMESYNCH iConf.timesynch_enabled
#define TIMESYNCH_TIMEOUT iConf.timesynch_timeout
#define TIMESYNCH_SERVER iConf.timesynch_server
#define PINGPONG_WARNING iConf.pingpong_warning
//add by oldhawk
#define MYSQL_HOST iConf.mysql_host
#define MYSQL_USER iConf.mysql_user
#define MYSQL_PASS iConf.mysql_pass
#define MYSQL_DATABASE iConf.mysql_database
//add end
在380行左右,修改如下代码:
unsigned has_options_allow_part_if_shunned:1;
int cgiirc_type; /* cheat :( */
unsigned has_cgiirc_hosts:1;
unsigned has_cgiirc_webpass:1;
//add by oldhawk
unsigned has_mysql_host:1;
unsigned has_mysql_user:1;
unsigned has_mysql_pass:1;
unsigned has_mysql_database:1;
//add end
三、打开unrealircd/src/s_conf.c,在1500行左右,修改如下代码:
1 ircfree(i->network.x_prefix_quit);
2 ircfree(i->network.x_helpchan);
3 ircfree(i->network.x_stats_server);
4 ircfree(i->spamfilter_ban_reason);
5 ircfree(i->spamfilter_virus_help_channel);
6 ircfree(i->spamexcept_line);
7 //add by oldhawk
8 ircfree(i->mysql_host);
9 ircfree(i->mysql_user);
10 ircfree(i->mysql_pass);
11 ircfree(i->mysql_database);
12 //add end
13
上面的修改,如果你配置的值是数字型的就免了吧,不用free,如果是字符串型的,则不能少。
在2430行左右,修改如下代码:
if (!settings.has_help_channel)
Error("set::help-channel is missing");
if (!settings.has_hiddenhost_prefix)
Error("set::hiddenhost-prefix is missing");
//add by oldhawk
if (!settings.has_mysql_host)
Error("set::mysql-host is missing");
if (!settings.has_mysql_user)
Error("set::mysql-user is missing");
if (!settings.has_mysql_pass)
Error("set::mysql-pass is missing");
if (!settings.has_mysql_database)
Error("set::mysql-database is missing");
//add end
继续往下,在7041行左右,修改如下代码:
#endif
}
//add by oldhawk
else if (!strcmp(cep->ce_varname, "mysql-host")) {
ircstrdup(tempiConf.mysql_host, cep->ce_vardata);
}
else if (!strcmp(cep->ce_varname, "mysql-user")) {
ircstrdup(tempiConf.mysql_user, cep->ce_vardata);
}
else if (!strcmp(cep->ce_varname, "mysql-pass")) {
ircstrdup(tempiConf.mysql_pass, cep->ce_vardata);
}
else if (!strcmp(cep->ce_varname, "mysql-database")) {
ircstrdup(tempiConf.mysql_database, cep->ce_vardata);
}
//add end
else
再继续,马上就要结束了,在7959行左右,修改如下代码:
#endif
}
//add by oldhawk
else if (!strcmp(cep->ce_varname, "mysql-host")) {
CheckNull(cep);
CheckDuplicate(cep, mysql_host, "mysql-host");
}
else if (!strcmp(cep->ce_varname, "mysql-user")) {
CheckNull(cep);
CheckDuplicate(cep, mysql_user, "mysql-user");
}
else if (!strcmp(cep->ce_varname, "mysql-pass")) {
CheckNull(cep);
CheckDuplicate(cep, mysql_pass, "mysql-pass");
}
else if (!strcmp(cep->ce_varname, "mysql-database")) {
CheckNull(cep);
CheckDuplicate(cep, mysql_database, "mysql-database");
}
//add end
else
好了,虽然修改的地方比较多,但还是很容易,如果以后想自已增加更多的配置项的时候,就按照这个步骤来吧,其实你可以参照原来的代码,比如对配置项的值做一些处理,像数值太大或大小,或小于0,等等。多看原来的代码,相信你会很快熟悉起来的。
现在编译后,你就可以在代码中使用这样的配置变量了。