void OnContextDestroy(RelaySession context) { lock (m_class_lock) { m_sessions.Remove(context); Global.SessionCount--; } if (m_srv_type == ServerType.AgentServer) { bool isProperLogout = false; bool.TryParse(context.State["proper_logout"] as string, out isProperLogout); string username = context.State["username"] as string; if (isProperLogout) { Global.logmgr.WriteLog(LogLevel.Notify, "User [{0}] logged out", username); } else { Global.logmgr.WriteLog(LogLevel.Notify, "User with ip [{0}] uname [{1}] has been disconnected", context.State["ip_address"] as string, (username.Length > 0) ? username : "******"); } } }
//----------------------------------------------------------------------------- void OnContextCreate(RelaySession context) { lock (m_class_lock) { m_sessions.Add(context); Global.SessionCount++; } }
//----------------------------------------------------------------------------- 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()); } }
public PacketProcessResult ProcessModule(Packet pck, RelaySession session) { if (m_module_filter_handlers.ContainsKey(pck.Opcode)) { PacketHandler handler = m_module_filter_handlers[pck.Opcode] as PacketHandler; if (handler != null) { return(handler(pck, session, m_server)); } else { if (Global.EnableBanExploitAbuser) { Global.BlockedIpAddresses.Add(Utility.GetRemoteEpString(session.Arguments.ClientSocket)); } return(PacketProcessResult.Disconnect); } } if (m_module_debug_opcodes.Contains(pck.Opcode) || m_log_all_client_pck) { //Debug log Global.logmgr.WritePacketLog(pck, PacketDirection.ModuleToClient, session.State); } if (m_module_handlers.ContainsKey(pck.Opcode)) { PacketHandler handler = m_module_handlers[pck.Opcode] as PacketHandler; if (m_server == null) { throw new Exception("PacketDispatcher::ProcessModule m_server not set"); } return(handler(pck, session, m_server)); } //We simply ignore packet and continue looping if handler doesent do something else return(PacketProcessResult.DoNothing); }
//----------------------------------------------------------------------------- int GetConnectionCountBySession(RelaySession context) { int nCount = 0; lock (m_class_lock) { try { string my_ip = context.State["ip_address"] as string; foreach (var item in m_sessions) { if (item.State["ip_address"].ToString() == my_ip) { nCount++; } } } catch { } } return(nCount); }
void OnContextDestroy(RelaySession context) { lock (m_class_lock) { m_sessions.Remove(context); Global.SessionCount--; } if (m_srv_type == ServerType.AgentServer) { bool isProperLogout = false; bool.TryParse(context.State["proper_logout"] as string, out isProperLogout); string username = context.State["username"] as string; if (isProperLogout) { Global.logmgr.WriteLog(LogLevel.Notify, "User [{0}] logged out", username); } else { Global.logmgr.WriteLog(LogLevel.Notify, "User with ip [{0}] uname [{1}] has been disconnected", context.State["ip_address"] as string, (username.Length> 0 ) ? username : "******"); } } }
//----------------------------------------------------------------------------- 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()); } }
//----------------------------------------------------------------------------- int GetConnectionCountBySession(RelaySession context) { int nCount = 0; lock (m_class_lock) { try { string my_ip = context.State["ip_address"] as string; foreach (var item in m_sessions) { if (item.State["ip_address"].ToString() == my_ip) { nCount++; } } } catch { } } return nCount; }
public PacketProcessResult ProcessModule(Packet pck, RelaySession session) { if (m_module_filter_handlers.ContainsKey(pck.Opcode)) { PacketHandler handler = m_module_filter_handlers[pck.Opcode] as PacketHandler; if (handler != null) { return handler(pck, session, m_server); } else { if (Global.EnableBanExploitAbuser) { Global.BlockedIpAddresses.Add(Utility.GetRemoteEpString(session.Arguments.ClientSocket)); } return PacketProcessResult.Disconnect; } } if(m_module_debug_opcodes.Contains(pck.Opcode) || m_log_all_client_pck) { //Debug log Global.logmgr.WritePacketLog(pck, PacketDirection.ModuleToClient, session.State); } if (m_module_handlers.ContainsKey(pck.Opcode)) { PacketHandler handler = m_module_handlers[pck.Opcode] as PacketHandler; if (m_server == null) { throw new Exception("PacketDispatcher::ProcessModule m_server not set"); } return handler(pck, session, m_server); } //We simply ignore packet and continue looping if handler doesent do something else return PacketProcessResult.DoNothing; }