//----------------------------------------------------------------------------- public RelaySession(RelaySessionArgs arg, PacketDispatcher packetProcessor) { m_io_lock = new object(); m_args = arg; m_pck_processor = packetProcessor; m_state = new RelaySessionState(); m_module_connected = false; m_client_sec = new Security(); m_module_sec = new Security(); m_client_buffer = new byte[Global.RecvBuffersSize]; m_module_buffer = new byte[Global.RecvBuffersSize]; m_state["ip_address"] = Utility.GetRemoteEpString(m_args.ClientSocket); m_client_sec.GenerateSecurity(m_args.Blowfish, m_args.SecBytes, m_args.Handshake); m_args.ClientSocket.NoDelay = true; m_module_sock.NoDelay = true; }
//----------------------------------------------------------------------------- void OnAcceptCallback(IAsyncResult iar) { m_connection_completed.Set(); try { Socket client = m_listener_sock.EndAccept(iar); RelaySessionArgs ContextArguments = new RelaySessionArgs() { ClientSocket = client, ModuleEp = m_module_addr, eOnCreate = m_session_create_handler, eOnDestroy = m_session_destroy_handler, Blowfish = m_blowfish, SecBytes = m_sec_bytes, Handshake = m_handshake, SrvType = m_srv_type }; RelaySession context = new RelaySession(ContextArguments, m_pck_processor); //is set from constructor of UserContext string ip_address = context.State["ip_address"] as string; if (!Global.BlockedIpAddresses.Contains(ip_address)) { context.Start(); } else { client.Shutdown(SocketShutdown.Both); client.Close(); } } catch (Exception e) { Global.logmgr.WriteLog(LogLevel.Notify, "Error at silkroadserver onacceptcallback"); Global.logmgr.WriteLog(LogLevel.Notify, e.ToString()); } }
//----------------------------------------------------------------------------- void OnAcceptCallback(IAsyncResult iar) { m_connection_completed.Set(); try { Socket client = m_listener_sock.EndAccept(iar); RelaySessionArgs ContextArguments = new RelaySessionArgs() { ClientSocket = client, ModuleEp = m_module_addr, eOnCreate = m_session_create_handler, eOnDestroy = m_session_destroy_handler, Blowfish = m_blowfish, SecBytes = m_sec_bytes, Handshake = m_handshake, SrvType = m_srv_type }; RelaySession context = new RelaySession(ContextArguments, m_pck_processor ); //is set from constructor of UserContext string ip_address = context.State["ip_address"] as string; if (!Global.BlockedIpAddresses.Contains(ip_address)) { context.Start(); } else { client.Shutdown(SocketShutdown.Both); client.Close(); } } catch(Exception e) { Global.logmgr.WriteLog(LogLevel.Notify, "Error at silkroadserver onacceptcallback"); Global.logmgr.WriteLog(LogLevel.Notify, e.ToString()); } }