Пример #1
0
int chlogif_parse(int fd) {
	struct char_session_data* sd = NULL;

	// only process data from the login-server
	if( fd != login_fd ) {
		ShowDebug("parse_fromlogin: Disconnecting invalid session #%d (is not the login-server)\n", fd);
		do_close(fd);
		return 0;
	}

	if( session[fd]->flag.eof ) {
		do_close(fd);
		login_fd = -1;
		chlogif_on_disconnect();
		return 0;
	} else if ( session[fd]->flag.ping ) {/* we've reached stall time */
		if( DIFF_TICK(last_tick, session[fd]->rdata_tick) > (stall_time * 2) ) {/* we can't wait any longer */
			set_eof(fd);
			return 0;
		} else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */
			WFIFOHEAD(fd,2);// sends a ping packet to login server (will receive pong 0x2718)
			WFIFOW(fd,0) = 0x2719;
			WFIFOSET(fd,2);

			session[fd]->flag.ping = 2;
		}
	}

	sd = (struct char_session_data*)session[fd]->session_data;

	while(RFIFOREST(fd) >= 2) {
		// -1: Login server is not connected
		//  0: Avoid processing followup packets (prev was probably incomplete) packet
		//  1: Continue parsing
		int next = 1;
		uint16 command = RFIFOW(fd,0);
		switch( command ) {
			case 0x2711: next = chlogif_parse_ackconnect(fd,sd); break;
			case 0x2713: next = chlogif_parse_ackaccreq(fd, sd); break;
			case 0x2717: next = chlogif_parse_reqaccdata(fd, sd); break;
			case 0x2718: next = chlogif_parse_keepalive(fd, sd); break;
			case 0x2721: next = chlogif_parse_AccInfoAck(fd); break;
			case 0x2723: next = chlogif_parse_ackchangesex(fd, sd); break;
			case 0x2726: next = chlogif_parse_ack_global_accreg(fd, sd); break;
			case 0x2731: next = chlogif_parse_accbannotification(fd, sd); break;
			case 0x2734: next = chlogif_parse_askkick(fd,sd); break;
			case 0x2735: next = chlogif_parse_updip(fd,sd); break;
			case 0x2743: next = chlogif_parse_vipack(fd); break;
			default:
				ShowError("Unknown packet 0x%04x received from login-server, disconnecting.\n", command);
				set_eof(fd);
				return 0;
		}
		if (next == 0)
			return 0; //do not parse next data
	}

	RFIFOFLUSH(fd);
	return 0;
}
Пример #2
0
int chlogif_parse(int fd) {
	struct char_session_data* sd = NULL;

	// only process data from the login-server
	if( fd != login_fd ) {
		ShowDebug("parse_fromlogin: Disconnecting invalid session #%d (is not the login-server)\n", fd);
		do_close(fd);
		return 0;
	}

	if( session[fd]->flag.eof ) {
		do_close(fd);
		login_fd = -1;
		chlogif_on_disconnect();
		return 0;
	} else if ( session[fd]->flag.ping ) {/* we've reached stall time */
		if( DIFF_TICK(last_tick, session[fd]->rdata_tick) > (stall_time * 2) ) {/* we can't wait any longer */
			set_eof(fd);
			return 0;
		} else if( session[fd]->flag.ping != 2 ) { /* we haven't sent ping out yet */
			WFIFOHEAD(fd,2);// sends a ping packet to login server (will receive pong 0x2718)
			WFIFOW(fd,0) = 0x2719;
			WFIFOSET(fd,2);

			session[fd]->flag.ping = 2;
		}
	}

	sd = (struct char_session_data*)session[fd]->session_data;

	while(RFIFOREST(fd) >= 2) {
		int next=1;
		uint16 command = RFIFOW(fd,0);
		switch( command )
		{
			case 0x2741: next = chlogif_parse_BankingAck(fd); break;
			case 0x2743: next = chlogif_parse_vipack(fd); break;
			// acknowledgement of connect-to-loginserver request
			case 0x2711: next = chlogif_parse_ackconnect(fd,sd); break;
			// acknowledgement of account authentication request
			case 0x2713: next = chlogif_parse_ackaccreq(fd, sd); break;
			// account data
			case 0x2717: next = chlogif_parse_reqaccdata(fd, sd); break;
			// login-server alive packet
			case 0x2718: next = chlogif_parse_keepalive(fd, sd); break;
			// changesex reply
			case 0x2723: next = chlogif_parse_ackchangesex(fd, sd); break;
			// reply to an account_reg2 registry request
			case 0x2729: next = chlogif_parse_ackacc2req(fd, sd); break;
			// State change of account/ban notification (from login-server)
			case 0x2731: next = chlogif_parse_accbannotification(fd, sd); break;
			// Login server request to kick a character out. [Skotlex]
			case 0x2734: next = chlogif_parse_askkick(fd,sd); break;
			// ip address update signal from login server
			case 0x2735: next = chlogif_parse_updip(fd,sd); break;
			// @accinfo result
			case 0x2721: next = chlogif_parse_AccInfoAck(fd); break;
			default:
				ShowError("Unknown packet 0x%04x received from login-server, disconnecting.\n", command);
				set_eof(fd);
				return 0;
		}
		if(next==0) return 0; //do not parse next data
	}

	RFIFOFLUSH(fd);
	return 0;
}