コード例 #1
0
        private void OnConnectionAuth(object o, ConnectionAuthEventArgs e)
        {
            //The chat login packet fields are : (Field 0 = Server PW, Field 1 = User nickname).

            if (e.AuthCommand.Fields.Length < 2)
            {
                e.AllowConnection = false;
                e.DisallowReason  = "No nickname sent.";
                return;
            }
            else
            {
                if (e.AuthCommand.Fields[1].Length < 3)
                {
                    e.AllowConnection = false;
                    e.DisallowReason  = "Nickname too short.";
                    return;
                }
                else if (e.AuthCommand.Fields[1].Length > 15)
                {
                    e.AllowConnection = false;
                    e.DisallowReason  = "Nickname too long.";
                    return;
                }
                else
                {
                    if (e.AuthCommand.Fields[0] == txtPassword.Text)
                    {
                        e.AllowConnection = true;

                        //Store the users nickname on the connection
                        UserData ud = new UserData( );
                        ud.NickName = e.AuthCommand.Fields[1];
                        e.ClientConnection.UserObject = ud;

                        //Send the connected packet
                        m_UDP.SendReliableCommandToAll(BroadcastFilter.Clients | BroadcastFilter.AuthedOnly, 0, "22", new string[] { ud.NickName, "1" });

                        //Send the user list to currently connected users
                        SendUserList(null);
                    }
                    else
                    {
                        e.AllowConnection = false;
                        e.DisallowReason  = "Bad password.";
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Remote host tried to connect directly to us
 /// </summary>
 private void m_UDP_OnConnectionAuth(object o, ConnectionAuthEventArgs e)
 {
     //Clients don't accept connections.
     e.AllowConnection = false;
     e.DisallowReason  = "Can't connect directly to a chat client";
 }
コード例 #3
0
 /// <summary>
 /// Client has sent login information
 /// </summary>
 private void m_UDP_OnConnectionAuth(object o, ConnectionAuthEventArgs e)
 {
     this.Invoke(new GenesisCore.ConnectionAuthHandler(OnConnectionAuth), new object[] { o, e });
 }