OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4MessageInput Class Reference

#include <C4MessageInput.h>

Public Member Functions

 C4MessageInput ()
 
 ~C4MessageInput ()
 
void Default ()
 
void Clear ()
 
bool Init ()
 
void AddCommand (const char *strCommand, const char *strScript)
 
class C4MessageBoardCommandGetCommand (const char *strName)
 
bool CloseTypeIn ()
 
bool StartTypeIn (bool fObjInput=false, C4Object *pObj=nullptr, bool fUpperCase=false, bool fTeam=false, int32_t iPlr=-1, const StdStrBuf &rsInputQuery=StdStrBuf())
 
bool KeyStartTypeIn (bool fTeam)
 
bool ToggleTypeIn ()
 
bool IsTypeIn ()
 
C4ChatInputDialogGetTypeIn ()
 
void StoreBackBuffer (const char *szMessage)
 
const char * GetBackBuffer (int32_t iIndex)
 
bool ProcessInput (const char *szText)
 
bool ProcessCommand (const char *szCommand)
 
void ClearPointers (C4Object *pObj)
 
void AbortMsgBoardQuery (C4Object *pObj, int32_t iPlr)
 

Friends

class C4ChatInputDialog
 

Detailed Description

Definition at line 106 of file C4MessageInput.h.

Constructor & Destructor Documentation

C4MessageInput::C4MessageInput ( )
inline

Definition at line 109 of file C4MessageInput.h.

References Default().

109 : pCommands(nullptr) { Default(); }

Here is the call graph for this function:

C4MessageInput::~C4MessageInput ( )
inline

Definition at line 110 of file C4MessageInput.h.

References Clear().

110 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

void C4MessageInput::AbortMsgBoardQuery ( C4Object pObj,
int32_t  iPlr 
)

Definition at line 861 of file C4MessageInput.cpp.

References CloseTypeIn(), C4ChatInputDialog::GetScriptTargetObject(), C4ChatInputDialog::GetScriptTargetPlayer(), GetTypeIn(), and C4ChatInputDialog::IsScriptQueried().

862 {
863  // close typein if it is used for the given parameters
864  C4ChatInputDialog *pDlg = GetTypeIn();
865  if (pDlg && pDlg->IsScriptQueried() && pDlg->GetScriptTargetObject() == pObj && pDlg->GetScriptTargetPlayer() == iPlr) CloseTypeIn();
866 }
C4ChatInputDialog * GetTypeIn()
bool IsScriptQueried() const
class C4Object * GetScriptTargetObject() const
int32_t GetScriptTargetPlayer() const

Here is the call graph for this function:

void C4MessageInput::AddCommand ( const char *  strCommand,
const char *  strScript 
)

Definition at line 835 of file C4MessageInput.cpp.

References _MAX_FNAME, C4MaxName, GetCommand(), C4MessageBoardCommand::Name, C4MessageBoardCommand::Next, SCopy(), and C4MessageBoardCommand::Script.

Referenced by Init().

