예제 #1
0
        protected override void Process(Networking.AuthenticationClient s)
        {
            ushort errorCode = GetUShort(0);

            if (Enum.IsDefined(typeof(ErrorCodes), errorCode))
            {
                ErrorCodes enumErrorCode = (ErrorCodes)errorCode;
                uint       targetId      = GetuInt(1);

                switch (enumErrorCode)
                {
                // A new player logs in.
                case ErrorCodes.Success:
                {
                    Entities.User u = Managers.UserManager.Instance.Get(targetId);
                    if (u != null)
                    {
                        Log.Debug("User authorized");
                        uint   userId      = GetuInt(2);
                        string userName    = GetString(3);
                        string displayName = GetString(4);
                        byte   accessLevel = GetByte(5);
                        u.OnAuthorize(userId, displayName, accessLevel);
                    }
                    break;
                }

                // Update the information of a player.
                case ErrorCodes.Update:
                {
                    break;
                }

                // A player logs out of the server. //TODO: code this
                case ErrorCodes.EndConnection:
                {
                    break;
                }

                case ErrorCodes.InvalidKeyOrSession:
                {
                    Entities.User u = Managers.UserManager.Instance.Get(targetId);
                    if (u != null)
                    {
                        if (!u.Authorized)
                        {
                            u.Send(new Packets.Authorization(Packets.Authorization.ErrorCodes.NormalProcedure));
                        }
                        u.Disconnect();
                    }
                    break;
                }

                case ErrorCodes.InvalidSessionMatch:
                {
                    Entities.User u = Managers.UserManager.Instance.Get(targetId);
                    if (u != null)
                    {
                        u.Send(new Packets.Authorization(Packets.Authorization.ErrorCodes.NormalProcedure));
                        u.Disconnect();
                    }
                    break;
                }

                case ErrorCodes.EntityAlreadyAuthorized:
                {
                    Entities.User u = Managers.UserManager.Instance.Get(targetId);
                    if (u != null)
                    {
                        u.Send(new Packets.Authorization(Packets.Authorization.ErrorCodes.NormalProcedure));
                        u.Disconnect();
                    }
                    break;
                }

                default:
                {
                    // Unused.
                    break;
                }
                }
            }
            else
            {
                //  Log.Instance.WriteLine(string.Concat("Unknown PlayerAuthorization error: ", errorCode));
            }
        }
예제 #2
0
        protected override void Process(Networking.AuthenticationClient s)
        {
            ushort errorCode = GetUShort(0);

            if (s.Authorized)
            {
                return;               // Ignore other packets.
            }
            if (Enum.IsDefined(typeof(ErrorCodes), errorCode))
            {
                ErrorCodes enumErrorCode = (ErrorCodes)errorCode;
                switch (enumErrorCode)
                {
                case ErrorCodes.Success:
                {
                    s.OnAuthorize(GetByte(1));

                    if (!s.IsFirstConnect)         //TODO: UPDATE
                    {
                        // We disconnected, sync the server!
                    }

                    break;
                }

                case ErrorCodes.InvalidKeyOrSession:
                {
                    Log.Error("Error while authorizing: the authorization key didn't match.");
                    s.Disconnect(true);
                    break;
                }

                case ErrorCodes.EntityAlreadyAuthorized:
                {
                    Log.Error("Error while authorizing: a server with the same ip address is already online.");
                    s.Disconnect(true);
                    break;
                }

                case ErrorCodes.ServerLimitReached:
                {
                    Log.Error("Error while authorizing: maximum amount of servers reached.");
                    s.Disconnect(true);
                    break;
                }

                case ErrorCodes.ServerNameInUse:
                {
                    Log.Error("Error while authorizing: the server name is already in use.");
                    s.Disconnect(true);
                    break;
                }

                default:
                {
                    Log.Error(string.Concat("An unknown(", errorCode.ToString("x2"), ") error occured while authorizing the server."));
                    s.Disconnect(true);
                    break;
                }
                }
            }
            else
            {
                // Unknown error
                Log.Error(string.Concat("An unknown(", errorCode.ToString("x2"), ") error occured while authorizing the server."));
                s.Disconnect(true);
            }
        }
예제 #3
0
 protected override void Process(Networking.AuthenticationClient s)
 {
 }