internal int ConnectionAuthing(Connection cn, Command cmd) { if (cn.Authed) { return(UdpConsts.UDP_OK); } ConnectionAuthEventArgs connectionAuthEventArgs = new ConnectionAuthEventArgs(cn, cmd); if (this.OnConnectionAuth != null) { this.OnConnectionAuth(null, connectionAuthEventArgs); } if (connectionAuthEventArgs.DisallowReason.Length > 200) { connectionAuthEventArgs.DisallowReason = connectionAuthEventArgs.DisallowReason.Substring(0, 200); } if (!connectionAuthEventArgs.AllowConnection) { cn.SendUnreliableCommand(0, UdpConsts.OPCODE_LOGINACK, new string[] { "FAIL", connectionAuthEventArgs.DisallowReason }); this.m_Clients.RemoveConnection(cn, true, connectionAuthEventArgs.DisallowReason); } else { cn.SendUnreliableCommand(0, UdpConsts.OPCODE_LOGINACK, new string[] { "OK" }); cn.Authed = true; } return(UdpConsts.UDP_OK); }
/// <summary> /// Called when a connection is attempting to authenticate /// </summary> /// <param name="cn">Connection</param> /// <param name="cmd">Command</param> /// <returns>UDP_OK or error code</returns> internal int ConnectionAuthing(Connection cn, Command cmd) { //Is the connection already authed? if (cn.Authed) { DebugDump("Connection " + cn.RemoteEP.ToString() + " sent an auth packet but is already authed? Command ignored."); return(UdpConsts.UDP_OK); } ConnectionAuthEventArgs ea = new ConnectionAuthEventArgs(cn, cmd); DebugDump("Connection " + cn.RemoteEP.ToString() + " sent login data..."); //Have the third party client app process the login data if (OnConnectionAuth != null) { OnConnectionAuth(null, ea); } //Clamp the disallow reason to 200 characters if (ea.DisallowReason.Length > 200) { ea.DisallowReason = ea.DisallowReason.Substring(0, 200); } if (!ea.AllowConnection) { DebugDump("Login data is bad, rejecting connection."); cn.SendUnreliableCommand(0, UdpConsts.OPCODE_LOGINACK, new string[] { "FAIL", ea.DisallowReason }); m_Clients.RemoveConnection(cn, true, ea.DisallowReason); } else { DebugDump("Login data is ok, connection authed."); cn.SendUnreliableCommand(0, UdpConsts.OPCODE_LOGINACK, new string[] { "OK" }); cn.Authed = true; } return(UdpConsts.UDP_OK); }
/// <summary> /// Called when a connection is attempting to authenticate /// </summary> /// <param name="cn">Connection</param> /// <param name="cmd">Command</param> /// <returns>UDP_OK or error code</returns> internal int ConnectionAuthing(Connection cn, Command cmd) { //Is the connection already authed? if(cn.Authed) { DebugDump("Connection " + cn.RemoteEP.ToString() + " sent an auth packet but is already authed? Command ignored."); return UdpConsts.UDP_OK; } ConnectionAuthEventArgs ea = new ConnectionAuthEventArgs(cn, cmd); DebugDump("Connection " + cn.RemoteEP.ToString() + " sent login data..."); //Have the third party client app process the login data if (OnConnectionAuth != null) OnConnectionAuth(null, ea); //Clamp the disallow reason to 200 characters if (ea.DisallowReason.Length > 200) ea.DisallowReason = ea.DisallowReason.Substring(0, 200); if (!ea.AllowConnection) { DebugDump("Login data is bad, rejecting connection."); cn.SendUnreliableCommand(0, UdpConsts.OPCODE_LOGINACK, new string[] { "FAIL", ea.DisallowReason }); m_Clients.RemoveConnection(cn, true, ea.DisallowReason); } else { DebugDump("Login data is ok, connection authed."); cn.SendUnreliableCommand(0, UdpConsts.OPCODE_LOGINACK, new string[] { "OK" }); cn.Authed = true; } return UdpConsts.UDP_OK; }