public void connect(string addr, int port) { try { end_point_ = new IPEndPoint(IPAddress.Parse(addr), port); socket_ = new Socket(end_point_.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket_.Connect(end_point_); if (socket_.Connected) { output_.output_debug("-client: connection to server established\n"); wait_for_data(); } else { output_.output_debug("-client: can't connect to login server\n"); return; } } catch (SocketException se) { output_.output_debug("-client: " + se.Message + "\n"); } }
// Main processor public void process_packet(byte[] data_buffer, int packet_lenght, Socket socket) { if (first_packet_ && login_) { process_first_packet(data_buffer, packet_lenght, socket); } else { if (login_) { blowfish_cipher_.init(false, blowfish_key_); blowfish_cipher_.processBigBlock(data_buffer, 0x02, decoded_buffer_, 0x00, packet_lenght - 2); output_.output_debug("-server: packet code: "); output_.output_debug(decoded_buffer_, 1); output_.output_debug("\n"); switch (decoded_buffer_[0]) { case 0x0B: output_.output_debug("-client: login packet\n"); craft_login_packet(socket); break; case 0x03: output_.output_debug("-client: login accepted.\n"); craft_login_ok_packet(socket, decoded_buffer_); break; case 0x01: output_.output_debug("-client: login fail.\n"); break; case 0x04: output_.output_debug("-server: total servers: "); output_.output_debug(decoded_buffer_[1].ToString()); output_.output_debug("\n"); craft_select_server_packet(socket, decoded_buffer_); break; case 0x07: output_.output_debug("-server: server selected.\n-client: connecting to game server\n"); play_ok_[0] = decoded_buffer_[1]; play_ok_[1] = decoded_buffer_[2]; play_ok_[2] = decoded_buffer_[3]; play_ok_[3] = decoded_buffer_[4]; play_ok_[4] = decoded_buffer_[5]; play_ok_[5] = decoded_buffer_[6]; play_ok_[6] = decoded_buffer_[7]; play_ok_[7] = decoded_buffer_[8]; play_ok_[8] = decoded_buffer_[9]; login_ = false; socket.Close(); connection_.connect("178.162.141.22", 2106); craft_gameserver_protocol_packet(connection_.socket_); break; } } else { Buffer.BlockCopy(data_buffer, 2, data_buffer, 0, packet_lenght - 2); output_.output_debug("-server: GS packet code: "); output_.output_debug(data_buffer, 1); output_.output_debug("\n"); switch (data_buffer[0]) { case 0x2E: output_.output_debug("-server: auth key packet\n"); break; } } } }