diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/chrif.c | 74 |
1 files changed, 61 insertions, 13 deletions
diff --git a/src/map/chrif.c b/src/map/chrif.c index c4fe9dd67..7fbff78e4 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -37,7 +37,7 @@ static const int packet_len_table[0x3d] = { // U - used, F - free 6,30,-1,-1,86, 7,44,34, // 2b08-2b0f: U->2b08, U->2b09, F->2b0a, F->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f 11,10,10, 6,11,-1,266,10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17 2,10, 2,-1,-1,-1, 2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, U->2b1e, U->2b1f - -1,10, 8, 2, 2,14,-1,-1, // 2b20-2b27: U->2b20, U->2b21, U->2b22, U->2b23, U->2b24, U->2b25, F->2b26, F->2b27 + -1,10, 8, 2, 2,14,19,19, // 2b20-2b27: U->2b20, U->2b21, U->2b22, U->2b23, U->2b24, U->2b25, F->2b26, F->2b27 }; //Used Packets: @@ -46,7 +46,7 @@ static const int packet_len_table[0x3d] = { // U - used, F - free //2afa: Outgoing, chrif_sendmap -> 'sending our maps' //2afb: Incoming, chrif_sendmapack -> 'Maps received successfully / or not ..' //2afc: Outgoing, chrif_scdata_request -> request sc_data for pc_authok'ed char. <- new command reuses previous one. -//2afd: Incoming, chrif_authok -> 'character selected, add to auth db' +//2afd: Incoming, chrif_authok -> 'client authentication ok' //2afe: Outgoing, send_usercount_tochar -> 'sends player count of this map server to charserver' //2aff: Outgoing, send_users_tochar -> 'sends all actual connected character ids to charserver' //2b00: Incoming, map_setusers -> 'set the actual usercount? PACKET.2B COUNT.L.. ?' (not sure) @@ -87,8 +87,8 @@ static const int packet_len_table[0x3d] = { // U - used, F - free //2b23: Outgoing, chrif_keepalive. charserver ping. //2b24: Incoming, chrif_keepalive_ack. charserver ping reply. //2b25: Incoming, chrif_deadopt -> 'Removes baby from Father ID and Mother ID' -//2b26: FREE -//2b27: FREE +//2b26: Outgoing, chrif_authreq -> 'client authentication request' +//2b27: Incoming, chrif_authfail -> 'client authentication failed' int chrif_connected = 0; int char_fd = 0; //Using 0 instead of -1 is safer against crashes. [Skotlex] @@ -384,7 +384,7 @@ int chrif_changemapserver(struct map_session_data* sd, uint32 ip, uint16 port) WFIFOL(char_fd,24) = htonl(ip); WFIFOW(char_fd,28) = htons(port); WFIFOB(char_fd,30) = sd->status.sex; - WFIFOL(char_fd,31) = 0; // sd's IP, not used anymore + WFIFOL(char_fd,31) = htonl(session[sd->fd]->client_addr); WFIFOSET(char_fd,35); return 0; } @@ -517,6 +517,14 @@ void chrif_authreq(struct map_session_data *sd) if(!node) { //data from char server has not arrived yet. + WFIFOHEAD(char_fd,19); + WFIFOW(char_fd,0) = 0x2b26; + WFIFOL(char_fd,2) = sd->status.account_id; + WFIFOL(char_fd,6) = sd->status.char_id; + WFIFOL(char_fd,10) = sd->login_id1; + WFIFOB(char_fd,14) = sd->status.sex; + WFIFOL(char_fd,15) = htonl(session[sd->fd]->client_addr); + WFIFOSET(char_fd,19); chrif_sd_to_auth(sd, ST_LOGIN); return; } @@ -550,10 +558,13 @@ void chrif_authreq(struct map_session_data *sd) //character selected, insert into auth db void chrif_authok(int fd) { + int account_id; + uint32 login_id1; + time_t expiration_time; + uint32 login_id2; + struct mmo_charstatus* status; + int char_id; struct auth_node *node; - int account_id = RFIFOL(fd, 4); - struct mmo_charstatus *status = (struct mmo_charstatus *)RFIFOP(fd, 20); - int char_id = status->char_id; TBL_PC* sd; //Check if both servers agree on the struct's size @@ -563,6 +574,13 @@ void chrif_authok(int fd) return; } + account_id = RFIFOL(fd,4); + login_id1 = RFIFOL(fd,8); + expiration_time = (time_t)(int32)RFIFOL(fd,12); + login_id2 = RFIFOL(fd,16); + status = (struct mmo_charstatus*)RFIFOP(fd,20); + char_id = status->char_id; + //Check if we don't already have player data in our server //Causes problems if the currently connected player tries to quit or this data belongs to an already connected player which is trying to re-auth. if ((sd = map_id2sd(account_id)) != NULL) @@ -578,9 +596,9 @@ void chrif_authok(int fd) if(node->char_dat == NULL && node->account_id == account_id && node->char_id == char_id && - node->login_id1 == RFIFOL(fd, 8)) + node->login_id1 == login_id1 ) { //Auth Ok - if (pc_authok(sd, RFIFOL(fd, 16), RFIFOL(fd, 12), status)) + if (pc_authok(sd, login_id2, expiration_time, status)) { chrif_char_online(sd); return; @@ -604,14 +622,43 @@ void chrif_authok(int fd) node->account_id=account_id; node->char_id=char_id; - node->login_id1=RFIFOL(fd, 8); - node->expiration_time=RFIFOL(fd, 12); - node->login_id2=RFIFOL(fd, 16); + node->login_id1=login_id1; + node->expiration_time=expiration_time; + node->login_id2=login_id2; memcpy(node->char_dat,status,sizeof(struct mmo_charstatus)); node->node_created=gettick(); idb_put(auth_db, account_id, node); } +// client authentication failed +void chrif_authfail(int fd) +{ + int account_id; + int char_id; + uint32 login_id1; + char sex; + uint32 ip; + struct auth_node* node; + + account_id = RFIFOL(fd,2); + char_id = RFIFOL(fd,6); + login_id1 = RFIFOL(fd,10); + sex = RFIFOB(fd,14); + ip = ntohl(RFIFOL(fd,15)); + + node = chrif_search(account_id); + if( node != NULL && + node->account_id == account_id && + node->char_id == char_id && + node->login_id1 == login_id1 && + node->sex == sex && + node->state == ST_LOGIN ) + {// found a match + clif_authfail_fd(node->fd, 0); + chrif_auth_delete(account_id, char_id, ST_LOGIN); + } +} + int auth_db_cleanup_sub(DBKey key,void *data,va_list ap) { struct auth_node *node=(struct auth_node*)data; @@ -1443,6 +1490,7 @@ int chrif_parse(int fd) case 0x2b22: chrif_updatefamelist_ack(fd); break; case 0x2b24: chrif_keepalive_ack(fd); break; case 0x2b25: chrif_deadopt(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break; + case 0x2b27: chrif_authfail(fd); break; default: ShowError("chrif_parse : unknown packet (session #%d): 0x%x. Disconnecting.\n", fd, cmd); set_eof(fd); |