Exemplo n.º 1
0
        //This is a very simple very bad example.
        //You would need to replace with your own logic. Perhaps with a DB connection.
        void HandleLoginMsg(InsightNetworkMessage netMsg)
        {
            LoginMsg message = netMsg.ReadMessage <LoginMsg>();

            logger.Log("[ServerAuthentication] - Login Received: " + message.AccountName + " / " + message.AccountPassword);

            if (EnforceAuthentication)
            {
                //Check the username and password. Again this is bad code for example only. REPLACE ME
                if (message.AccountName.Equals("root") && message.AccountPassword.Equals("password"))
                {
                    string UniqueId = Guid.NewGuid().ToString();

                    registeredUsers.Add(new UserContainer()
                    {
                        username     = message.AccountName,
                        uniqueId     = UniqueId,
                        connectionId = netMsg.connectionId
                    });

                    netMsg.Reply(new LoginResponseMsg()
                    {
                        Status   = CallbackStatus.Success,
                        UniqueID = UniqueId
                    });
                }

                //Login Failed
                else
                {
                    netMsg.Reply(new LoginResponseMsg()
                    {
                        Status = CallbackStatus.Error
                    });
                }
            }
            else
            {
                string UniqueId = Guid.NewGuid().ToString();

                registeredUsers.Add(new UserContainer()
                {
                    username     = message.AccountName,
                    uniqueId     = UniqueId,
                    connectionId = netMsg.connectionId
                });

                netMsg.Reply(new LoginResponseMsg()
                {
                    Status = CallbackStatus.Success
                });
            }
        }
Exemplo n.º 2
0
        //This is just an example. No actual authentication happens.
        //You would need to replace with your own logic. Perhaps with a DB connection.
        void HandleLoginMsg(InsightNetworkMessage netMsg)
        {
            LoginMsg message = netMsg.ReadMessage <LoginMsg>();

            if (server.logNetworkMessages)
            {
                Debug.Log("[Authentication] - Login Received: " + message.AccountName + " / " + message.AccountPassword);
            }

            //Login Sucessful
            if (true) //Put your DB logic here
            {
                string UniqueId = Guid.NewGuid().ToString();

                registeredUsers.Add(new UserContainer()
                {
                    username     = message.AccountName,
                    uniqueId     = UniqueId,
                    connectionId = netMsg.connectionId
                });

                netMsg.Reply((short)MsgId.LoginResponse, new LoginResponseMsg()
                {
                    Authenticated = true,
                    UniqueID      = UniqueId
                });
            }

            //Login Failed. Unreachable code currently as there is no real auth happening.
            //else
            //{
            //    netMsg.Reply((short)MsgId.LoginResponse, new LoginResponseMsg()
            //    {
            //        Authenticated = false
            //    });
            //}
        }
Exemplo n.º 3
0
 private bool Authenticated(LoginMsg _message)           //Put your DB logic here
 {
     return(true);
 }