public void AddServerCommand(LogicServerCommand serverCommand) { if (this.m_logicGameMode.GetState() != 1) { throw new Exception("GameMode.addServerCommand: Method called in invalid game state."); } this.m_serverCommandStorage.AddServerCommand(serverCommand); AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(serverCommand); this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1); }
public async Task <JObject> ExecuteDebugCommand(int id, [FromQuery(Name = "userId")] long accountId, [FromQuery(Name = "pass")] string passToken) { AccountDocument accountDocument = await UserManager.GetAccount(accountId); if (accountDocument == null) { return(this.BuildResponse(HttpStatusCode.InternalServerError)); } if (this.GetUserRole() <= UserRole.NULL && passToken != accountDocument.PassToken) { return(this.BuildResponse(HttpStatusCode.Forbidden)); } RedisValue currentSession = await ServerAdmin.SessionDatabase.Get(accountDocument.Id); if (currentSession.IsNull) { return(this.BuildResponse(HttpStatusCode.Forbidden).AddAttribute("reason", "No client connected.")); } LogicDebugCommand logicDebugCommand = null; switch ((DebugCommandType)id) { case DebugCommandType.FAST_FORWARD_1_HOUR: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.FAST_FORWARD_1_HOUR); break; case DebugCommandType.FAST_FORWARD_24_HOUR: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.FAST_FORWARD_24_HOUR); break; case DebugCommandType.ADD_UNITS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_UNITS); break; case DebugCommandType.ADD_RESOURCES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_RESOURCES); break; case DebugCommandType.INCREASE_XP_LEVEL: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.INCREASE_XP_LEVEL); break; case DebugCommandType.UPGRADE_ALL_BUILDINGS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.UPGRADE_ALL_BUILDINGS); break; case DebugCommandType.COMPLETE_TUTORIAL: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.COMPLETE_TUTORIAL); break; case DebugCommandType.UNLOCK_MAP: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.UNLOCK_MAP); break; case DebugCommandType.SHIELD_TO_HALF: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.SHIELD_TO_HALF); break; case DebugCommandType.FAST_FORWARD_1_MIN: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.FAST_FORWARD_1_MIN); break; case DebugCommandType.INCREASE_TROPHIES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.INCREASE_TROPHIES); break; case DebugCommandType.DECREASE_TROPHIES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.DECREASE_TROPHIES); break; case DebugCommandType.ADD_ALLIANCE_UNITS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_ALLIANCE_UNITS); break; case DebugCommandType.INCREASE_HERO_LEVELS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.INCREASE_HERO_LEVELS); break; case DebugCommandType.REMOVE_RESOURCES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.REMOVE_RESOURCES); break; case DebugCommandType.RESET_MAP_PROGRESS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.RESET_MAP_PROGRESS); break; case DebugCommandType.DEPLOY_ALL_TROOPS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.DEPLOY_ALL_TROOPS); break; case DebugCommandType.ADD_100_TROPHIES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_100_TROPHIES); break; case DebugCommandType.REMOVE_100_TROPHIES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.REMOVE_100_TROPHIES); break; case DebugCommandType.UPGRADE_TO_MAX_FOR_TH: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.UPGRADE_TO_MAX_FOR_TH); break; case DebugCommandType.REMOVE_UNITS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.REMOVE_UNITS); break; case DebugCommandType.DISARM_TRAPS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.DISARM_TRAPS); break; case DebugCommandType.REMOVE_OBSTACLES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.REMOVE_OBSTACLES); break; case DebugCommandType.RESET_HERO_LEVELS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.RESET_HERO_LEVELS); break; case DebugCommandType.COLLECT_WAR_RESOURCES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.COLLECT_WAR_RESOURCES); break; case DebugCommandType.SET_RANDOM_TROPHIES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.SET_RANDOM_TROPHIES); break; case DebugCommandType.COMPLETE_WAR_TUTORIAL: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.COMPLETE_WAR_TUTORIAL); break; case DebugCommandType.ADD_WAR_RESOURCES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_WAR_RESOURCES); break; case DebugCommandType.REMOVE_WAR_RESOURCES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.REMOVE_WAR_RESOURCES); break; case DebugCommandType.RESET_WAR_TUTORIAL: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.RESET_WAR_TUTORIAL); break; case DebugCommandType.ADD_UNIT: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_UNIT); break; case DebugCommandType.SET_MAX_UNIT_SPELL_LEVELS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.SET_MAX_UNIT_SPELL_LEVELS); break; case DebugCommandType.REMOVE_ALL_AMMO: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.REMOVE_ALL_AMMO); break; case DebugCommandType.RESET_ALL_LAYOUTS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.RESET_ALL_LAYOUTS); break; case DebugCommandType.LOCK_CLAN_CASTLE: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.LOCK_CLAN_CASTLE); break; case DebugCommandType.RANDOM_RESOURCES_TROPHY_XP: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.RANDOM_RESOURCES_TROPHY_XP); break; case DebugCommandType.LOAD_LEVEL: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.LOAD_LEVEL); logicDebugCommand.SetDebugString(UserManager.GetPresetLevel()); break; case DebugCommandType.UPGRADE_BUILDING: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.UPGRADE_BUILDING); break; case DebugCommandType.UPGRADE_BUILDINGS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.UPGRADE_BUILDINGS); break; case DebugCommandType.ADD_1000_CLAN_XP: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_1000_CLAN_XP); break; case DebugCommandType.RESET_ALL_TUTORIALS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.RESET_ALL_TUTORIALS); break; case DebugCommandType.ADD_1000_TROPHIES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_1000_TROPHIES); break; case DebugCommandType.REMOVE_1000_TROPHIES: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.REMOVE_1000_TROPHIES); break; case DebugCommandType.CAUSE_DAMAGE: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.CAUSE_DAMAGE); break; case DebugCommandType.SET_MAX_HERO_LEVELS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.SET_MAX_HERO_LEVELS); break; case DebugCommandType.ADD_PRESET_TROOPS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_PRESET_TROOPS); break; case DebugCommandType.TOGGLE_INVULNERABILITY: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.TOGGLE_INVULNERABILITY); break; case DebugCommandType.ADD_GEMS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_GEMS); break; case DebugCommandType.PAUSE_ALL_BOOSTS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.PAUSE_ALL_BOOSTS); break; case DebugCommandType.TRAVEL: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.TRAVEL); break; case DebugCommandType.TOGGLE_RED: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.TOGGLE_RED); break; case DebugCommandType.COMPLETE_HOME_TUTORIALS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.COMPLETE_HOME_TUTORIALS); break; case DebugCommandType.UNLOCK_SHIPYARD: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.UNLOCK_SHIPYARD); break; case DebugCommandType.GIVE_REENGAGEMENT_LOOT_FOR_30_DAYS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.GIVE_REENGAGEMENT_LOOT_FOR_30_DAYS); break; case DebugCommandType.ADD_FREE_UNITS: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.ADD_FREE_UNITS); break; case DebugCommandType.RANDOM_ALLIANCE_EXP_LEVEL: logicDebugCommand = new LogicDebugCommand(LogicDebugActionType.RANDOM_ALLIANCE_EXP_LEVEL); break; } if (logicDebugCommand == null) { return(this.BuildResponse(HttpStatusCode.InternalServerError)); } long sessionId = long.Parse(currentSession); AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(logicDebugCommand); availableServerCommandMessage.Encode(); ServerMessageManager.SendMessage(new ForwardLogicMessage { MessageType = availableServerCommandMessage.GetMessageType(), MessageLength = availableServerCommandMessage.GetEncodingLength(), MessageVersion = (short)availableServerCommandMessage.GetMessageVersion(), MessageBytes = availableServerCommandMessage.GetByteStream().GetByteArray(), SessionId = sessionId }, ServerManager.GetProxySocket(sessionId)); return(this.BuildResponse(HttpStatusCode.OK)); }
private static void OnGameStartFakeAttackMessageReceived(GameStartFakeAttackMessage message) { if (GameSessionManager.TryGet(message.SessionId, out GameSession session)) { if (message.AccountId != null) { ServerRequestManager.Create(new GameAvatarRequestMessage { AccountId = message.AccountId }, ServerManager.GetDocumentSocket(9, message.AccountId)).OnComplete = args => { if (session.IsDestructed()) { return; } if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success) { GameState currentGameState = session.GameState; if (currentGameState != null && currentGameState.GetGameStateType() == GameStateType.HOME) { GameAvatarResponseMessage gameAvatarResponseMessage = (GameAvatarResponseMessage)args.ResponseMessage; GameDocument document = gameAvatarResponseMessage.Document; AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(new LogicMatchmakingCommand()); session.SendPiranhaMessage(availableServerCommandMessage, 1); session.FakeAttackState = new GameFakeAttackState { Home = document.LogicClientHome, HomeOwnerAvatar = document.LogicClientAvatar, PlayerAvatar = session.GameAvatar.LogicClientAvatar, SaveTime = document.SaveTime, MaintenanceTime = document.MaintenanceTime }; } } else { AttackHomeFailedMessage attackHomeFailedMessage = new AttackHomeFailedMessage(); attackHomeFailedMessage.SetReason(AttackHomeFailedMessage.Reason.GENERIC); session.SendPiranhaMessage(attackHomeFailedMessage, 1); } }; } else { GameState currentGameState = session.GameState; if (currentGameState != null && currentGameState.GetGameStateType() == GameStateType.HOME) { AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(new LogicMatchmakingCommand()); session.SendPiranhaMessage(availableServerCommandMessage, 1); session.FakeAttackState = new GameFakeAttackState { Home = GameBaseGenerator.GenerateBase((LogicGameObjectData)message.ArgData), HomeOwnerAvatar = GameBaseGenerator.HomeOwnerAvatar, PlayerAvatar = session.GameAvatar.LogicClientAvatar, SaveTime = TimeUtil.GetTimestamp(), MaintenanceTime = -1 }; } } } }
private void OnSendGlobalChatLineMessageReceived(SendGlobalChatLineMessage message) { if (!this.CanSendGlobalChatMessage()) { return; } string chatMessage = StringUtil.RemoveMultipleSpaces(message.RemoveMessage()); if (chatMessage.Length > 0) { if (chatMessage.Length > 128) { chatMessage = chatMessage.Substring(0, 128); } if (chatMessage.StartsWith("/op ")) { string[] args = chatMessage.Trim().Split(' '); if (args.Length < 3) { return; } string commandType = args[1]; string commandName = args[2]; switch (commandType) { case "attack": { if (string.Equals(commandName, "me", StringComparison.InvariantCultureIgnoreCase)) { this.m_session.SendMessage(new GameStartFakeAttackMessage { AccountId = this.m_session.AccountId, ArgData = null }, 9); } else if (commandName.StartsWith("#")) { LogicLong accountId = HashTagCodeGenerator.m_instance.ToId(commandName.ToUpperInvariant()); if (accountId != null) { this.m_session.SendMessage(new GameStartFakeAttackMessage { AccountId = accountId, ArgData = null }, 9); } } else if (string.Equals(commandName, "generate", StringComparison.InvariantCultureIgnoreCase)) { if (args.Length >= 4) { if (int.TryParse(args[3], out int id)) { LogicGameObjectData gameObjectData = null; switch (id / 100) { case 0: LogicBuildingData buildingData = (LogicBuildingData)LogicDataTables.GetDataById(GlobalID.CreateGlobalID((int)LogicDataType.BUILDING + 1, id), LogicDataType.BUILDING); if (buildingData.IsTownHall() || buildingData.IsTownHallVillage2()) { return; } if (!buildingData.IsEnabledInVillageType(0)) { return; } if (buildingData.IsLocked() && !buildingData.IsAllianceCastle()) { return; } gameObjectData = buildingData; break; case 1: gameObjectData = (LogicGameObjectData)LogicDataTables.GetDataById(GlobalID.CreateGlobalID((int)LogicDataType.TRAP + 1, id), LogicDataType.TRAP); break; } if (gameObjectData != null) { this.m_session.SendMessage(new GameStartFakeAttackMessage { AccountId = null, ArgData = gameObjectData }, 9); } } } else { this.m_session.SendMessage(new GameStartFakeAttackMessage { AccountId = null, ArgData = null }, 9); } } break; } case "village": switch (commandName) { case "upgrade": { AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.UPGRADE_ALL_BUILDINGS)); this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1); break; } case "obstacle": { AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.REMOVE_OBSTACLES)); this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1); break; } case "preset": // TODO: Implement this. break; } break; case "hero": switch (commandName) { case "max": { AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.SET_MAX_HERO_LEVELS)); this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1); return; } case "reset": { AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.RESET_HERO_LEVELS)); this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1); return; } } break; case "unit": switch (commandName) { case "max": { AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.SET_MAX_UNIT_SPELL_LEVELS)); this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1); return; } } break; } } else { ServerRequestManager.Create(new AvatarRequestMessage { AccountId = this.m_session.AccountId }, ServerManager.GetDocumentSocket(9, this.m_session.AccountId)).OnComplete = args => { if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success) { this.m_session.ChatInstance.PublishMessage(((AvatarResponseMessage)args.ResponseMessage).LogicClientAvatar, WordCensorUtil.FilterMessage(chatMessage)); this.m_previousGlobalChatMessageTime = DateTime.UtcNow; } }; } } }