bool C4MainMenu::MenuCommand(const char *szCommand, bool fIsCloseCommand) { // Determine player C4Player *pPlr = ::Players.Get(Player); // Activate if (SEqual2(szCommand,"ActivateMenu:")) { if (C4GameOverDlg::IsShown()) return false; // no new menus during game over dlg if (SEqual(szCommand+13,"Main")) return ActivateMain(Player); if (SEqual(szCommand+13,"Hostility")) return ActivateHostility(Player); if (SEqual(szCommand+13,"NewPlayer")) return ActivateNewPlayer(Player); if (SEqual(szCommand+13,"Goals")) { ::Control.DoInput(CID_PlrAction, C4ControlPlayerAction::ActivateGoalMenu(::Players.Get(Player)), CDT_Queue); return true; } if (SEqual(szCommand+13,"Rules")) return ActivateRules(Player); if (SEqual(szCommand+13,"Host")) return ActivateHost(Player); if (SEqual(szCommand+13,"Client")) return ActivateClient(Player); if (SEqual(szCommand+13,"Options")) return ActivateOptions(Player); if (SEqual(szCommand+13,"Display")) return ActivateDisplay(Player); if (SEqual(szCommand+13,"Save:Game")) return ActivateSavegame(Player); if (SEqual(szCommand+13,"TeamSel")) return pPlr ? pPlr->ActivateMenuTeamSelection(true) : false; if (SEqual(szCommand+13,"Surrender")) return ActivateSurrender(Player); if (SEqual(szCommand+13,"Observer")) return ActivateObserver(); } // JoinPlayer if (SEqual2(szCommand,"JoinPlayer:")) { // not in league or replay mode if (Game.Parameters.isLeague() || Game.C4S.Head.Replay) return false; // join player // 2do: not for observers and such? Players.JoinNew(szCommand+11); return true; } // SetHostility if (SEqual2(szCommand,"SetHostility:")) { // only if allowed if (!Game.Teams.IsHostilityChangeAllowed()) return false; int32_t iOpponent; sscanf(szCommand+13,"%i",&iOpponent); C4Player *pOpponent = ::Players.Get(iOpponent); if (!pOpponent || pOpponent->GetType() != C4PT_User) return false; ::Control.DoInput(CID_PlrAction, C4ControlPlayerAction::SetHostility(::Players.Get(Player), pOpponent, !::Players.HostilityDeclared(Player, pOpponent->Number)), CDT_Queue); return true; } // Abort if (SEqual2(szCommand,"Abort")) { FullScreen.ShowAbortDlg(); return true; } // Surrender if (SEqual2(szCommand,"Surrender")) { ::Control.DoInput(CID_PlrAction, C4ControlPlayerAction::Surrender(::Players.Get(Player)), CDT_Queue); return true; } // Save game if (SEqual2(szCommand, "Save:Game:")) { char strFilename[_MAX_PATH + 1]; SCopySegment(szCommand, 2, strFilename, ':', _MAX_PATH); char strTitle[_MAX_PATH + 1]; SCopy(szCommand + SCharPos(':', szCommand, 2) + 1, strTitle, _MAX_PATH); Game.QuickSave(strFilename, strTitle); ActivateSavegame(Player); return true; } // Kick if (SEqual2(szCommand,"Host:Kick:")) { int iClientID = atoi(szCommand+10); if (iClientID && ::Network.isEnabled()) { if (Game.Parameters.isLeague() && ::Players.GetAtClient(iClientID)) ::Network.Vote(VT_Kick, true, iClientID); else { C4Client *pClient = Game.Clients.getClientByID(iClientID); if (pClient) Game.Clients.CtrlRemove(pClient, LoadResStr("IDS_MSG_KICKBYMENU")); Close(true); } } return true; } // Part if (SEqual2(szCommand,"Part")) { if (::Network.isEnabled()) { if (Game.Parameters.isLeague() && ::Players.GetLocalByIndex(0)) ::Network.Vote(VT_Kick, true, ::Control.ClientID()); else { Game.RoundResults.EvaluateNetwork(C4RoundResults::NR_NetError, LoadResStr("IDS_ERR_GAMELEFTVIAPLAYERMENU")); ::Network.Clear(); } } return true; } // Options if (SEqual2(szCommand,"Options:")) { // Music if (SEqual(szCommand + 8, "Music")) { Application.MusicSystem.ToggleOnOff(); } // Sound if (SEqual(szCommand + 8, "Sound")) { if (Config.Sound.RXSound) { Application.SoundSystem.Clear(); Config.Sound.RXSound = false; } else { Config.Sound.RXSound = true; if (!Application.SoundSystem.Init()) { Log(LoadResStr("IDS_PRC_NOSND")); } } } // Reopen with updated options ActivateOptions(Player, GetSelection()); return true; } // Display if (SEqual2(szCommand,"Display:")) { // Upper board if (SEqual(szCommand + 8, "UpperBoard")) { Config.Graphics.UpperBoard = !Config.Graphics.UpperBoard; ::Viewports.RecalculateViewports(); } // FPS if (SEqual(szCommand + 8, "FPS")) Config.General.FPS = !Config.General.FPS; // Player names if (SEqual(szCommand + 8, "PlayerNames")) Config.Graphics.ShowCrewNames = !Config.Graphics.ShowCrewNames; // Clonk names if (SEqual(szCommand + 8, "ClonkNames")) Config.Graphics.ShowCrewCNames = !Config.Graphics.ShowCrewCNames; // Clock if (SEqual(szCommand + 8, "Clock")) Config.Graphics.ShowClock = !Config.Graphics.ShowClock; // Reopen with updated options ActivateDisplay(Player, GetSelection()); return true; } // Goal info if (SEqual2(szCommand,"Player:Goal:") || SEqual2(szCommand,"Player:Rule:")) { if (!ValidPlr(Player)) return false; // observers may not look at goal/rule info, because it requires queue activation Close(true); C4Object *pObj; C4ID idItem(szCommand+12); C4Def * pDef = C4Id2Def(idItem); if (pDef && (pObj = ::Objects.Find(pDef))) ::Control.DoInput(CID_PlrAction, C4ControlPlayerAction::ActivateGoal(::Players.Get(Player), pObj), CDT_Queue); else return false; return true; } // Team selection if (SEqual2(szCommand, "TeamSel:")) { Close(true); int32_t idTeam = atoi(szCommand+8); // OK, join this team if (pPlr) pPlr->DoTeamSelection(idTeam); return true; } // Team switch if (SEqual2(szCommand, "TeamSwitch:")) { Close(true); int32_t idTeam = atoi(szCommand+11); // check if it's still allowed if (!Game.Teams.IsTeamSwitchAllowed()) return false; // OK, join this team ::Control.DoInput(CID_PlrAction, C4ControlPlayerAction::SetTeam(::Players.Get(Player), idTeam), CDT_Queue); return true; } // Observe if (SEqual2(szCommand, "Observe:")) { const char *szObserverTarget = szCommand+8; C4Viewport *pVP = ::Viewports.GetViewport(NO_OWNER); if (pVP) // viewport may have closed meanwhile { if (SEqual(szObserverTarget, "Free")) { // free view pVP->Init(NO_OWNER, true); return true; } else { // view following player int32_t iPlr = atoi(szObserverTarget); if (ValidPlr(iPlr)) { pVP->Init(iPlr, true); return true; } } } return false; } // No valid command return false; }
_Use_decl_annotations_ NTSTATUS NDISFilterDriverDeviceIoControl( PDEVICE_OBJECT DeviceObject, PIRP Irp ) { DbgPrint("NDISFilterDriverDeviceIoControl\n"); PIO_STACK_LOCATION IrpSp; NTSTATUS Status = STATUS_SUCCESS; PFILTER_DEVICE_EXTENSION FilterDeviceExtension; PUCHAR InputBuffer; PUCHAR OutputBuffer; ULONG InputBufferLength, OutputBufferLength; PLIST_ENTRY Link; PUCHAR pInfo; ULONG InfoLength = 0; PMS_FILTER pFilter = NULL; BOOLEAN bFalse = FALSE; UNREFERENCED_PARAMETER(DeviceObject); KIRQL OldIrql; IrpSp = IoGetCurrentIrpStackLocation(Irp); if (IrpSp->FileObject == NULL) { return(STATUS_UNSUCCESSFUL); } FilterDeviceExtension = (PFILTER_DEVICE_EXTENSION)NdisGetDeviceReservedExtension(DeviceObject); ASSERT(FilterDeviceExtension->Signature == 'FTDR'); Irp->IoStatus.Information = 0; KeAcquireSpinLock(&FilterDeviceExtension->QLock, &OldIrql); switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) { case IOCTL_ADD_IPV4_RULE: DbgPrint("IOCTL_ADD_IPV4_RULE BEGIN\n"); InputBuffer = Irp->UserBuffer; InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; if (InputBufferLength != sizeof(RULE_IPV4)) { Status = NDIS_STATUS_FAILURE; break; } PRULE_IPV4 pRuleIPv4 = ExAllocatePool(NonPagedPool, sizeof(RULE_IPV4)); RtlCopyMemory(pRuleIPv4, InputBuffer, InputBufferLength); AddIPv4Rule(FilterDeviceExtension, pRuleIPv4); DbgPrint("IOCTL_ADD_IPV4_RULE END\n"); break; case IOCTL_DEL_IPV4_RULE: DbgPrint("IOCTL_DEL_IPV4_RULE BEGIN\n"); InputBuffer = Irp->UserBuffer; InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; if (InputBufferLength != sizeof(ULONG)) { Status = NDIS_STATUS_FAILURE; break; } ULONG IdIPv4 = *((PULONG)(InputBuffer)); DelIPv4Rule(FilterDeviceExtension, IdIPv4); DbgPrint("IOCTL_DEL_IPV4_RULE END\n"); break; case IOCTL_ADD_IPV6_RULE: DbgPrint("IOCTL_ADD_IPV6_RULE BEGIN\n"); InputBuffer = Irp->UserBuffer; InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; if (InputBufferLength != sizeof(RULE_IPV6)) { Status = NDIS_STATUS_FAILURE; break; } PRULE_IPV6 pRuleIPv6 = ExAllocatePool(NonPagedPool, sizeof(RULE_IPV6)); RtlCopyMemory(pRuleIPv6, InputBuffer, InputBufferLength); AddIPv6Rule(FilterDeviceExtension, pRuleIPv6); DbgPrint("IOCTL_ADD_IPV6_RULE END\n"); break; case IOCTL_DEL_IPV6_RULE: DbgPrint("IOCTL_DEL_IPV6_RULE BEGIN\n"); InputBuffer = Irp->UserBuffer; InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; if (InputBufferLength != sizeof(ULONG)) { Status = NDIS_STATUS_FAILURE; break; } ULONG IdIPv6 = *((PULONG)(InputBuffer)); DelIPv6Rule(FilterDeviceExtension, IdIPv6); DbgPrint("IOCTL_END_IPV6_RULE END\n"); break; case IOCTL_ACTIVATE_FILTER: DbgPrint("IOCTL_ACTIVATE_FILTER BEGIN\n"); InputBuffer = Irp->UserBuffer; InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; if (InputBufferLength != 0) { Status = NDIS_STATUS_FAILURE; break; } ActivateRules(FilterDeviceExtension); DbgPrint("IOCTL_ACTIVATE_FILTER END\n"); break; case IOCTL_DEACTIVATE_FILTER: DbgPrint("IOCTL_DEACTIVATE_FILTER BEGIN\n"); InputBuffer = Irp->UserBuffer; InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; if (InputBufferLength != 0) { Status = NDIS_STATUS_FAILURE; break; } DeactivateRules(FilterDeviceExtension); DbgPrint("IOCTL_DEACTIVATE_FILTER END\n"); break; case IOCTL_FILTER_RESTART_ALL: break; case IOCTL_FILTER_RESTART_ONE_INSTANCE: InputBuffer = OutputBuffer = (PUCHAR)Irp->AssociatedIrp.SystemBuffer; InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; pFilter = filterFindFilterModule (InputBuffer, InputBufferLength); if (pFilter == NULL) { break; } NdisFRestartFilter(pFilter->FilterHandle); break; case IOCTL_FILTER_ENUERATE_ALL_INSTANCES: InputBuffer = OutputBuffer = (PUCHAR)Irp->AssociatedIrp.SystemBuffer; InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength; pInfo = OutputBuffer; FILTER_ACQUIRE_LOCK(&FilterListLock, bFalse); Link = FilterModuleList.Flink; while (Link != &FilterModuleList) { pFilter = CONTAINING_RECORD(Link, MS_FILTER, FilterModuleLink); InfoLength += (pFilter->FilterModuleName.Length + sizeof(USHORT)); if (InfoLength <= OutputBufferLength) { *(PUSHORT)pInfo = pFilter->FilterModuleName.Length; NdisMoveMemory(pInfo + sizeof(USHORT), (PUCHAR)(pFilter->FilterModuleName.Buffer), pFilter->FilterModuleName.Length); pInfo += (pFilter->FilterModuleName.Length + sizeof(USHORT)); } Link = Link->Flink; } FILTER_RELEASE_LOCK(&FilterListLock, bFalse); if (InfoLength <= OutputBufferLength) { Status = NDIS_STATUS_SUCCESS; } // // Buffer is small // else { Status = STATUS_BUFFER_TOO_SMALL; } break; default: break; } KeReleaseSpinLock(&FilterDeviceExtension->QLock, OldIrql); Irp->IoStatus.Status = Status; Irp->IoStatus.Information = InfoLength; IoCompleteRequest(Irp, IO_NO_INCREMENT); return Status; }