Ejemplo n.º 1
0
        /// <summary>
        /// Removes a connection
        /// </summary>
        /// <param name="conn">Connection to remove</param>
        /// <param name="send_disconnect_packet">If true, will send a disconnection packet</param>
        /// <param name="reason">Reason to send (only matters if sending a disconnection packet</param>
        /// <returns>UDP_OK or error code</returns>
        private int RemoveConnection(Connection conn, bool send_disconnect_packet, string reason)
        {
            int retval = UdpConsts.UDP_OK;

            retval = m_Servers.RemoveConnection(conn, send_disconnect_packet, reason);
            if (retval != UdpConsts.UDP_OK)
            {
                retval = m_Clients.RemoveConnection(conn, send_disconnect_packet, reason);
            }

            return(retval);
        }
Ejemplo n.º 2
0
        /// <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);
        }