public void Handle(INetworkStateContext <TWorld> gameStateContext, NetworkCommandConnection networkCommandConnectionToHandle)
        {
            if (!HasValidGameState(networkCommandConnectionToHandle))
            {
                gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.Error);
            }

            var typeToProofAgainst = typeof(UserData).FullName;

            if (networkCommandConnectionToHandle.CommandArgument != typeToProofAgainst)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"Cannot transition user to update state. Command argument is not of type user data. Type is {networkCommandConnectionToHandle.CommandArgument}");
                var errorHandler = gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.Error);
                gameStateContext.ChangeHandlerEasier(gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.Error), networkCommandConnectionToHandle);
            }
            else
            {
                var userRoleGateway = gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.UserRoleGateWay);
                gameStateContext.ChangeHandlerEasier(userRoleGateway, networkCommandConnectionToHandle);


                //Console.WriteLine("Transitioning user to update or else");
                //var gameStateData = CurrentNetworkCommandToUpdateGameState.Translate(networkCommandConnectionToHandle);
                //gameStateContext.CurrentNetOutgoingMessageBusService.SendToClient
                //(
                //    NetworkCommandConstants.UpdateCommand,
                //    gameStateData,
                //    networkCommandConnectionToHandle.Connection
                //);
                //gameStateContext.ChangeHandlerEasier(gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.Update), networkCommandConnectionToHandle);
            }
            gameStateContext[networkCommandConnectionToHandle.ConnectionId].Handle(gameStateContext, networkCommandConnectionToHandle);
        }
        public void Handle(INetworkStateContext <TWorld> gameStateContext, NetworkCommandConnection networkCommandConnectionToHandle)
        {
            //Passes through if network command id was already registered as a CLI user.
            UserDataWithLoginToken userData = null;

            if (!CachedAuthorizedUsers.ContainsKey(networkCommandConnectionToHandle.ConnectionId))
            {
                userData = CurrentNetworkCommandToFullUserDataTranslator.Translate(networkCommandConnectionToHandle);

                //check permissions
                if (!userData.Roles.HasFlag(UserDataRole.CanSendRemoteStateCommands))
                {
                    gameStateContext.ChangeHandlerEasier(gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.Error), networkCommandConnectionToHandle);
                    return;
                }
                if (!CachedAuthorizedUsers.TryAdd(networkCommandConnectionToHandle.ConnectionId, userData))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Whoops! Could not add user to cached authorized users");
                    gameStateContext.ChangeHandlerEasier(gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.Error), networkCommandConnectionToHandle);
                    return;
                }
                //say to client ready for rsc, waiting for signal
                gameStateContext.CurrentNetOutgoingMessageBusService.SendToClient(
                    CLINetworkCommandConstants.WaitForSignalCommand,
                    gameStateContext.GameStateRegistrar.WorldGameStateDataLayer.GetGameStateByLoginToken(userData?.LoginToken),
                    networkCommandConnectionToHandle.Connection);
            }
            else
            {
                //this is only triggered if the user has been registered as a CLI user
                gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.CLIPassthrough).Handle(gameStateContext, networkCommandConnectionToHandle);
            }
        }
        public void Handle(INetworkStateContext <TWorld> gameStateContext, NetworkCommandConnection networkCommandConnectionToHandle)
        {
            var typeToProofAgainst = typeof(UserData).FullName;

            //Now we look what the roles are and deliver answers
            if (networkCommandConnectionToHandle.CommandArgument != typeToProofAgainst)
            {
                ThrowError(gameStateContext, networkCommandConnectionToHandle);
            }

            var convertedInstance = NetworkCommandDataConverterService.ConvertToObject(networkCommandConnectionToHandle);

            if (convertedInstance as UserData == null)
            {
                ThrowError(gameStateContext, networkCommandConnectionToHandle);
            }

            //Actual router. Only one state will fire. See that the order of the entries in Router also provides the priority.
            //TODO: this should be a feature/library in the future
            var userRoles        = UserDataRoleService.GetRoles(convertedInstance as UserData);
            var userRolesHandler = gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)Routes.FirstOrDefault(kv => userRoles.HasFlag(kv.Key)).Value);

            gameStateContext.ChangeHandlerEasier(userRolesHandler, networkCommandConnectionToHandle);
            userRolesHandler.Handle(gameStateContext, networkCommandConnectionToHandle);
        }
