Skip to content

Commit

Permalink
Merge pull request #54 from AssassinTee/fix/chat-commands
Browse files Browse the repository at this point in the history
✨ Fix chat commands
  • Loading branch information
AssassinTee authored May 14, 2021
2 parents 6e130f6 + 819e888 commit 9b1610c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
15 changes: 14 additions & 1 deletion src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,19 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) {
pPlayer->m_LastChat + Server()->TickSpeed() * (Length / 20) > Server()->Tick()))
return;

if (pMsg->m_pMessage[0] == '/') {
const char *command = pMsg->m_pMessage+1;
if (CommandManager()->GetCommand(command)) {
CommandManager()->OnCommand(command, "", ClientID);
}
else {
char aNoCommand[128];
str_format(aNoCommand, sizeof(aNoCommand), "Unknown command '%s'", command);
SendServerInfo(aNoCommand, ClientID);
}
return;
}

pPlayer->m_LastChat = Server()->Tick();

// don't allow spectators to disturb players during a running game in tournament mode
Expand Down Expand Up @@ -1713,7 +1726,7 @@ void CGameContext::OnInit() {
m_pController = new CGameControllerCatch64(this);

// IDK how this works now
//m_pController->RegisterChatCommands(CommandManager());
m_pController->RegisterChatCommands(CommandManager());

// create all entities from the game layer
CMapItemLayerTilemap *pTileMap = m_Layers.GameLayer();
Expand Down
21 changes: 17 additions & 4 deletions src/game/server/gamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,13 @@ void IGameController::RegisterChatCommands(CCommandManager *pManager)
AddCommand("info", "", "show authors and mod description", ComInfo);
}*/

void IGameController::RegisterChatCommands(CCommandManager *pManager)
{
//pManager->AddCommand("test", "Test the command system", "r", Com_Example, this);
pManager->AddCommand("help", "How does this mod work", "", ComHelp, this);
pManager->AddCommand("info", "About page", "", ComInfo, this);
}

void IGameController::ComSendMessageList(std::vector<std::string>& messageList, const int ClientID)
{
CNetMsg_Sv_Chat Msg;
Expand All @@ -1374,17 +1381,23 @@ void IGameController::ComSendMessageList(std::vector<std::string>& messageList,
}
}

void IGameController::ComHelp(class IGameController* pGameController, class CPlayer *pPlayer, const char *pArgs)
void IGameController::ComHelp(IConsole::IResult *pResult, void *pContext)
{
auto *pComContext = (CCommandManager::SCommandContext *)pContext;
auto *pSelf = (IGameController *)pComContext->m_pContext;

std::vector<std::string> helplist = {"###Help###",
"You start in your team",
"If you hit a player, he is in your team, too",
"Very easy :D"};
pGameController->ComSendMessageList(helplist, pPlayer->GetCID());
pSelf->ComSendMessageList(helplist, pComContext->m_ClientID);
}

void IGameController::ComInfo(class IGameController* pGameController, class CPlayer *pPlayer, const char *pArgs)
void IGameController::ComInfo(IConsole::IResult *pResult, void *pContext)
{
auto *pComContext = (CCommandManager::SCommandContext *)pContext;
auto *pSelf = (IGameController *)pComContext->m_pContext;

std::vector<std::string> infolist = {"###Info###",
"Catch64 by AssassinTee",
"You like it? Give me a Star on GitHub!",
Expand All @@ -1393,5 +1406,5 @@ void IGameController::ComInfo(class IGameController* pGameController, class CPla
std::stringstream ss;
ss << "Teeworlds version: '" << GAME_RELEASE_VERSION << "', Catch64 Version: '" << CATCH_VERSION << "'";
infolist.push_back(ss.str());
pGameController->ComSendMessageList(infolist, pPlayer->GetCID());
pSelf->ComSendMessageList(infolist, pComContext->m_ClientID);
}
10 changes: 6 additions & 4 deletions src/game/server/gamecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ class IGameController
int m_TopscoreCount;

void ComSendMessageList(std::vector<std::string>& messageList, const int ClientID);
void ComHelp(class IGameController* pGameController, class CPlayer *pPlayer, const char *pArgs);
void ComInfo(class IGameController* pGameController, class CPlayer *pPlayer, const char *pArgs);


public:
Expand Down Expand Up @@ -183,7 +181,7 @@ class IGameController
void OnPlayerDisconnect(class CPlayer *pPlayer);
void OnPlayerInfoChange(class CPlayer *pPlayer);
void OnPlayerReadyChange(class CPlayer *pPlayer);
void OnPlayerCommand(class CPlayer *pPlayer, const char *pCommandName, const char *pCommandArgs);
// void OnPlayerCommand(class CPlayer *pPlayer, const char *pCommandName, const char *pCommandArgs);

void OnReset();

Expand Down Expand Up @@ -248,7 +246,11 @@ class IGameController
int GetStartWeapon(){ return m_StartWeapon;}

//static void Com_Example(IConsole::IResult *pResult, void *pContext);
//virtual void RegisterChatCommands(CCommandManager *pManager);
virtual void RegisterChatCommands(CCommandManager *pManager);

// chat commands
static void ComHelp(IConsole::IResult *pResult, void *pContext);
static void ComInfo(IConsole::IResult *pResult, void *pContext);
};

#endif
2 changes: 1 addition & 1 deletion src/game/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
#define PREV_CLIENT_VERSION 0x0704
#define SETTINGS_FILENAME "settings07"
static const char GAME_RELEASE_VERSION[8] = "0.7.5";
#define CATCH_VERSION "1.2.1"
#define CATCH_VERSION "1.3.0"
#endif

0 comments on commit 9b1610c

Please sign in to comment.