836 {
837  if (GetCommand(strCommand)) return;
838  // create entry
840  SCopy(strCommand, pCmd->Name, C4MaxName);
841  SCopy(strScript, pCmd->Script, _MAX_FNAME+30);
842  // add to list
843  pCmd->Next = pCommands; pCommands = pCmd;
844 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
C4MessageBoardCommand * Next
char Script[_MAX_FNAME+30+1]
const unsigned int C4MaxName
#define _MAX_FNAME
char Name[C4MaxName+1]
class C4MessageBoardCommand * GetCommand(const char *strName)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MessageInput::Clear ( )

Definition at line 255 of file C4MessageInput.cpp.

References CloseTypeIn(), and C4MessageBoardCommand::Next.

Referenced by C4Game::Clear(), and ~C4MessageInput().

256 {
257  // close any dialog
258  CloseTypeIn();
259  // free messageboard-commands
260  C4MessageBoardCommand *pCmd;
261  while ((pCmd = pCommands))
262  {
263  pCommands = pCmd->Next;
264  delete pCmd;
265  }
266 }
C4MessageBoardCommand * Next

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MessageInput::ClearPointers ( C4Object pObj)

Definition at line 854 of file C4MessageInput.cpp.

References CloseTypeIn(), C4ChatInputDialog::GetScriptTargetObject(), and GetTypeIn().

Referenced by C4Game::ClearPointers().

855 {
856  // target object loose? stop input
857  C4ChatInputDialog *pDlg = GetTypeIn();
858  if (pDlg && pDlg->GetScriptTargetObject() == pObj) CloseTypeIn();
859 }
C4ChatInputDialog * GetTypeIn()
class C4Object * GetScriptTargetObject() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MessageInput::CloseTypeIn ( )

Definition at line 268 of file C4MessageInput.cpp.

References C4GUI::Dialog::Close(), and GetTypeIn().

Referenced by AbortMsgBoardQuery(), Clear(), ClearPointers(), StartTypeIn(), and ToggleTypeIn().

269 {
270  // close dialog if present and valid
271  C4ChatInputDialog *pDlg = GetTypeIn();
272  if (!pDlg) return false;
273  pDlg->Close(false);
274  return true;
275 }
C4ChatInputDialog * GetTypeIn()
void Close(bool fOK)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MessageInput::Default ( )

Definition at line 249 of file C4MessageInput.cpp.

References C4MSGB_BackBufferMax.

Referenced by C4MessageInput(), and C4Game::Default().

250 {
251  // clear backlog
252  for (int32_t cnt=0; cnt<C4MSGB_BackBufferMax; cnt++) BackBuffer[cnt][0]=0;
253 }
const int32_t C4MSGB_BackBufferMax

Here is the caller graph for this function:

const char * C4MessageInput::GetBackBuffer ( int32_t  iIndex)

Definition at line 882 of file C4MessageInput.cpp.

References C4MSGB_BackBufferMax.

Referenced by C4GameLobby::MainDlg::KeyHistoryUpDown().

883 {
884  if (!Inside<int32_t>(iIndex, 0, C4MSGB_BackBufferMax-1)) return nullptr;
885  return BackBuffer[iIndex];
886 }
const int32_t C4MSGB_BackBufferMax

Here is the caller graph for this function:

C4MessageBoardCommand * C4MessageInput::GetCommand ( const char *  strName)

Definition at line 846 of file C4MessageInput.cpp.

References C4MessageBoardCommand::Next, and SEqual().

Referenced by AddCommand(), and ProcessCommand().

847 {
848  for (C4MessageBoardCommand *pCmd = pCommands; pCmd; pCmd = pCmd->Next)
849  if (SEqual(pCmd->Name, strName))
850  return pCmd;
851  return nullptr;
852 }
C4MessageBoardCommand * Next
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97

Here is the call graph for this function:

Here is the caller graph for this function:

C4ChatInputDialog* C4MessageInput::GetTypeIn ( )
inline

Definition at line 133 of file C4MessageInput.h.

References C4ChatInputDialog::GetInstance().

Referenced by AbortMsgBoardQuery(), ClearPointers(), CloseTypeIn(), and ToggleTypeIn().

133 { return C4ChatInputDialog::GetInstance(); }
static C4ChatInputDialog * GetInstance()

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MessageInput::Init ( )

Definition at line 239 of file C4MessageInput.cpp.

References AddCommand().

Referenced by C4Game::PreInit().

240 {
241  // add default commands
242  if (!pCommands)
243  {
244  AddCommand("speed", "SetGameSpeed(%d)");
245  }
246  return true;
247 }
void AddCommand(const char *strCommand, const char *strScript)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MessageInput::IsTypeIn ( )

Definition at line 307 of file C4MessageInput.cpp.

References C4ChatInputDialog::IsShown().

Referenced by C4MessageBoard::Execute(), StartTypeIn(), and ToggleTypeIn().

308 {
309  // check GUI and dialog
311 }
static bool IsShown()

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MessageInput::KeyStartTypeIn ( bool  fTeam)

Definition at line 285 of file C4MessageInput.cpp.

References Application, C4Application::isEditor, and StartTypeIn().

Referenced by C4Game::InitKeyboard().

286 {
287  // fullscreen only
288  if (Application.isEditor) return false;
289  // OK, start typing
290  return StartTypeIn(false, nullptr, false, fTeam);
291 }
bool StartTypeIn(bool fObjInput=false, C4Object *pObj=nullptr, bool fUpperCase=false, bool fTeam=false, int32_t iPlr=-1, const StdStrBuf &rsInputQuery=StdStrBuf())
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MessageInput::ProcessCommand ( const char *  szCommand)

Definition at line 428 of file C4MessageInput.cpp.

References C4Network2::AbortLobbyCountdown(), C4ConfigDeveloper::AltTodoFilename, CStdFile::Append(), Application, C4Config::AtUserDataPath(), C4CVT_DisableDebug, C4CVT_MaxPlayer, C4Group_CopyItem(), CDT_Decide, CDT_Sync, CID_ClientUpdate, CID_MsgBoardCmd, CID_Script, CID_Set, C4ConsoleGUI::ClearLog(), C4GameLobby::MainDlg::ClearLog(), C4Game::Clients, C4Network2::Clients, CStdFile::Close(), CNM_Async, CNM_Central, CNM_Decentral, C4ConfigNetwork::Comment, Config, Console, Control, StdStrBuf::Copy(), ValidatedStdCopyStrBufBase::CopyValidated(), C4ConfigLobby::CountdownTime, C4ClientList::CtrlRemove(), CUT_Activate, CUT_SetObserver, C4Game::DebugMode, C4Config::Developer, C4GameControl::DoInput(), StdStrBuf::Format(), FormatString(), C4Game::FrameSkip, C4Game::FullSpeed, Game, C4Config::General, C4PlayerList::GetAtClient(), C4ClientList::getClientByName(), C4ClientPlayerInfos::GetClientID(), C4PlayerInfoList::GetClientInfoByPlayerID(), GetCommand(), StdStrBuf::getData(), C4Network2Res::getFile(), GetFilename(), C4Group::GetFullName(), C4Network2Client::getID(), C4Network2ResCore::getID(), C4Client::getID(), C4PlayerInfo::GetID(), C4Network2::GetLobby(), C4Network2ClientList::GetLocal(), C4PlayerList::GetLocalByIndex(), C4PlayerInfo::GetName(), C4PlayerInfoList::GetNextPlayerInfoByID(), C4ClientPlayerInfos::GetPlayerInfoByID(), C4PlayerInfoList::GetPrimaryInfoByClientID(), C4Network2ResList::getRefRes(), C4GameRes::getResCore(), GraphicsSystem, C4Network2::InvalidateReference(), C4GameControl::isCtrlHost(), C4Network2::isEnabled(), C4Network2::isHost(), C4GameParameters::isLeague(), C4Network2::isLobbyCountDown(), C4GameControl::isNetwork(), C4Group::IsOpen(), C4Group::IsPacked(), C4Game::IsRunning, ItemExists(), C4Network2Players::JoinLocalPlayer(), LoadResStr(), C4Config::Lobby, C4GameLobby::LobbyError(), Log(), LogF(), C4GraphicsSystem::MessageBoard, Network, C4Config::Network, C4Application::NextTick(), NO_OWNER, C4Player::Number, C4GameLobby::MainDlg::OnError(), C4Game::Parameters, player, C4Game::PlayerInfos, C4Network2::Players, Players, StdStrBuf::Replace(), C4Network2Players::RequestPlayerInfoUpdate(), C4Network2::ResList, C4GraphicsSystem::SaveScreenshot(), C4GameParameters::Scenario, C4Game::ScenarioFile, C4Game::ScenarioFilename, SCharPos(), C4ControlScript::SCOPE_Console, SCopyUntil(), SEqual(), SEqual2(), SEqualNoCase(), C4Network2::SetCtrlMode(), C4PlayerInfo::SetOriginalColor(), C4Network2::SetPassword(), SSearch(), C4GameLobby::MainDlg::Start(), C4Network2::Start(), C4Network2::StartLobbyCountdown(), C4ConfigDeveloper::TodoFilename, C4Game::ToggleChart(), C4GameLobby::MainDlg::UpdatePassword(), C4ConfigGeneral::UserDataPath, C4Network2::Vote(), VT_Kick, WildcardMatch(), and CStdFile::WriteString().

Referenced by C4Console::In(), and ProcessInput().

429 {
431  // command
432  // must be 1 char longer than the longest command only. If given commands are longer, they will be truncated, and such a command won't exist anyway
433  const int32_t MaxCommandLen = 20;
434  char szCmdName[MaxCommandLen + 1];
435  SCopyUntil(szCommand + 1, szCmdName, ' ', MaxCommandLen);
436  // parameter
437  const char *pCmdPar = SSearch(szCommand, " ");
438  if (!pCmdPar) pCmdPar = "";
439 
440  // CAUTION when implementing special commands (like /quit) here:
441  // those must not be executed when text is pasted, because that could crash the GUI system
442  // when there are additional lines to paste, but the edit field is destructed by the command
443 
444  // lobby-only commands
445  if (!Game.IsRunning && SEqualNoCase(szCmdName, "joinplr"))
446  {
447  // compose path from given filename
448  StdStrBuf plrPath;
449  plrPath.Format("%s%s", Config.General.UserDataPath, pCmdPar);
450  // player join - check filename
451  if (!ItemExists(plrPath.getData()))
452  {
453  C4GameLobby::LobbyError(FormatString(LoadResStr("IDS_MSG_CMD_JOINPLR_NOFILE"), plrPath.getData()).getData());
454  }
455  else
457  return true;
458  }
459  if (!Game.IsRunning && SEqualNoCase(szCmdName, "plrclr"))
460  {
461  // get player name from input text
462  int iSepPos = SCharPos(' ', pCmdPar, 0);
463  C4PlayerInfo *pNfo=nullptr;
464  int32_t idLocalClient = -1;
465  if (::Network.Clients.GetLocal()) idLocalClient = ::Network.Clients.GetLocal()->getID();
466  if (iSepPos>0)
467  {
468  // a player name is given: Parse it
469  StdStrBuf sPlrName;
470  sPlrName.Copy(pCmdPar, iSepPos);
471  pCmdPar += iSepPos+1; int32_t id=0;
472  while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(id)))
473  {
474  id = pNfo->GetID();
475  if (WildcardMatch(sPlrName.getData(), pNfo->GetName())) break;
476  }
477  }
478  else
479  // no player name: Set local player
480  pNfo = Game.PlayerInfos.GetPrimaryInfoByClientID(idLocalClient);
481  C4ClientPlayerInfos *pCltNfo=nullptr;
482  if (pNfo) pCltNfo = Game.PlayerInfos.GetClientInfoByPlayerID(pNfo->GetID());
483  if (!pCltNfo)
484  {
485  C4GameLobby::LobbyError(LoadResStr("IDS_MSG_CMD_PLRCLR_NOPLAYER"));
486  }
487  else
488  {
489  // may color of this client be set?
490  if (pCltNfo->GetClientID() != idLocalClient && !::Network.isHost())
491  {
492  C4GameLobby::LobbyError(LoadResStr("IDS_MSG_CMD_PLRCLR_NOACCESS"));
493  }
494  else
495  {
496  // get color to set
497  uint32_t dwNewClr;
498  if (sscanf(pCmdPar, "%x", &dwNewClr) != 1)
499  {
500  C4GameLobby::LobbyError(LoadResStr("IDS_MSG_CMD_PLRCLR_USAGE"));
501  }
502  else
503  {
504  // color validation
505  dwNewClr |= 0xff000000;
506  if (!dwNewClr) ++dwNewClr;
507  // request a color change to this color
508  C4ClientPlayerInfos LocalInfoRequest = *pCltNfo;
509  C4PlayerInfo *pPlrInfo = LocalInfoRequest.GetPlayerInfoByID(pNfo->GetID());
510  assert(pPlrInfo);
511  if (pPlrInfo)
512  {
513  pPlrInfo->SetOriginalColor(dwNewClr); // set this as a new color wish
514  ::Network.Players.RequestPlayerInfoUpdate(LocalInfoRequest);
515  }
516  }
517  }
518  }
519  return true;
520  }
521  if (!Game.IsRunning && SEqualNoCase(szCmdName, "start"))
522  {
523  // timeout given?
524  int32_t iTimeout = Config.Lobby.CountdownTime;
525  if (!::Network.isHost())
526  C4GameLobby::LobbyError(LoadResStr("IDS_MSG_CMD_HOSTONLY"));
527  else if (pCmdPar && *pCmdPar && (!sscanf(pCmdPar, "%d", &iTimeout) || iTimeout<0))
528  C4GameLobby::LobbyError(LoadResStr("IDS_MSG_CMD_START_USAGE"));
529  else if (pLobby)
530  {
531  // abort previous countdown
533  // start new countdown (aborts previous if necessary)
534  pLobby->Start(iTimeout);
535  }
536  else
537  {
538  if (iTimeout)
539  ::Network.StartLobbyCountdown(iTimeout);
540  else
541  ::Network.Start();
542  }
543  return true;
544  }
545  if (!Game.IsRunning && SEqualNoCase(szCmdName, "abort"))
546  {
547  if (!::Network.isHost())
548  C4GameLobby::LobbyError(LoadResStr("IDS_MSG_CMD_HOSTONLY"));
549  else if (::Network.isLobbyCountDown())
551  else
552  C4GameLobby::LobbyError(LoadResStr("IDS_MSG_CMD_ABORT_NOCOUNTDOWN"));
553  return true;
554  }
555 
556  if (SEqual(szCmdName, "help"))
557  {
558  Log(LoadResStr(pLobby ? "IDS_TEXT_COMMANDSAVAILABLEDURINGLO" : "IDS_TEXT_COMMANDSAVAILABLEDURINGGA"));
559  if (!Game.IsRunning)
560  {
561  LogF("/start [time] - %s", LoadResStr("IDS_TEXT_STARTTHEROUNDWITHSPECIFIE"));
562  LogF("/abort - %s", LoadResStr("IDS_TEXT_ABORTSTARTCOUNTDOWN"));
563  LogF("/alert - %s", LoadResStr("IDS_TEXT_ALERTTHEHOSTIFTHEHOSTISAW"));
564  LogF("/joinplr [filename] - %s", LoadResStr("IDS_TEXT_JOINALOCALPLAYERFROMTHESP"));
565  LogF("/plrclr [player] [RGB] - %s", LoadResStr("IDS_TEXT_CHANGETHECOLOROFTHESPECIF"));
566  LogF("/plrclr [RGB] - %s", LoadResStr("IDS_TEXT_CHANGEYOUROWNPLAYERCOLOR"));
567  }
568  else
569  {
570  LogF("/fast [x] - %s", LoadResStr("IDS_TEXT_SETTOFASTMODESKIPPINGXFRA"));
571  LogF("/slow - %s", LoadResStr("IDS_TEXT_SETTONORMALSPEEDMODE"));
572  LogF("/chart - %s", LoadResStr("IDS_TEXT_DISPLAYNETWORKSTATISTICS"));
573  LogF("/nodebug - %s", LoadResStr("IDS_TEXT_PREVENTDEBUGMODEINTHISROU"));
574  LogF("/script [script] - %s", LoadResStr("IDS_TEXT_EXECUTEASCRIPTCOMMAND"));
575  LogF("/screenshot [zoom] - %s", LoadResStr("IDS_TEXT_SAFEZOOMEDFULLSCREENSHOT"));
576  }
577  LogF("/kick [client] - %s", LoadResStr("IDS_TEXT_KICKTHESPECIFIEDCLIENT"));
578  LogF("/observer [client] - %s", LoadResStr("IDS_TEXT_SETTHESPECIFIEDCLIENTTOOB"));
579  LogF("/me [action] - %s", LoadResStr("IDS_TEXT_PERFORMANACTIONINYOURNAME"));
580  LogF("/sound [sound] - %s", LoadResStr("IDS_TEXT_PLAYASOUNDFROMTHEGLOBALSO"));
581  if (Game.IsRunning) LogF("/private [player] [message] - %s", LoadResStr("IDS_MSG_SENDAPRIVATEMESSAGETOTHES"));
582  LogF("/team [message] - %s", LoadResStr("IDS_MSG_SENDAPRIVATEMESSAGETOYOUR"));
583  LogF("/set comment [comment] - %s", LoadResStr("IDS_TEXT_SETANEWNETWORKCOMMENT"));
584  LogF("/set password [password] - %s", LoadResStr("IDS_TEXT_SETANEWNETWORKPASSWORD"));
585  LogF("/set maxplayer [number] - %s", LoadResStr("IDS_TEXT_SETANEWMAXIMUMNUMBEROFPLA"));
586  LogF("/todo [text] - %s", LoadResStr("IDS_TEXT_ADDTODO"));
587  LogF("/clear - %s", LoadResStr("IDS_MSG_CLEARTHEMESSAGEBOARD"));
588  return true;
589  }
590  // dev-scripts
591  if (SEqual(szCmdName, "script"))
592  {
593  if (!Game.IsRunning) return false;
594  if (!Game.DebugMode) return false;
595 
597  return true;
598  }
599  // set runtime properties
600  if (SEqual(szCmdName, "set"))
601  {
602  if (SEqual2(pCmdPar, "maxplayer "))
603  {
604  if (::Control.isCtrlHost())
605  {
606  if (atoi(pCmdPar+10) == 0 && !SEqual(pCmdPar+10, "0"))
607  {
608  Log("Syntax: /set maxplayer count");
609  return false;
610  }
612  new C4ControlSet(C4CVT_MaxPlayer, atoi(pCmdPar+10)),
613  CDT_Decide);
614  return true;
615  }
616  }
617  if (SEqual2(pCmdPar, "comment ") || SEqual(pCmdPar, "comment"))
618  {
619  if (!::Network.isEnabled() || !::Network.isHost()) return false;
620  // Set in configuration, update reference
621  Config.Network.Comment.CopyValidated(pCmdPar[7] ? (pCmdPar+8) : "");
623  Log(LoadResStr("IDS_NET_COMMENTCHANGED"));
624  return true;
625  }
626  if (SEqual2(pCmdPar, "password ") || SEqual(pCmdPar, "password"))
627  {
628  if (!::Network.isEnabled() || !::Network.isHost()) return false;
629  ::Network.SetPassword(pCmdPar[8] ? (pCmdPar+9) : nullptr);
630  if (pLobby) pLobby->UpdatePassword();
631  return true;
632  }
633  // unknown property
634  return false;
635  }
636  // get szen from network folder - not in lobby; use res tab there
637  if (SEqual(szCmdName, "netgetscen"))
638  {
639  if (::Network.isEnabled() && !::Network.isHost() && !pLobby)
640  {
641  const C4Network2ResCore *pResCoreScen = Game.Parameters.Scenario.getResCore();
642  if (pResCoreScen)
643  {
644  C4Network2Res::Ref pScenario = ::Network.ResList.getRefRes(pResCoreScen->getID());
645  if (pScenario)
647  {
648  LogF(LoadResStr("IDS_MSG_CMD_NETGETSCEN_SAVED"), Config.AtUserDataPath(GetFilename(Game.ScenarioFilename)));
649  return true;
650  }
651  }
652  }
653  return false;
654  }
655  // clear message board
656  if (SEqual(szCmdName, "clear"))
657  {
658  // lobby
659  if (pLobby)
660  {
661  pLobby->ClearLog();
662  }
663  // fullscreen
664  else if (::GraphicsSystem.MessageBoard)
665  ::GraphicsSystem.MessageBoard->ClearLog();
666  else
667  {
668  // EM mode
669  Console.ClearLog();
670  }
671  return true;
672  }
673  // kick client
674  if (SEqual(szCmdName, "kick"))
675  {
676  if (::Network.isEnabled() && ::Network.isHost())
677  {
678  // find client
679  C4Client *pClient = Game.Clients.getClientByName(pCmdPar);
680  if (!pClient)
681  {
682  LogF(LoadResStr("IDS_MSG_CMD_NOCLIENT"), pCmdPar);
683  return false;
684  }
685  // league: Kick needs voting
686  if (Game.Parameters.isLeague() && ::Players.GetAtClient(pClient->getID()))
687  ::Network.Vote(VT_Kick, true, pClient->getID());
688  else
689  // add control
690  Game.Clients.CtrlRemove(pClient, LoadResStr("IDS_MSG_KICKFROMMSGBOARD"));
691  }
692  return true;
693  }
694  // set fast mode
695  if (SEqual(szCmdName, "fast"))
696  {
697  if (!Game.IsRunning) return false;
698  int32_t iFS;
699  if ((iFS=atoi(pCmdPar)) == 0) return false;
700  // set frameskip and fullspeed flag
701  Game.FrameSkip=Clamp<int32_t>(iFS,1,500);
702  Game.FullSpeed=true;
703  // start calculation immediatly
705  return true;
706  }
707  // reset fast mode
708  if (SEqual(szCmdName, "slow"))
709  {
710  if (!Game.IsRunning) return false;
711  Game.FullSpeed=false;
712  Game.FrameSkip=1;
713  return true;
714  }
715 
716  if (SEqual(szCmdName, "nodebug"))
717  {
718  if (!Game.IsRunning) return false;
720  return true;
721  }
722 
723  // kick/activate/deactivate/observer
724  if (SEqual(szCmdName, "activate") || SEqual(szCmdName, "deactivate") || SEqual(szCmdName, "observer"))
725  {
726  if (!::Network.isEnabled() || !::Network.isHost())
727  { Log(LoadResStr("IDS_MSG_CMD_HOSTONLY")); return false; }
728  // search for client
729  C4Client *pClient = Game.Clients.getClientByName(pCmdPar);
730  if (!pClient)
731  {
732  LogF(LoadResStr("IDS_MSG_CMD_NOCLIENT"), pCmdPar);
733  return false;
734  }
735  // what to do?
736  C4ControlClientUpdate *pCtrl = nullptr;
737  if (szCmdName[0] == 'a') // activate
738  pCtrl = new C4ControlClientUpdate(pClient->getID(), CUT_Activate, true);
739  else if (szCmdName[0] == 'd' && !Game.Parameters.isLeague()) // deactivate
740  pCtrl = new C4ControlClientUpdate(pClient->getID(), CUT_Activate, false);
741  else if (szCmdName[0] == 'o' && !Game.Parameters.isLeague()) // observer
742  pCtrl = new C4ControlClientUpdate(pClient->getID(), CUT_SetObserver);
743  // perform it
744  if (pCtrl)
746  else
747  Log(LoadResStr("IDS_LOG_COMMANDNOTALLOWEDINLEAGUE"));
748  return true;
749  }
750 
751  // control mode
752  if (SEqual(szCmdName, "centralctrl") || SEqual(szCmdName, "decentralctrl") || SEqual(szCmdName, "asyncctrl"))
753  {
754  if (!::Network.isEnabled() || !::Network.isHost())
755  { Log(LoadResStr("IDS_MSG_CMD_HOSTONLY")); return false; }
756  ::Network.SetCtrlMode(*szCmdName == 'c' ? CNM_Central : *szCmdName == 'd' ? CNM_Decentral : CNM_Async);
757  return true;
758  }
759 
760  // show chart
761  if (Game.IsRunning)
762  if (SEqual(szCmdName, "chart"))
763  return Game.ToggleChart();
764 
765  // whole map screenshot
766  if (SEqual(szCmdName, "screenshot"))
767  {
768  double zoom = atof(pCmdPar);
769  if (zoom<=0) return false;
770  ::GraphicsSystem.SaveScreenshot(true, zoom);
771  return true;
772  }
773 
774  // add to TODO list
775  if (SEqual(szCmdName, "todo"))
776  {
777  // must add something
778  if (!pCmdPar || !*pCmdPar) return false;
779  // try writing main file (usually {SCENARIO}/TODO.txt); if access is not possible, e.g. because scenario is packed, write to alternate file
780  const char *todo_filenames[] = { ::Config.Developer.TodoFilename, ::Config.Developer.AltTodoFilename };
781  bool success = false;
782  for (int i = 0; i < static_cast<int>(std::extent<decltype(todo_filenames)>::value); ++i)
783  {
784  StdCopyStrBuf todo_filename(todo_filenames[i]);
785  todo_filename.Replace("{USERPATH}", Config.General.UserDataPath);
786  int replacements = todo_filename.Replace("{SCENARIO}", Game.ScenarioFile.GetFullName().getData());
787  // sanity checks for writing scenario TODO file
788  if (replacements)
789  {
790  // entered in editor with no file open?
791  if (!::Game.ScenarioFile.IsOpen()) continue;
792  // not into packed
793  if (::Game.ScenarioFile.IsPacked()) continue;
794  // not into temp network file
795  if (::Control.isNetwork() && !::Control.isCtrlHost()) continue;
796  }
797  // try to append. May fail e.g. on packed scenario file, name getting too long, etc. Then fallback to alternate location.
798  CStdFile todo_file;
799  if (!todo_file.Append(todo_filename.getData())) continue;
800  if (!todo_file.WriteString(pCmdPar)) continue;
801  // check on file close because CStdFile may do a delayed write
802  if (!todo_file.Close()) continue;
803  success = true;
804  break;
805  }
806  // no message on success to avoid cluttering the chat during debug sessions
807  if (!success) Log(LoadResStr("IDS_ERR_TODO"));
808  return true;
809  }
810 
811  // custom command
812  C4MessageBoardCommand *pCmd;
813  if (Game.IsRunning)
814  if ((pCmd = GetCommand(szCmdName)))
815  {
816  // get player number of first local player; if multiple players
817  // share one computer, we can't distinguish between them anyway
818  int32_t player_num = NO_OWNER;
820  if (player) player_num = player->Number;
821 
822  // send command to network
823  ::Control.DoInput(CID_MsgBoardCmd, new C4ControlMsgBoardCmd(szCmdName, pCmdPar, player_num), CDT_Decide);
824 
825  // ok
826  return true;
827  }
828 
829  // unknown command
830  StdStrBuf sErr; sErr.Format(LoadResStr("IDS_ERR_UNKNOWNCMD"), szCmdName);
831  if (pLobby) pLobby->OnError(sErr.getData()); else Log(sErr.getData());
832  return false;
833 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
C4Client * getClientByName(const char *szName) const
Definition: C4Client.cpp:233
bool Close(StdBuf **ppMemory=nullptr)
Definition: CStdFile.cpp:155
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
bool IsRunning
Definition: C4Game.h:141
void SetPassword(const char *szToPassword)
Definition: C4Network2.cpp:794
bool Start()
Definition: C4Network2.cpp:528
char ScenarioFilename[_MAX_PATH+1]
Definition: C4Game.h:104
C4Config Config
Definition: C4Config.cpp:837
const char * GetName() const
Definition: C4PlayerInfo.h:160
void SetCtrlMode(int32_t iCtrlMode)
Definition: C4Network2.cpp:841
C4Console Console
Definition: C4Globals.cpp:45
bool isHost() const
Definition: C4Network2.h:209
void AbortLobbyCountdown()
void RequestPlayerInfoUpdate(const class C4ClientPlayerInfos &rRequest)
bool isCtrlHost() const
Definition: C4GameControl.h:99
C4Game Game
Definition: C4Globals.cpp:52
int32_t Number
Definition: C4Player.h:88
C4ConfigGeneral General
Definition: C4Config.h:252
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:333
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:177
ValidatedStdCopyStrBuf< C4InVal::VAL_Comment > Comment
Definition: C4Config.h:147
void Vote(C4ControlVoteType eType, bool fApprove=true, int32_t iData=0)
C4PlayerInfo * GetPrimaryInfoByClientID(int32_t iClientID) const
Definition: C4PlayerInfo.h:379
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
C4PlayerInfo * GetNextPlayerInfoByID(int32_t id) const
int32_t getID() const
void CtrlRemove(const C4Client *pClient, const char *szReason)
Definition: C4Client.cpp:350
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
C4GameParameters & Parameters
Definition: C4Game.h:69
C4Player * GetAtClient(int iClient, int iIndex=0) const
C4ClientPlayerInfos * GetClientInfoByPlayerID(int32_t id) const
void StartLobbyCountdown(int32_t iCountdownTime)
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void LobbyError(const char *szErrorMsg)
const C4Network2ResCore * getResCore() const
int32_t getID() const
Definition: C4Client.h:105
const char * getFile() const
bool SaveScreenshot(bool fSaveAll, float fSaveAllZoom)
int32_t getID() const
Definition: C4Network2Res.h:86
bool isNetwork() const
Definition: C4GameControl.h:97
C4Network2 Network
Definition: C4Globals.cpp:53
bool IsOpen() const
Definition: C4Group.cpp:1891
char TodoFilename[CFG_MaxString+1]
Definition: C4Config.h:85
int32_t FrameSkip
Definition: C4Game.h:139
char UserDataPath[CFG_MaxString+1]
Definition: C4Config.h:55
bool isLobbyCountDown()
Definition: C4Network2.h:297
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
void InvalidateReference()
C4GameControl Control
C4ConfigLobby Lobby
Definition: C4Config.h:257
bool Append(const char *szFilename, bool text=false)
Definition: CStdFile.cpp:136
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
int32_t GetClientID() const
Definition: C4PlayerInfo.h:260
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
C4Group ScenarioFile
Definition: C4Game.h:88
C4PlayerList Players
bool C4Group_CopyItem(const char *szSource, const char *szTarget1, bool fNoSort, bool fResetAttributes)
Definition: C4Group.cpp:100
C4ConfigNetwork Network
Definition: C4Config.h:256
C4ConfigDeveloper Developer
Definition: C4Config.h:253
C4Player * GetLocalByIndex(int iIndex) const
const int NO_OWNER
Definition: C4Constants.h:138
void OnError(const char *szErrMsg)
void Start(int32_t iCountdownTime)
C4Network2Res::Ref getRefRes(int32_t iResID)
int32_t CountdownTime
Definition: C4Config.h:198
bool isEnabled() const
Definition: C4Network2.h:203
C4Network2ResList ResList
Definition: C4Network2.h:113
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:73
bool FullSpeed
Definition: C4Game.h:138
void SetOriginalColor(DWORD dwUseClr)
Definition: C4PlayerInfo.h:119
std::unique_ptr< C4MessageBoard > MessageBoard
const char * AtUserDataPath(const char *szFilename)
Definition: C4Config.cpp:530
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:384
C4Network2Players Players
Definition: C4Network2.h:119
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
bool SEqual2(const char *szStr1, const char *szStr2)
Definition: Standard.cpp:168
C4ClientList & Clients
Definition: C4Game.h:71
bool isLeague() const
bool ToggleChart()
Definition: C4Game.cpp:3664
bool ClearLog()
Definition: C4Console.cpp:672
char AltTodoFilename[CFG_MaxString+1]
Definition: C4Config.h:86
bool IsPacked() const
Definition: C4Group.cpp:2009
int32_t GetID() const
Definition: C4PlayerInfo.h:197
C4PlayerInfo * GetPlayerInfoByID(int32_t id) const
C4Network2Client * GetLocal() const
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:203
bool JoinLocalPlayer(const char *szLocalPlayerFilename, bool initial=false)
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
bool WriteString(const char *szStr)
Definition: CStdFile.cpp:268
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
void Copy()
Definition: StdBuf.h:475
void CopyValidated(const char *szFromVal)
C4Application Application
Definition: C4Globals.cpp:44
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
Definition: Standard.cpp:138
bool DebugMode
Definition: C4Game.h:146
class C4MessageBoardCommand * GetCommand(const char *strName)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MessageInput::ProcessInput ( const char *  szText)