示例#4
0
 public void Handle(INetworkStateContext <TWorld> gameStatecontext, NetworkCommandConnection networkCommandConnection)
 {
     if (networkCommandConnection == null)
     {
         return;
     }
     gameStatecontext.ChangeHandlerEasier(gameStatecontext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.Login), networkCommandConnection); //where to?
     gameStatecontext[networkCommandConnection.ConnectionId].Handle(gameStatecontext, networkCommandConnection);
 }
 public void Handle(INetworkStateContext <TWorld> gameStateContext, NetworkCommandConnection networkCommandConnection)
 {
     if (networkCommandConnection == null)
     {
         return;
     }
     try
     {
         var gData = CurrentNetworkCommandToInitialGameState.Translate(networkCommandConnection);
         if (!HasValidGameStateData(gData))
         {
             gameStateContext.ChangeHandlerEasier(gameStateContext[(byte)ServerInternalGameStates.Login], networkCommandConnection);
         }
     }
     catch (Exception)
     {
         gameStateContext.ChangeHandlerEasier(gameStateContext[(byte)ServerInternalGameStates.Error], networkCommandConnection);
     }
     gameStateContext[networkCommandConnection.ConnectionId].Handle(gameStateContext, networkCommandConnection);
 }
示例#6
0
        public void Handle(INetworkStateContext <TWorld> gameStateContext, NetworkCommandConnection networkCommandConnectionToHandle)
        {
            try
            {
                throw new InvalidOperationException(networkCommandConnectionToHandle.Data);
            }
            catch (Exception ex)
            {
                gameStateContext.Logger.Log(LogLevel.Error, ex.Message + Environment.NewLine + ex.InnerException?.Message);
            }

            gameStateContext.ChangeHandlerEasier(gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.Login), networkCommandConnectionToHandle);
        }
        // private bool HasValidGameStateData(GameStateData gameStateData)
        // {
        //     if (gameStateData == null ||
        //         string.IsNullOrWhiteSpace(gameStateData?.LoginToken))
        //         return false;
        //     return true;
        // }

        public void Handle(INetworkStateContext <TWorld> gameStateContext, NetworkCommandConnection networkCommandConnectionToHandle)
        {
            try
            {
                //converts user to login token. If user is not registered, it will be... else ..boom
                var gameStateData = CurrentNetworkCommandToLoginGameState.Translate(networkCommandConnectionToHandle);
                gameStateContext.Logger.Log(LogLevel.Information, "RegisterGameStateData");
                gameStateData = gameStateContext.GameStateRegistrar.WorldGameStateDataLayer.RegisterGameStateData(gameStateData.LoginToken);

                gameStateContext.Logger.Log(LogLevel.Information, "SendToClient UpdateCommand register token data");
                gameStateContext.CurrentNetOutgoingMessageBusService.SendToClient(NetworkCommandConstants.UpdateCommand, gameStateData, networkCommandConnectionToHandle.Connection);

                gameStateContext.Logger.Log(LogLevel.Information, "LoginSuccessful");
                gameStateContext.ChangeHandlerEasier(gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.LoginSuccessful), networkCommandConnectionToHandle);
            }
            catch (System.Exception ex)
            {
                gameStateContext.Logger.Log(LogLevel.Error, ex.Message);
                gameStateContext.Logger.Log(LogLevel.Error, ex.InnerException?.Message);
                gameStateContext.ChangeHandlerEasier(gameStateContext[(byte)ServerInternalGameStates.Error], networkCommandConnectionToHandle);
            }
            gameStateContext[networkCommandConnectionToHandle.ConnectionId].Handle(gameStateContext, networkCommandConnectionToHandle);
        }
 private void ThrowError(INetworkStateContext <TWorld> gameStateContext, NetworkCommandConnection networkCommandConnectionToHandle)
 {
     gameStateContext.Logger.Log(LogLevel.Error, $"Cannot transition user to update state. Command argument is not of type user data. Type is {networkCommandConnectionToHandle.CommandArgument}");
     gameStateContext.ChangeHandlerEasier(gameStateContext.GameStateRegistrar.GetNeworkLayerState((byte)ServerInternalGameStates.Error), networkCommandConnectionToHandle);
 }