- The IRC bot now reads a configuration file (irc.c) instead of it all being hardcoded

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@5958 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
Zido 2006-04-08 12:09:36 +00:00
parent 2113db40cb
commit cb78101f64
5 changed files with 102 additions and 6 deletions

View File

@ -4,6 +4,8 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2006/04/08 2006/04/08
* Added irc_athena.conf :) from now on, set your irc configuration in
conf/irc_athena.conf [Zido]
* Removed the baby class check when using "changebase" to change to the * Removed the baby class check when using "changebase" to change to the
Wedding Sprite, since it fixes the bug that the sprite doesn't show Wedding Sprite, since it fixes the bug that the sprite doesn't show
at all, and baby classes arn't messed up by it anymore. at all, and baby classes arn't messed up by it anymore.

36
conf-tmpl/irc_athena.conf Normal file
View File

@ -0,0 +1,36 @@
// ______ __ __
// /\ _ \/\ \__/\ \
// __\ \ \L\ \ \ ,_\ \ \___ __ ___ __
// /'__`\ \ __ \ \ \/\ \ _ `\ /'__`\/' _ `\ /'__`\
///\ __/\ \ \/\ \ \ \_\ \ \ \ \/\ __//\ \/\ \/\ \L\.\_
//\ \____\\ \_\ \_\ \__\\ \_\ \_\ \____\ \_\ \_\ \__/.\_\
// \/____/ \/_/\/_/\/__/ \/_/\/_/\/____/\/_/\/_/\/__/\/_/
// _ _ _ _ _ _ _ _ _ _ _ _ _
// / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
//( e | n | g | l | i | s | h ) ( A | t | h | e | n | a )
// \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
//
//--------------------------------------------------------
// eAthena IRC Bot Configuration File
//--------------------------------------------------------
//Turn the IRC Bot 'on' or 'off'
use_irc: off
//IRC Server Address
irc_server: irc.deltaanime.net
//IRC Server Port
irc_port: 6667
//IRC Channel
irc_channel: #
//IRC Trade Channel
irc_trade_channel: #
//IRC Nickname
irc_nick:
//IRC Password ("0" for no pass)
irc_pass: 0

View File

@ -15,6 +15,7 @@ typedef int socklen_t;
#include <netdb.h> #include <netdb.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h>
#ifndef SIOCGIFCONF #ifndef SIOCGIFCONF
#include <sys/sockio.h> // SIOCGIFCONF on Solaris, maybe others? [Shinomori] #include <sys/sockio.h> // SIOCGIFCONF on Solaris, maybe others? [Shinomori]
@ -54,7 +55,7 @@ char irc_channel[32]="";
char irc_trade_channel[32]=""; char irc_trade_channel[32]="";
unsigned char irc_ip_str[128]=""; unsigned char irc_ip_str[128]="";
unsigned long irc_ip=6667; unsigned long irc_ip=0;
unsigned short irc_port = 6667; unsigned short irc_port = 6667;
int irc_fd=0; int irc_fd=0;
@ -241,6 +242,8 @@ void irc_parse_sub(int fd, char *incoming_string)
irc_send(send_string); irc_send(send_string);
sprintf(send_string, "JOIN %s", irc_channel); sprintf(send_string, "JOIN %s", irc_channel);
irc_send(send_string); irc_send(send_string);
sprintf(send_string,"NAMES %s",irc_channel);
irc_send(send_string);
irc_si->state = 2; irc_si->state = 2;
} }
else if(!strcmp(command,"433")){ else if(!strcmp(command,"433")){
@ -460,3 +463,53 @@ int irc_rmnames() {
return 0; return 0;
} }
int irc_read_conf(char *file) {
FILE *fp=NULL;
char w1[256];
char w2[256];
char path[256];
char row[1024];
memset(w1,'\0',256);
memset(w2,'\0',256);
memset(path,'\0',256);
memset(row,'\0',256);
sprintf(path,"conf/%s",file);
if(!(fp=fopen(path,"r"))) {
ShowError("Cannot find file: %s\n",path);
return 0;
}
while(fgets(row,1023,fp)!=NULL) {
if(row[0]=='/'&&row[1]=='/')
continue;
sscanf(row,"%[^:]: %255[^\r\n]",w1,w2);
if(strcmpi(w1,"use_irc")==0) {
if(strcmpi(w2,"on")==0)
use_irc=1;
else
use_irc=0;
}
else if(strcmpi(w1,"irc_server")==0)
strcpy(irc_ip_str,w2);
else if(strcmpi(w1,"irc_port")==0)
irc_port=atoi(w2);
else if(strcmpi(w1,"irc_channel")==0)
strcpy(irc_channel,w2);
else if(strcmpi(w1,"irc_trade_channel")==0)
strcpy(irc_trade_channel,w2);
else if(strcmpi(w1,"irc_nick")==0)
strcpy(irc_nick,w2);
else if(strcmpi(w1,"irc_pass")==0) {
if(strcmpi(w2,"0")!=0)
strcpy(irc_password,w2);
}
}
ShowInfo("IRC Config read successfully\n");
return 1;
}

View File

@ -1,5 +1,8 @@
#include "map.h" #include "map.h"
// IRC .conf file [Zido]
#define IRC_CONF "irc_athena.conf"
// IRC Access levels [Zido] // IRC Access levels [Zido]
#define ACCESS_OWNER 5 #define ACCESS_OWNER 5
#define ACCESS_SOP 4 #define ACCESS_SOP 4
@ -44,8 +47,9 @@ struct channel_data {
}user[MAX_CHANNEL_USERS]; }user[MAX_CHANNEL_USERS];
}; };
int parse_names_packet(char *str); int parse_names_packet(char *str); // [Zido]
int parse_names(char *str); int parse_names(char *str); // [Zido]
int set_access(char *nick,int level); int set_access(char *nick,int level); // [Zido]
int get_access(char *nick); int get_access(char *nick); // [Zido]
int irc_rmnames(void); int irc_rmnames(void); // [Zido]
int irc_read_conf(char *file); // [Zido]

View File

@ -3812,6 +3812,7 @@ int do_init(int argc, char *argv[]) {
} }
map_config_read(MAP_CONF_NAME); map_config_read(MAP_CONF_NAME);
irc_read_conf(IRC_CONF); // [Zido]
chrif_checkdefaultlogin(); chrif_checkdefaultlogin();
if ((naddr_ == 0) && (map_ip_set_ == 0 || char_ip_set_ == 0)) { if ((naddr_ == 0) && (map_ip_set_ == 0 || char_ip_set_ == 0)) {