Definition at line 313 of file C4MessageInput.cpp.

References C4CMT_Alert, C4CMT_Me, C4CMT_Normal, C4CMT_Private, C4CMT_Say, C4CMT_Sound, C4CMT_Team, C4MaxMessage, C4MaxName, C4Game::C4S, C4SFilm_Cinematic, CDT_Private, CID_Message, Control, C4GameControl::DoInput(), C4SHead::Film, Game, C4PlayerList::GetByName(), C4PlayerList::GetLocalByIndex(), C4Scenario::Head, C4Game::IsRunning, C4TeamList::IsTeamVisible(), IsWhiteSpace(), LoadResStr(), Log(), C4Player::Number, Players, ProcessCommand(), SCopy(), SCopyUntil(), SEqual2NoCase(), SEqualNoCase(), SLen(), C4Game::Teams, and text.

Referenced by C4Console::In(), C4ChatInputDialog::OnChatInput(), C4GameLobby::MainDlg::OnChatInput(), and C4Application::OnCommand().

314 {
315  // helper variables
316  char OSTR[402]; // cba
317  C4ControlMessageType eMsgType;
318  const char *szMsg = nullptr;
319  int32_t iToPlayer = -1;
320 
321  // Starts with '^', "team:" or "/team ": Team message
322  if (szText[0] == '^' || SEqual2NoCase(szText, "team:") || SEqual2NoCase(szText, "/team "))
323  {
324  if (!Game.Teams.IsTeamVisible())
325  {
326  // team not known; can't send!
327  Log(LoadResStr("IDS_MSG_CANTSENDTEAMMESSAGETEAMSN"));
328  return false;
329  }
330  else
331  {
332  eMsgType = C4CMT_Team;
333  szMsg = szText[0] == '^' ? szText+1 :
334  szText[0] == '/' ? szText+6 : szText+5;
335  }
336  }
337  // Starts with "/private ": Private message (running game only)
338  else if (Game.IsRunning && SEqual2NoCase(szText, "/private "))
339  {
340  // get target name
341  char szTargetPlr[C4MaxName + 1];
342  SCopyUntil(szText + 9, szTargetPlr, ' ', C4MaxName);
343  // search player
344  C4Player *pToPlr = ::Players.GetByName(szTargetPlr);
345  if (!pToPlr) return false;
346  // set
347  eMsgType = C4CMT_Private;
348  iToPlayer = pToPlr->Number;
349  szMsg = szText + 10 + SLen(szText);
350  if (szMsg > szText + SLen(szText)) return false;
351  }
352  // Starts with "/me ": Me-Message
353  else if (SEqual2NoCase(szText, "/me "))
354  {
355  eMsgType = C4CMT_Me;
356  szMsg = szText+4;
357  }
358  // Starts with "/sound ": Sound-Message
359  else if (SEqual2NoCase(szText, "/sound "))
360  {
361  eMsgType = C4CMT_Sound;
362  szMsg = szText+7;
363  }
364  // Disabled due to spamming
365  // Starts with "/alert": Taskbar flash (message optional)
366  else if (SEqual2NoCase(szText, "/alert ") || SEqualNoCase(szText, "/alert"))
367  {
368  eMsgType = C4CMT_Alert;
369  szMsg = szText+6;
370  if (*szMsg) ++szMsg;
371  }
372  // Starts with '"': Let the clonk say it
373  else if (Game.IsRunning && szText[0] == '"')
374  {
375  eMsgType = C4CMT_Say;
376  // Append '"', if neccessary
377  StdStrBuf text(szText);
378  SCopy(szText, OSTR, 400);
379  char *pEnd = OSTR + SLen(OSTR) - 1;
380  if (*pEnd != '"') { *++pEnd = '"'; *++pEnd = 0; }
381  szMsg = OSTR;
382  }
383  // Starts with '/': Command
384  else if (szText[0] == '/')
385  return ProcessCommand(szText);
386  // Regular message
387  else
388  {
389  eMsgType = C4CMT_Normal;
390  szMsg = szText;
391  }
392 
393  // message?
394  if (szMsg)
395  {
396  char szMessage[C4MaxMessage + 1];
397  // go over whitespaces, check empty message
398  while (IsWhiteSpace(*szMsg)) szMsg++;
399  if (!*szMsg)
400  {
401  if (eMsgType != C4CMT_Alert) return true;
402  *szMessage = '\0';
403  }
404  else
405  {
406  // trim right
407  const char *szEnd = szMsg + SLen(szMsg) - 1;
408  while (IsWhiteSpace(*szEnd) && szEnd >= szMsg) szEnd--;
409  // Say: Strip quotation marks in cinematic film mode
411  {
412  if (eMsgType == C4CMT_Say) { ++szMsg; szEnd--; }
413  }
414  // get message
415  SCopy(szMsg, szMessage, std::min<ptrdiff_t>(C4MaxMessage, szEnd - szMsg + 1));
416  }
417  // get sending player (if any)
418  C4Player *pPlr = Game.IsRunning ? ::Players.GetLocalByIndex(0) : nullptr;
419  // send
421  new C4ControlMessage(eMsgType, szMessage, pPlr ? pPlr->Number : -1, iToPlayer),
422  CDT_Private);
423  }
424 
425  return true;
426 }
bool IsRunning
Definition: C4Game.h:141
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
C4Game Game
Definition: C4Globals.cpp:52
int32_t Number
Definition: C4Player.h:88
C4Scenario C4S
Definition: C4Game.h:76
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:177
bool IsWhiteSpace(char cChar)
Definition: Standard.h:76
bool IsTeamVisible() const
Definition: C4Teams.cpp:455
size_t SLen(const char *sptr)
Definition: Standard.h:78
C4TeamList & Teams
Definition: C4Game.h:72
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
C4PlayerList Players
bool ProcessCommand(const char *szCommand)
C4Player * GetLocalByIndex(int iIndex) const
const unsigned int C4MaxName
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
bool SEqual2NoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:190
C4SHead Head
Definition: C4Scenario.h:230
const int C4MaxMessage
Definition: C4Constants.h:28
C4Player * GetByName(const char *szName, int iExcluding=NO_OWNER) const
C4ControlMessageType
Definition: C4Control.h:512
void SCopyUntil(const char *szSource, char *sTarget, char cUntil, int iMaxL, int iIndex)
Definition: Standard.cpp:138
int32_t Film
Definition: C4Scenario.h:73

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MessageInput::StartTypeIn ( bool  fObjInput = false,
C4Object pObj = nullptr,
bool  fUpperCase = false,
bool  fTeam = false,
int32_t  iPlr = -1,
const StdStrBuf rsInputQuery = StdStrBuf() 
)

