summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-17 13:23:34 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-17 13:23:34 +0000
commit3a4984a967675b1fd10c84730994bf08766c639d (patch)
tree00be3127a35d41ecbf1cb8f3b56922cd3575f36b
parent1110866d367cb7a158e0b4c9dc2a16e15d3ca90d (diff)
downloadhercules-3a4984a967675b1fd10c84730994bf08766c639d.tar.gz
hercules-3a4984a967675b1fd10c84730994bf08766c639d.tar.bz2
hercules-3a4984a967675b1fd10c84730994bf08766c639d.tar.xz
hercules-3a4984a967675b1fd10c84730994bf08766c639d.zip
* Added flag.server to indicate interserver sockets
- replaces the previous way (setting 'client_addr' to 0) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11930 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--Changelog-Trunk.txt3
-rw-r--r--src/char/char.c16
-rw-r--r--src/char_sql/char.c16
-rw-r--r--src/common/socket.c22
-rw-r--r--src/common/socket.h13
-rw-r--r--src/ladmin/ladmin.c3
-rw-r--r--src/login/admin.c2
-rw-r--r--src/login/login.c6
-rw-r--r--src/login_sql/login.c6
-rw-r--r--src/map/chrif.c4
-rw-r--r--src/map/clif.c2
-rw-r--r--src/map/guild.c3
-rw-r--r--src/map/irc.c2
13 files changed, 53 insertions, 45 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index 58351e828..3d44a11df 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -3,6 +3,9 @@ Date Added
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
+2007/12/17
+ * Added flag.server to indicate interserver sockets
+ - replaces the previous way (setting 'client_addr' to 0)
2007/12/14
* Guardian hp handling code removal (see bugreport:342)
- removed guardian hp from the castle data structure, database,
diff --git a/src/char/char.c b/src/char/char.c
index 6a9e94696..c6cdf3f32 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -348,7 +348,7 @@ void set_char_online(int map_id, int char_id, int account_id)
delete_timer(character->waiting_disconnect, chardb_waiting_disconnect);
character->waiting_disconnect = -1;
}
- if (login_fd > 0 && !session[login_fd]->eof)
+ if (login_fd > 0 && !session[login_fd]->flag.eof)
{
WFIFOHEAD(login_fd,6);
WFIFOW(login_fd,0) = 0x272b;
@@ -374,7 +374,7 @@ void set_char_offline(int char_id, int account_id)
}
}
- if (login_fd > 0 && !session[login_fd]->eof)
+ if (login_fd > 0 && !session[login_fd]->flag.eof)
{
WFIFOHEAD(login_fd,6);
WFIFOW(login_fd,0) = 0x272c;
@@ -424,7 +424,7 @@ void set_all_offline(int id)
ShowNotice("Sending users of map-server %d offline.\n",id);
online_char_db->foreach(online_char_db,char_db_kickoffline,id);
- if (id >= 0 || login_fd <= 0 || session[login_fd]->eof)
+ if (id >= 0 || login_fd <= 0 || session[login_fd]->flag.eof)
return;
//Tell login-server to also mark all our characters as offline.
WFIFOHEAD(login_fd,2);
@@ -1954,7 +1954,7 @@ int parse_fromlogin(int fd)
if( fd != login_fd )
set_eof(fd);
- if(session[fd]->eof) {
+ if(session[fd]->flag.eof) {
if (fd == login_fd) {
ShowWarning("Connection to login-server lost (connection #%d).\n", fd);
login_fd = -1;
@@ -2605,7 +2605,7 @@ int parse_frommap(int fd)
ARR_FIND( 0, MAX_MAP_SERVERS, id, server[id].fd == fd );
if(id == MAX_MAP_SERVERS)
set_eof(fd);
- if(session[fd]->eof) {
+ if(session[fd]->flag.eof) {
if (id < MAX_MAP_SERVERS) {
unsigned char buf[16384];
ShowStatus("Map-server %d (session #%d) has disconnected.\n", id, fd);
@@ -3225,7 +3225,7 @@ int parse_char(int fd)
if(login_fd < 0)
set_eof(fd);
- if(session[fd]->eof)
+ if(session[fd]->flag.eof)
{
if (sd != NULL)
{
@@ -3639,7 +3639,7 @@ int parse_char(int fd)
server[i].users = 0;
memset(server[i].map, 0, sizeof(server[i].map));
session[fd]->func_parse = parse_frommap;
- session[fd]->client_addr = 0;
+ session[fd]->flag.server = 1;
realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
char_mapif_init(fd);
// send gm acccounts level to map-servers
@@ -3852,7 +3852,7 @@ int check_connect_login_server(int tid, unsigned int tick, int id, int data)
return 0;
}
session[login_fd]->func_parse = parse_fromlogin;
- session[login_fd]->client_addr = 0;
+ session[login_fd]->flag.server = 1;
realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
WFIFOHEAD(login_fd,86);
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index e18475c36..a40d627b8 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -258,7 +258,7 @@ void set_char_online(int map_id, int char_id, int account_id)
cp = idb_get(char_db_,char_id);
inter_guild_CharOnline(char_id, cp?cp->guild_id:-1);
}
- if (login_fd > 0 && !session[login_fd]->eof)
+ if (login_fd > 0 && !session[login_fd]->flag.eof)
{
WFIFOHEAD(login_fd,6);
WFIFOW(login_fd,0) = 0x272b;
@@ -301,7 +301,7 @@ void set_char_offline(int char_id, int account_id)
}
}
- if (login_fd > 0 && !session[login_fd]->eof)
+ if (login_fd > 0 && !session[login_fd]->flag.eof)
{
WFIFOHEAD(login_fd,6);
WFIFOW(login_fd,0) = 0x272c;
@@ -351,7 +351,7 @@ void set_all_offline(int id)
ShowNotice("Sending users of map-server %d offline.\n",id);
online_char_db->foreach(online_char_db,char_db_kickoffline,id);
- if (id >= 0 || login_fd <= 0 || session[login_fd]->eof)
+ if (id >= 0 || login_fd <= 0 || session[login_fd]->flag.eof)
return;
//Tell login-server to also mark all our characters as offline.
WFIFOHEAD(login_fd,2);
@@ -1623,7 +1623,7 @@ int parse_fromlogin(int fd)
if( fd != login_fd )
set_eof(fd);
- if(session[fd]->eof) {
+ if(session[fd]->flag.eof) {
if (fd == login_fd) {
ShowWarning("Connection to login-server lost (connection #%d).\n", fd);
login_fd = -1;
@@ -2126,7 +2126,7 @@ int parse_frommap(int fd)
ARR_FIND( 0, MAX_MAP_SERVERS, id, server[id].fd == fd );
if(id == MAX_MAP_SERVERS)
set_eof(fd);
- if(session[fd]->eof) {
+ if(session[fd]->flag.eof) {
if (id < MAX_MAP_SERVERS) {
unsigned char buf[16384];
ShowStatus("Map-server %d (session #%d) has disconnected.\n", id, fd);
@@ -2801,7 +2801,7 @@ int parse_char(int fd)
if(login_fd < 0)
set_eof(fd);
- if(session[fd]->eof)
+ if(session[fd]->flag.eof)
{
if (sd != NULL)
{ // already authed client
@@ -3189,7 +3189,7 @@ int parse_char(int fd)
server[i].users = 0;
memset(server[i].map, 0, sizeof(server[i].map));
session[fd]->func_parse = parse_frommap;
- session[fd]->client_addr = 0;
+ session[fd]->flag.server = 1;
realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
char_mapif_init(fd);
// send gm acccounts level to map-servers
@@ -3398,7 +3398,7 @@ int check_connect_login_server(int tid, unsigned int tick, int id, int data)
return 0;
}
session[login_fd]->func_parse = parse_fromlogin;
- session[login_fd]->client_addr = 0;
+ session[login_fd]->flag.server = 1;
realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
WFIFOHEAD(login_fd,86);
diff --git a/src/common/socket.c b/src/common/socket.c
index 83c2dc7fd..b1c564034 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -282,7 +282,7 @@ void set_eof(int fd)
// Add this socket to the shortlist for eof handling.
send_shortlist_add_fd(fd);
#endif
- session[fd]->eof = 1;
+ session[fd]->flag.eof = 1;
}
}
@@ -460,15 +460,15 @@ int make_listen_bind(uint32 ip, uint16 port)
sFD_SET(fd, &readfds);
create_session(fd, connect_client, null_send, null_parse);
+ session[fd]->client_addr = 0; // just listens
session[fd]->rdata_tick = 0; // disable timeouts on this socket
- session[fd]->client_addr = 0;
return fd;
}
int make_connection(uint32 ip, uint16 port)
{
- struct sockaddr_in server_address;
+ struct sockaddr_in remote_address;
int fd;
int result;
@@ -493,13 +493,13 @@ int make_connection(uint32 ip, uint16 port)
setsocketopts(fd);
- server_address.sin_family = AF_INET;
- server_address.sin_addr.s_addr = htonl(ip);
- server_address.sin_port = htons(port);
+ remote_address.sin_family = AF_INET;
+ remote_address.sin_addr.s_addr = htonl(ip);
+ remote_address.sin_port = htons(port);
ShowStatus("Connecting to %d.%d.%d.%d:%i\n", CONVIP(ip), port);
- result = sConnect(fd, (struct sockaddr *)(&server_address), sizeof(struct sockaddr_in));
+ result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in));
if( result == SOCKET_ERROR ) {
ShowError("make_connection: connect failed (socket #%d, code %d)!\n", fd, sErrno);
do_close(fd);
@@ -512,7 +512,7 @@ int make_connection(uint32 ip, uint16 port)
sFD_SET(fd,&readfds);
create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse);
- session[fd]->client_addr = 0;
+ session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr);
return fd;
}
@@ -1252,7 +1252,7 @@ bool session_isValid(int fd)
bool session_isActive(int fd)
{
- return ( session_isValid(fd) && !session[fd]->eof );
+ return ( session_isValid(fd) && !session[fd]->flag.eof );
}
// Resolves hostname into a numeric ip.
@@ -1327,12 +1327,12 @@ void send_shortlist_do_sends()
// If it's been marked as eof, call the parse func on it so that
// the socket will be immediately closed.
- if( session[fd]->eof )
+ if( session[fd]->flag.eof )
session[fd]->func_parse(fd);
// If the session still exists, is not eof and has things left to
// be sent from it we'll keep it in the shortlist.
- if( session[fd] && !session[fd]->eof && session[fd]->wdata_size )
+ if( session[fd] && !session[fd]->flag.eof && session[fd]->wdata_size )
{
send_shortlist_set[fd/32] |= 1<<(fd%32);
++i;
diff --git a/src/common/socket.h b/src/common/socket.h
index cdbac8f00..73322a206 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -35,7 +35,7 @@
#define RFIFOSPACE(fd) (session[fd]->max_rdata - session[fd]->rdata_size)
#define WFIFOSPACE(fd) (session[fd]->max_wdata - session[fd]->wdata_size)
-#define RFIFOREST(fd) (session[fd]->eof ? 0 : session[fd]->rdata_size - session[fd]->rdata_pos)
+#define RFIFOREST(fd) (session[fd]->flag.eof ? 0 : session[fd]->rdata_size - session[fd]->rdata_pos)
#define RFIFOFLUSH(fd) \
do { \
if(session[fd]->rdata_size == session[fd]->rdata_pos){ \
@@ -70,16 +70,19 @@ typedef int (*ParseFunc)(int fd);
struct socket_data
{
- unsigned char eof;
+ struct {
+ unsigned char eof : 1;
+ unsigned char server : 1;
+ } flag;
- unsigned char *rdata, *wdata;
+ uint32 client_addr; // remote client address
+
+ uint8 *rdata, *wdata;
size_t max_rdata, max_wdata;
size_t rdata_size, wdata_size;
size_t rdata_pos;
time_t rdata_tick; // time of last recv (for detecting timeouts); zero when timeout is disabled
- uint32 client_addr; // remote client address (0 for server connections)
-
RecvFunc func_recv;
SendFunc func_send;
ParseFunc func_parse;
diff --git a/src/ladmin/ladmin.c b/src/ladmin/ladmin.c
index 6c50b5ae6..89728be84 100644
--- a/src/ladmin/ladmin.c
+++ b/src/ladmin/ladmin.c
@@ -3239,7 +3239,7 @@ int parse_fromlogin(int fd)
struct char_session_data *sd;
int id;
RFIFOHEAD(fd);
- if (session[fd]->eof) {
+ if (session[fd]->flag.eof) {
if (defaultlanguage == 'F') {
ShowMessage("Impossible de se connecter au serveur de login [%s:%d] !\n", loginserverip, loginserverport);
ladmin_log("Impossible de se connecter au serveur de login [%s:%d] !\n", loginserverip, loginserverport);
@@ -4201,6 +4201,7 @@ int Connect_login_server(void)
ShowMessage("Error: Failed to connect to Login Server\n");
exit(EXIT_FAILURE);
}
+ session[login_fd]->flag.server = 1;
if (passenc == 0) {
WFIFOHEAD(login_fd,28);
WFIFOW(login_fd,0) = 0x7918; // Request for administation login
diff --git a/src/login/admin.c b/src/login/admin.c
index 0babf1e30..152c9e84d 100644
--- a/src/login/admin.c
+++ b/src/login/admin.c
@@ -45,7 +45,7 @@ int parse_admin(int fd)
char ip[16];
ip2str(ipl, ip);
- if( session[fd]->eof )
+ if( session[fd]->flag.eof )
{
do_close(fd);
ShowInfo("Remote administration has disconnected (session #%d).\n", fd);
diff --git a/src/login/login.c b/src/login/login.c
index 714eb178b..9a6f61c0b 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -1230,7 +1230,7 @@ int parse_fromchar(int fd)
return 0;
}
- if( session[fd]->eof )
+ if( session[fd]->flag.eof )
{
ShowStatus("Char-server '%s' has disconnected.\n", server[id].name);
online_db->foreach(online_db, online_db_setoffline, id); //Set all chars from this char server to offline.
@@ -1820,7 +1820,7 @@ int parse_login(int fd)
uint32 ipl;
char ip[16];
- if( session[fd]->eof )
+ if( session[fd]->flag.eof )
{
do_close(fd);
return 0;
@@ -2059,7 +2059,7 @@ int parse_login(int fd)
WFIFOSET(fd,3);
session[fd]->func_parse = parse_fromchar;
- session[fd]->client_addr = 0;
+ session[fd]->flag.server = 1;
realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
send_GM_accounts(fd); // send GM account to char-server
diff --git a/src/login_sql/login.c b/src/login_sql/login.c
index 299c06818..5d76c2d93 100644
--- a/src/login_sql/login.c
+++ b/src/login_sql/login.c
@@ -616,7 +616,7 @@ int parse_fromchar(int fd)
return 0;
}
- if( session[fd]->eof )
+ if( session[fd]->flag.eof )
{
ShowStatus("Char-server '%s' has disconnected.\n", server[id].name);
online_db->foreach(online_db, online_db_setoffline, id); //Set all chars from this char server to offline.
@@ -1220,7 +1220,7 @@ int parse_login(int fd)
uint32 ipl;
char ip[16];
- if( session[fd]->eof )
+ if( session[fd]->flag.eof )
{
do_close(fd);
return 0;
@@ -1523,7 +1523,7 @@ int parse_login(int fd)
WFIFOSET(fd,3);
session[fd]->func_parse = parse_fromchar;
- session[fd]->client_addr = 0;
+ session[fd]->flag.server = 1;
realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
send_GM_accounts(fd); // send GM account to char-server
diff --git a/src/map/chrif.c b/src/map/chrif.c
index a041d9957..11ce53ae7 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -1245,7 +1245,7 @@ int chrif_parse(int fd)
return 0;
}
- if (session[fd]->eof)
+ if (session[fd]->flag.eof)
{
if (chrif_connected == 1)
chrif_disconnect(fd);
@@ -1393,7 +1393,7 @@ int check_connect_char_server(int tid, unsigned int tick, int id, int data)
}
session[char_fd]->func_parse = chrif_parse;
- session[char_fd]->client_addr = 0;
+ session[char_fd]->flag.server = 1;
realloc_fifo(char_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
chrif_connect(char_fd);
diff --git a/src/map/clif.c b/src/map/clif.c
index 6a7017d5f..957154a3d 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -11494,7 +11494,7 @@ int clif_parse(int fd)
{ // begin main client packet processing loop
sd = (TBL_PC *)session[fd]->session_data;
- if (session[fd]->eof) {
+ if (session[fd]->flag.eof) {
if (sd) {
if (sd->state.autotrade) {
//Disassociate character from the socket connection.
diff --git a/src/map/guild.c b/src/map/guild.c
index ac5f67fa8..1e90226dc 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -233,7 +233,7 @@ struct guild_castle* guild_castle_search(int gcid)
struct guild_castle* guild_mapindex2gc(short mapindex)
{
struct guild_castle* gc;
-
+
DBIterator* iter = castle_db->iterator(castle_db);
for( gc = iter->first(iter,NULL); iter->exists(iter); gc = iter->next(iter,NULL) )
{
@@ -277,6 +277,7 @@ int guild_getindex(struct guild *g,int account_id,int char_id)
int guild_getposition(struct guild* g, struct map_session_data* sd)
{
int i;
+
if( g == NULL && (g=guild_search(sd->status.guild_id)) == NULL )
return -1;
diff --git a/src/map/irc.c b/src/map/irc.c
index a7995e615..67d269e51 100644
--- a/src/map/irc.c
+++ b/src/map/irc.c
@@ -121,7 +121,7 @@ void irc_announce_mvp(struct map_session_data *sd, struct mob_data *md)
int irc_parse(int fd)
{
- if (session[fd]->eof)
+ if (session[fd]->flag.eof)
{
do_close(fd);
irc_si = NULL;