Definition at line 277 of file C4MessageInput.cpp.

References C4ChatInputDialog, CloseTypeIn(), IsTypeIn(), pGUI, and C4GUI::Screen::ShowRemoveDlg().

Referenced by KeyStartTypeIn(), and ToggleTypeIn().

278 {
279  // close any previous
280  if (IsTypeIn()) CloseTypeIn();
281  // start new
282  return ::pGUI->ShowRemoveDlg(new C4ChatInputDialog(fObjInput, pObj, fUpperCase, fTeam, iPlr, rsInputQuery));
283 }
friend class C4ChatInputDialog
bool ShowRemoveDlg(Dialog *pDlg)
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MessageInput::StoreBackBuffer ( const char *  szMessage)

Definition at line 868 of file C4MessageInput.cpp.

References C4MaxMessage, C4MSGB_BackBufferMax, SCopy(), and SEqual().

Referenced by C4ChatInputDialog::OnChatInput(), and C4GameLobby::MainDlg::OnChatInput().

869 {
870  if (!szMessage || !szMessage[0]) return;
871  int32_t i,cnt;
872  // Check: Remove doubled buffer
873  for (i=0; i<C4MSGB_BackBufferMax-1; ++i)
874  if (SEqual(BackBuffer[i], szMessage))
875  break;
876  // Move up buffers
877  for (cnt=i; cnt>0; cnt--) SCopy(BackBuffer[cnt-1],BackBuffer[cnt]);
878  // Add message
879  SCopy(szMessage,BackBuffer[0], C4MaxMessage);
880 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
const int32_t C4MSGB_BackBufferMax
const int C4MaxMessage
Definition: C4Constants.h:28

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MessageInput::ToggleTypeIn ( )

Definition at line 293 of file C4MessageInput.cpp.

References CloseTypeIn(), GetTypeIn(), IsTypeIn(), and StartTypeIn().

294 {
295  // toggle off?
296  if (IsTypeIn())
297  {
298  // no accidental close of script queried dlgs by chat request
299  if (GetTypeIn()->IsScriptQueried()) return false;
300  return CloseTypeIn();
301  }
302  else
303  // toggle on!
304  return StartTypeIn();
305 }
C4ChatInputDialog * GetTypeIn()
bool StartTypeIn(bool fObjInput=false, C4Object *pObj=nullptr, bool fUpperCase=false, bool fTeam=false, int32_t iPlr=-1, const StdStrBuf &rsInputQuery=StdStrBuf())

Here is the call graph for this function:

Friends And Related Function Documentation

friend class C4ChatInputDialog
friend

Definition at line 143 of file C4MessageInput.h.

Referenced by StartTypeIn().


The documentation for this class was generated from the following files: