From 4ca0681689758884e5730881e88c1e98bfc74e46 Mon Sep 17 00:00:00 2001 From: GreYFoX Date: Sat, 27 Aug 2011 17:11:39 +0200 Subject: [PATCH] Added chat commands for only chat and available to all users Thanks @heinrich5991 for this idea of a separate console object to handle it --- src/engine/shared/config.h | 3 +- src/engine/shared/console.cpp | 3 + src/game/ddracecommands.h | 19 +- src/game/server/ddracechat.cpp | 499 +++++++++++++++++++++++++ src/game/server/ddracechat.h | 29 ++ src/game/server/ddracecommands.cpp | 477 ----------------------- src/game/server/entities/character.cpp | 1 - src/game/server/entities/character.h | 1 - src/game/server/gamecontext.cpp | 5 +- src/game/server/gamecontext.h | 2 + 10 files changed, 540 insertions(+), 499 deletions(-) create mode 100644 src/game/server/ddracechat.cpp create mode 100644 src/game/server/ddracechat.h diff --git a/src/engine/shared/config.h b/src/engine/shared/config.h index 1508b88e4..6ccf1e4ee 100644 --- a/src/engine/shared/config.h +++ b/src/engine/shared/config.h @@ -22,7 +22,8 @@ enum CFGFLAG_STORE=8, CFGFLAG_MASTER=16, // DDRace - CMDFLAG_TEST=32 + CMDFLAG_TEST=32, + CFGFLAG_CHAT = 64 }; #endif diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index cc57f12f8..8d55a24bc 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -693,6 +693,9 @@ void CConsole::Register(const char *pName, const char *pParams, pCommand->m_Temp = false; AddCommandSorted(pCommand); + + if(pCommand->m_Flags&CFGFLAG_CHAT) + pCommand->SetAccessLevel(ACCESS_LEVEL_USER); } void CConsole::RegisterTemp(const char *pName, const char *pParams, int Flags, const char *pHelp) diff --git a/src/game/ddracecommands.h b/src/game/ddracecommands.h index 6b47c1e5a..42f368ed5 100644 --- a/src/game/ddracecommands.h +++ b/src/game/ddracecommands.h @@ -28,32 +28,15 @@ CONSOLE_COMMAND("up", "", CFGFLAG_SERVER|CMDFLAG_TEST, ConGoUp, this, "Makes you CONSOLE_COMMAND("down", "", CFGFLAG_SERVER|CMDFLAG_TEST, ConGoDown, this, "Makes you move 1 tile down") CONSOLE_COMMAND("move", "ii", CFGFLAG_SERVER|CMDFLAG_TEST, ConMove, this, "Moves to the tile with x/y-number ii") CONSOLE_COMMAND("move_raw", "ii", CFGFLAG_SERVER|CMDFLAG_TEST, ConMoveRaw, this, "Moves to the point with x/y-coordinates ii") -CONSOLE_COMMAND("credits", "", CFGFLAG_SERVER, ConCredits, this, "Shows the credits of the DDRace mod") -CONSOLE_COMMAND("emote", "?si", CFGFLAG_SERVER, ConEyeEmote, this, "Sets your tee's eye emote") -CONSOLE_COMMAND("broadmsg", "", CFGFLAG_SERVER, ConToggleBroadcast, this, "Toggles showing the server's broadcast message during race on/off") -CONSOLE_COMMAND("eyeemote", "", CFGFLAG_SERVER, ConEyeEmote, this, "Toggles use of standard eye-emotes on/off") -CONSOLE_COMMAND("settings", "?s", CFGFLAG_SERVER, ConSettings, this, "Shows gameplay information for this server") -CONSOLE_COMMAND("help", "?r", CFGFLAG_SERVER, ConHelp, this, "Shows help to command r, general help if left blank") -CONSOLE_COMMAND("info", "", CFGFLAG_SERVER, ConInfo, this, "Shows info about this server") -CONSOLE_COMMAND("me", "r", CFGFLAG_SERVER, ConMe, this, "Like the famous irc command '/me says hi' will display ' says hi'") -CONSOLE_COMMAND("pause", "", CFGFLAG_SERVER, ConTogglePause, this, "Toggles pause on/off (if activated on server)") CONSOLE_COMMAND("force_pause", "vi", CFGFLAG_SERVER, ConForcePause, this, "Force v to pause for i seconds") CONSOLE_COMMAND("force_unpause", "v", CFGFLAG_SERVER, ConForcePause, this, "Set force-pause timer of v to 0.") -CONSOLE_COMMAND("rank", "?r", CFGFLAG_SERVER, ConRank, this, "Shows the rank of player with name r (your rank by default)") -CONSOLE_COMMAND("rules", "", CFGFLAG_SERVER, ConRules, this, "Shows the server rules") -CONSOLE_COMMAND("team", "?i", CFGFLAG_SERVER, ConJoinTeam, this, "Lets you join team i (shows your team if left blank)") -CONSOLE_COMMAND("top5", "?i", CFGFLAG_SERVER, ConTop5, this, "Shows five ranks of the ladder beginning with rank i (1 by default)") -CONSOLE_COMMAND("showothers", "?i", CFGFLAG_SERVER, ConShowOthers, this, "Whether to showplayers from other teams or not (off by default), optional i = 0 for off else for on") +CONSOLE_COMMAND("showothers", "?i", CFGFLAG_CHAT, ConShowOthers, this, "Whether to showplayers from other teams or not (off by default), optional i = 0 for off else for on") CONSOLE_COMMAND("mute", "", CFGFLAG_SERVER, ConMute, this, ""); CONSOLE_COMMAND("muteid", "vi", CFGFLAG_SERVER, ConMuteID, this, ""); CONSOLE_COMMAND("muteip", "si", CFGFLAG_SERVER, ConMuteIP, this, ""); CONSOLE_COMMAND("unmute", "v", CFGFLAG_SERVER, ConUnmute, this, ""); CONSOLE_COMMAND("mutes", "", CFGFLAG_SERVER, ConMutes, this, ""); - -#if defined(CONF_SQL) -CONSOLE_COMMAND("times", "?s?i", CFGFLAG_SERVER, ConTimes, this, "/times ?s?i shows last 5 times of the server or of a player beginning with name s starting with time i (i = 1 by default)") -#endif #undef CONSOLE_COMMAND #endif diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp new file mode 100644 index 000000000..353c22819 --- /dev/null +++ b/src/game/server/ddracechat.cpp @@ -0,0 +1,499 @@ +/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */ +#include "gamecontext.h" +#include +#include +#include +#include +#include +#include +#if defined(CONF_SQL) + #include +#endif + +bool CheckClientID(int ClientID); + +void CGameContext::ConCredits(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + pSelf->SendChatTarget(pResult->m_ClientID,"Teeworlds Team takes most of the credits also"); + pSelf->SendChatTarget(pResult->m_ClientID,"This mod was originally created by \'3DA\'"); + pSelf->SendChatTarget(pResult->m_ClientID,"Now it is maintained & re-coded by:"); + pSelf->SendChatTarget(pResult->m_ClientID,"\'[Egypt]GreYFoX@GTi\' and \'[BlackTee]den\'"); + pSelf->SendChatTarget(pResult->m_ClientID,"Others Helping on the code: \'heinrich5991\', \'ravomavain\', \'Trust o_0 Aeeeh ?!\', \'noother\', \'<3 fisted <3\' & \'LemonFace\'"); + pSelf->SendChatTarget(pResult->m_ClientID,"Documentation: Zeta-Hoernchen, Entities: Fisico"); + pSelf->SendChatTarget(pResult->m_ClientID,"Code (in the past): \'3DA\' and \'Fluxid\'"); + pSelf->SendChatTarget(pResult->m_ClientID,"Please check the changelog on DDRace.info."); + pSelf->SendChatTarget(pResult->m_ClientID,"Also the commit log on github.com/GreYFoXGTi/DDRace."); +} + +void CGameContext::ConInfo(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + pSelf->SendChatTarget(pResult->m_ClientID,"DDRace Mod. Version: " GAME_VERSION); +#if defined( GIT_SHORTREV_HASH ) + pSelf->SendChatTarget(pResult->m_ClientID,"Git revision hash: " GIT_SHORTREV_HASH); +#endif + pSelf->SendChatTarget(pResult->m_ClientID,"Official site: DDRace.info"); + pSelf->SendChatTarget(pResult->m_ClientID,"For more Info /cmdlist"); + pSelf->SendChatTarget(pResult->m_ClientID,"Or visit DDRace.info"); +} + +void CGameContext::ConHelp(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + + if(pResult->NumArguments() == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,"/cmdlist will show a list of all chat commands"); + pSelf->SendChatTarget(pResult->m_ClientID,"/help + any command will show you the help for this command"); + pSelf->SendChatTarget(pResult->m_ClientID,"Example /help settings will display the help about "); + } + else + { + const char *pArg = pResult->GetString(0); + const IConsole::CCommandInfo *pCmdInfo = pSelf->Console()->GetCommandInfo(pArg, CFGFLAG_SERVER, false); + if(pCmdInfo && pCmdInfo->m_pHelp) + pSelf->SendChatTarget(pResult->m_ClientID,pCmdInfo->m_pHelp); + else + pSelf->SendChatTarget(pResult->m_ClientID,"Command is either unknown or you have given a blank command without any parameters."); + } +} + +void CGameContext::ConSettings(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + + if(pResult->NumArguments() == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,"to check a server setting say /settings and setting's name, setting names are:"); + pSelf->SendChatTarget(pResult->m_ClientID,"teams, cheats, collision, hooking, endlesshooking, me, "); + pSelf->SendChatTarget(pResult->m_ClientID,"hitting, oldlaser, timeout, votes, pause and scores"); + } + else + { + const char *pArg = pResult->GetString(0); + char aBuf[256]; + float ColTemp; + float HookTemp; + pSelf->m_Tuning.Get("player_collision", &ColTemp); + pSelf->m_Tuning.Get("player_hooking", &HookTemp); + if(str_comp(pArg, "teams") == 0) + { + str_format(aBuf, sizeof(aBuf), "%s %s", g_Config.m_SvTeam == 1 ? "Teams are available on this server" : !g_Config.m_SvTeam ? "Teams are not available on this server" : "You have to be in a team to play on this server", /*g_Config.m_SvTeamStrict ? "and if you die in a team all of you die" : */"and if you die in a team only you die"); + pSelf->SendChatTarget(pResult->m_ClientID,aBuf); + } + else if(str_comp(pArg, "collision") == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,ColTemp?"Players can collide on this server":"Players Can't collide on this server"); + } + else if(str_comp(pArg, "hooking") == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,HookTemp?"Players can hook each other on this server":"Players Can't hook each other on this server"); + } + else if(str_comp(pArg, "endlesshooking") == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvEndlessDrag?"Players can hook time is unlimited":"Players can hook time is limited"); + } + else if(str_comp(pArg, "hitting") == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvHit?"Player's weapons affect each other":"Player's weapons has no affect on each other"); + } + else if(str_comp(pArg, "oldlaser") == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvOldLaser?"Lasers can hit you if you shot them and that they pull you towards the bounce origin (Like DDRace Beta)":"Lasers can't hit you if you shot them, and they pull others towards the shooter"); + } + else if(str_comp(pArg, "me") == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvSlashMe?"Players can use /me commands the famous IRC Command":"Players Can't use the /me command"); + } + else if(str_comp(pArg, "timeout") == 0) + { + str_format(aBuf, sizeof(aBuf), "The Server Timeout is currently set to %d", g_Config.m_ConnTimeout); + pSelf->SendChatTarget(pResult->m_ClientID,aBuf); + } + else if(str_comp(pArg, "votes") == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvVoteKick?"Players can use Callvote menu tab to kick offenders":"Players Can't use the Callvote menu tab to kick offenders"); + if(g_Config.m_SvVoteKick) + str_format(aBuf, sizeof(aBuf), "Players are banned for %d second(s) if they get voted off", g_Config.m_SvVoteKickBantime); + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvVoteKickBantime?aBuf:"Players are just kicked and not banned if they get voted off"); + } + else if(str_comp(pArg, "pause") == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvPauseable?g_Config.m_SvPauseTime?"/pause is available on this server and it pauses your time too":"/pause is available on this server but it doesn't pause your time":"/pause is NOT available on this server"); + } + else if(str_comp(pArg, "scores") == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvHideScore?"Scores are private on this server":"Scores are public on this server"); + } + } +} + +void CGameContext::ConRules(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + bool Printed = false; + if(g_Config.m_SvDDRaceRules) + { + pSelf->SendChatTarget(pResult->m_ClientID,"No blocking."); + pSelf->SendChatTarget(pResult->m_ClientID,"No insulting / spamming."); + pSelf->SendChatTarget(pResult->m_ClientID,"No fun voting / vote spamming."); + pSelf->SendChatTarget(pResult->m_ClientID,"Breaking any of these rules will result in a penalty, decided by server admins."); + Printed = true; + } + if(g_Config.m_SvRulesLine1[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine1); + Printed = true; + } + if(g_Config.m_SvRulesLine2[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine2); + Printed = true; + } + if(g_Config.m_SvRulesLine3[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine3); + Printed = true; + } + if(g_Config.m_SvRulesLine4[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine4); + Printed = true; + } + if(g_Config.m_SvRulesLine5[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine5); + Printed = true; + } + if(g_Config.m_SvRulesLine6[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine6); + Printed = true; + } + if(g_Config.m_SvRulesLine7[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine7); + Printed = true; + } + if(g_Config.m_SvRulesLine8[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine8); + Printed=true; + } + if(g_Config.m_SvRulesLine9[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine9); + Printed=true; + } + if(g_Config.m_SvRulesLine10[0]) + { + pSelf->SendChatTarget(pResult->m_ClientID,g_Config.m_SvRulesLine10); + Printed = true; + } + if(!Printed) + pSelf->SendChatTarget(pResult->m_ClientID,"No Rules Defined, Kill em all!!"); +} + +void CGameContext::ConTogglePause(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) return; + char aBuf[128]; + + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + if(!pPlayer) + return; + + if(g_Config.m_SvPauseable) + { + CCharacter* pChr = pPlayer->GetCharacter(); + if(!pPlayer->GetTeam() && pChr && (!pChr->GetWeaponGot(WEAPON_NINJA) || pChr->m_FreezeTime) && pChr->IsGrounded() && pChr->m_Pos==pChr->m_PrevPos && !pPlayer->m_InfoSaved) + { + if(pPlayer->m_LastSetTeam + pSelf->Server()->TickSpeed() * g_Config.m_SvPauseFrequency <= pSelf->Server()->Tick()) + { + pPlayer->SaveCharacter(); + pPlayer->m_InfoSaved = true; + pPlayer->SetTeam(TEAM_SPECTATORS); + } + else + pSelf->SendChatTarget(pResult->m_ClientID,"You can\'t pause that often."); + } + else if(pPlayer->GetTeam()==TEAM_SPECTATORS && pPlayer->m_InfoSaved && pPlayer->m_ForcePauseTime == 0) + { + pPlayer->m_PauseInfo.m_Respawn = true; + pPlayer->SetTeam(TEAM_RED); + pPlayer->m_InfoSaved = false; + //pPlayer->LoadCharacter();//TODO:Check if this system Works + } + else if(pChr) + pSelf->SendChatTarget(pResult->m_ClientID,pChr->GetWeaponGot(WEAPON_NINJA)?"You can't use /pause while you are a ninja":(!pChr->IsGrounded())?"You can't use /pause while you are a in air":"You can't use /pause while you are moving"); + else if(pPlayer->m_ForcePauseTime > 0) + { + str_format(aBuf, sizeof(aBuf), "You have been force-paused. %ds left.", pPlayer->m_ForcePauseTime/pSelf->Server()->TickSpeed()); + pSelf->SendChatTarget(pResult->m_ClientID,aBuf); + } + else if(pPlayer->m_ForcePauseTime < 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,"You have been force-paused."); + } + else + pSelf->SendChatTarget(pResult->m_ClientID,"No pause data saved."); + } + else + pSelf->SendChatTarget(pResult->m_ClientID,"Pause isn't allowed on this server."); +} + +void CGameContext::ConTop5(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) return; + + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + if(!pPlayer) + return; + + if(g_Config.m_SvHideScore) + { + pSelf->SendChatTarget(pResult->m_ClientID,"Showing the top 5 is not allowed on this server."); + return; + } + + if(pResult->NumArguments() > 0) + pSelf->Score()->ShowTop5(pResult, pPlayer->GetCID(), pUserData, pResult->GetInteger(0)); + else + pSelf->Score()->ShowTop5(pResult, pPlayer->GetCID(), pUserData); +} +#if defined(CONF_SQL) +void CGameContext::ConTimes(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) return; + + if(g_Config.m_SvUseSQL) + { + CGameContext *pSelf = (CGameContext *)pUserData; + CSqlScore *pScore = (CSqlScore *)pSelf->Score(); + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + if(!pPlayer) + return; + + if(pResult->NumArguments() == 0) + { + pScore->ShowTimes(pPlayer->GetCID(),1); + return; + } + + else if(pResult->NumArguments() < 3) + { + if (pResult->NumArguments() == 1) + { + if(pResult->GetInteger(0) != 0) + pScore->ShowTimes(pPlayer->GetCID(),pResult->GetInteger(0)); + else + pScore->ShowTimes(pPlayer->GetCID(), (str_comp(pResult->GetString(0), "me") == 0) ? pSelf->Server()->ClientName(pResult->m_ClientID) : pResult->GetString(0),1); + return; + } + else if (pResult->GetInteger(1) != 0) + { + pScore->ShowTimes(pPlayer->GetCID(), (str_comp(pResult->GetString(0), "me") == 0) ? pSelf->Server()->ClientName(pResult->m_ClientID) : pResult->GetString(0),pResult->GetInteger(1)); + return; + } + } + + pSelf->SendChatTarget(pResult->m_ClientID,"/times needs 0, 1 or 2 parameter. 1. = name, 2. = start number"); + pSelf->SendChatTarget(pResult->m_ClientID,"Example: /times, /times me, /times Hans, /times \"Papa Smurf\" 5"); + pSelf->SendChatTarget(pResult->m_ClientID,"Bad: /times Papa Smurf 5 # Good: /times \"Papa Smurf\" 5 "); + } +} +#endif + +void CGameContext::ConRank(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) return; + + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + if(!pPlayer) + return; + + if(pResult->NumArguments() > 0) + if(!g_Config.m_SvHideScore) + pSelf->Score()->ShowRank(pResult->m_ClientID, pResult->GetString(0), true); + else + pSelf->SendChatTarget(pResult->m_ClientID,"Showing the rank of other players is not allowed on this server."); + else + pSelf->Score()->ShowRank(pResult->m_ClientID, pSelf->Server()->ClientName(pResult->m_ClientID)); +} + +void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) return; + + if(pSelf->m_VoteCloseTime && pSelf->m_VoteCreator == pResult->m_ClientID) + { + pSelf->SendChatTarget(pResult->m_ClientID,"You are running a vote please try again after the vote is done!"); + return; + } + else if(g_Config.m_SvTeam == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,"Admin has disabled teams"); + return; + } + else if (g_Config.m_SvTeam == 2) + { + pSelf->SendChatTarget(pResult->m_ClientID,"You must join to any team and play with anybody or you will not play"); + } + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + + if(pResult->NumArguments() > 0) + { + if(pPlayer->GetCharacter() == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,"You can't change teams while you are dead/a spectator."); + } + else + { + if(((CGameControllerDDRace*)pSelf->m_pController)->m_Teams.SetCharacterTeam(pPlayer->GetCID(), pResult->GetInteger(0))) + { + if(pPlayer->m_Last_Team + pSelf->Server()->TickSpeed() * g_Config.m_SvTeamChangeDelay <= pSelf->Server()->Tick()) + { + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), "%s joined team %d", pSelf->Server()->ClientName(pPlayer->GetCID()), pResult->GetInteger(0)); + pSelf->SendChat(-1, CGameContext::CHAT_ALL, aBuf); + pPlayer->m_Last_Team = pSelf->Server()->Tick(); + } + else + { + pSelf->SendChatTarget(pResult->m_ClientID,"You can\'t join teams that fast!"); + } + } + else + { + pSelf->SendChatTarget(pResult->m_ClientID,"You cannot join this team at this time"); + } + } + } + else + { + char aBuf[512]; + if(!pPlayer->IsPlaying()) + { + pSelf->SendChatTarget(pResult->m_ClientID,"You can't check your team while you are dead/a spectator."); + } + else + { + str_format(aBuf, sizeof(aBuf), "You are in team %d", ((CGameControllerDDRace*)pSelf->m_pController)->m_Teams.m_Core.Team(pResult->m_ClientID)); + pSelf->SendChatTarget(pResult->m_ClientID,aBuf); + } + } +} + +void CGameContext::ConMe(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) return; + + char aBuf[256 + 24]; + + str_format(aBuf, 256 + 24, "'%s' %s", pSelf->Server()->ClientName(pResult->m_ClientID), pResult->GetString(0)); + if(g_Config.m_SvSlashMe) + pSelf->SendChat(-2, CGameContext::CHAT_ALL, aBuf, pResult->m_ClientID); + else + pSelf->SendChatTarget(pResult->m_ClientID,"/me is disabled on this server, admin can enable it by using sv_slash_me"); +} + +void CGameContext::ConToggleEyeEmote(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) return; + + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + if(!pPlayer) + return; + CCharacter* pChr = pPlayer->GetCharacter(); + if(!pChr) + return; + + pChr->m_EyeEmote = !pChr->m_EyeEmote; + pSelf->SendChatTarget(pResult->m_ClientID,(pChr->m_EyeEmote) ? "You can now use the preset eye emotes." : "You don't have any eye emotes, remember to bind some. (until you die)"); +} + +void CGameContext::ConEyeEmote(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) return; + + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + if(!pPlayer) + return; + CCharacter* pChr = pPlayer->GetCharacter(); + if(!pChr) + return; + + if (pResult->NumArguments() == 0) + { + pSelf->SendChatTarget(pResult->m_ClientID,"Emote commands are: /emote surprise /emote blink /emote close /emote angry /emote happy /emote pain"); + pSelf->SendChatTarget(pResult->m_ClientID,"Example: /emote surprise 10 for 10 seconds or /emote surprise (default 1 second)"); + } + else + { + if (pChr) + { + if (!str_comp(pResult->GetString(0), "angry")) + pChr->m_DefEmote = EMOTE_ANGRY; + else if (!str_comp(pResult->GetString(0), "blink")) + pChr->m_DefEmote = EMOTE_BLINK; + else if (!str_comp(pResult->GetString(0), "close")) + pChr->m_DefEmote = EMOTE_BLINK; + else if (!str_comp(pResult->GetString(0), "happy")) + pChr->m_DefEmote = EMOTE_HAPPY; + else if (!str_comp(pResult->GetString(0), "pain")) + pChr->m_DefEmote = EMOTE_PAIN; + else if (!str_comp(pResult->GetString(0), "surprise")) + pChr->m_DefEmote = EMOTE_SURPRISE; + else if (!str_comp(pResult->GetString(0), "normal")) + pChr->m_DefEmote = EMOTE_NORMAL; + else + pSelf->SendChatTarget(pResult->m_ClientID,"Unknown emote... Say /emote"); + + int Duration = 1; + if (pResult->NumArguments() > 1) + Duration = pResult->GetInteger(1); + + pChr->m_DefEmoteReset = pSelf->Server()->Tick() + Duration * pSelf->Server()->TickSpeed(); + } + } +} + +void CGameContext::ConShowOthersChat(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if(!CheckClientID(pResult->m_ClientID)) return; + + CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; + if(!pPlayer) + return; + if(g_Config.m_SvShowOthers) + { + if(pPlayer->m_IsUsingDDRaceClient) + { + if(pResult->NumArguments()) + pPlayer->m_ShowOthers = pResult->GetInteger(0); + else + pPlayer->m_ShowOthers = !pPlayer->m_ShowOthers; + } + else + pSelf->SendChatTarget(pResult->m_ClientID,"Showing players from other teams is only available with DDRace Client, http://DDRace.info"); + } + else + pSelf->SendChatTarget(pResult->m_ClientID,"Showing players from other teams is disabled by the server admin"); +} + +bool CheckClientID(int ClientID) +{ + dbg_assert(ClientID >= 0 || ClientID < MAX_CLIENTS, "The Client ID is wrong"); + if(ClientID < 0 || ClientID >= MAX_CLIENTS) return false; + return true; +} diff --git a/src/game/server/ddracechat.h b/src/game/server/ddracechat.h new file mode 100644 index 000000000..46ccf0c5b --- /dev/null +++ b/src/game/server/ddracechat.h @@ -0,0 +1,29 @@ +/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */ +#ifndef GAME_SERVER_DDRACECOMMANDS_H +#define GAME_SERVER_DDRACECOMMANDS_H +#undef GAME_SERVER_DDRACECOMMANDS_H // this file can be included several times + +#ifndef CHAT_COMMAND +#define CHAT_COMMAND(name, params, flags, callback, userdata, help) +#endif + +CHAT_COMMAND("credits", "", CFGFLAG_CHAT, ConCredits, this, "Shows the credits of the DDRace mod") +CHAT_COMMAND("emote", "?si", CFGFLAG_CHAT, ConEyeEmote, this, "Sets your tee's eye emote") +CHAT_COMMAND("eyeemote", "", CFGFLAG_CHAT, ConEyeEmote, this, "Toggles use of standard eye-emotes on/off") +CHAT_COMMAND("settings", "?s", CFGFLAG_CHAT, ConSettings, this, "Shows gameplay information for this server") +CHAT_COMMAND("help", "?r", CFGFLAG_CHAT, ConHelp, this, "Shows help to command r, general help if left blank") +CHAT_COMMAND("info", "", CFGFLAG_CHAT, ConInfo, this, "Shows info about this server") +CHAT_COMMAND("me", "r", CFGFLAG_CHAT, ConMe, this, "Like the famous irc command '/me says hi' will display ' says hi'") +CHAT_COMMAND("pause", "", CFGFLAG_CHAT, ConTogglePause, this, "Toggles pause on/off (if activated on server)") +CHAT_COMMAND("rank", "?r", CFGFLAG_CHAT, ConRank, this, "Shows the rank of player with name r (your rank by default)") +CHAT_COMMAND("rules", "", CFGFLAG_CHAT, ConRules, this, "Shows the server rules") +CHAT_COMMAND("team", "?i", CFGFLAG_CHAT, ConJoinTeam, this, "Lets you join team i (shows your team if left blank)") +CHAT_COMMAND("top5", "?i", CFGFLAG_CHAT, ConTop5, this, "Shows five ranks of the ladder beginning with rank i (1 by default)") +CHAT_COMMAND("showothers", "?i", CFGFLAG_CHAT, ConShowOthersChat, this, "Whether to showplayers from other teams or not (off by default), optional i = 0 for off else for on") + +#if defined(CONF_SQL) +CHAT_COMMAND("times", "?s?i", CFGFLAG_CHAT, ConTimes, this, "/times ?s?i shows last 5 times of the server or of a player beginning with name s starting with time i (i = 1 by default)") +#endif +#undef CHAT_COMMAND + +#endif diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index e3a81728a..b61f0d5f5 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -246,189 +246,6 @@ void CGameContext::ConTeleport(IConsole::IResult *pResult, void *pUserData) } } -void CGameContext::ConCredits(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Teeworlds Team takes most of the credits also"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "This mod was originally created by \'3DA\'"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Now it is maintained & re-coded by:"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "\'[Egypt]GreYFoX@GTi\' and \'[BlackTee]den\'"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Others Helping on the code: \'heinrich5991\', \'ravomavain\', \'Trust o_0 Aeeeh ?!\', \'noother\', \'<3 fisted <3\' & \'LemonFace\'"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Documentation: Zeta-Hoernchen, Entities: Fisico"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Code (in the past): \'3DA\' and \'Fluxid\'"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Please check the changelog on DDRace.info."); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Also the commit log on github.com/GreYFoXGTi/DDRace."); -} - -void CGameContext::ConInfo(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "DDRace Mod. Version: " GAME_VERSION); -#if defined( GIT_SHORTREV_HASH ) - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Git revision hash: " GIT_SHORTREV_HASH); -#endif - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Official site: DDRace.info"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "For more Info /cmdlist"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Or visit DDRace.info"); -} - -void CGameContext::ConHelp(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - - if(pResult->NumArguments() == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "/cmdlist will show a list of all chat commands"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "/help + any command will show you the help for this command"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Example /help settings will display the help about "); - } - else - { - const char *pArg = pResult->GetString(0); - const IConsole::CCommandInfo *pCmdInfo = pSelf->Console()->GetCommandInfo(pArg, CFGFLAG_SERVER, false); - if(pCmdInfo && pCmdInfo->m_pHelp) - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", pCmdInfo->m_pHelp); - else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Command is either unknown or you have given a blank command without any parameters."); - } -} - -void CGameContext::ConSettings(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - - if(pResult->NumArguments() == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "to check a server setting say /settings and setting's name, setting names are:"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "teams, cheats, collision, hooking, endlesshooking, me, "); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "hitting, oldlaser, timeout, votes, pause and scores"); - } - else - { - const char *pArg = pResult->GetString(0); - char aBuf[256]; - float ColTemp; - float HookTemp; - pSelf->m_Tuning.Get("player_collision", &ColTemp); - pSelf->m_Tuning.Get("player_hooking", &HookTemp); - if(str_comp(pArg, "teams") == 0) - { - str_format(aBuf, sizeof(aBuf), "%s %s", g_Config.m_SvTeam == 1 ? "Teams are available on this server" : !g_Config.m_SvTeam ? "Teams are not available on this server" : "You have to be in a team to play on this server", /*g_Config.m_SvTeamStrict ? "and if you die in a team all of you die" : */"and if you die in a team only you die"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", aBuf); - } - else if(str_comp(pArg, "collision") == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", ColTemp?"Players can collide on this server":"Players Can't collide on this server"); - } - else if(str_comp(pArg, "hooking") == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", HookTemp?"Players can hook each other on this server":"Players Can't hook each other on this server"); - } - else if(str_comp(pArg, "endlesshooking") == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvEndlessDrag?"Players can hook time is unlimited":"Players can hook time is limited"); - } - else if(str_comp(pArg, "hitting") == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvHit?"Player's weapons affect each other":"Player's weapons has no affect on each other"); - } - else if(str_comp(pArg, "oldlaser") == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvOldLaser?"Lasers can hit you if you shot them and that they pull you towards the bounce origin (Like DDRace Beta)":"Lasers can't hit you if you shot them, and they pull others towards the shooter"); - } - else if(str_comp(pArg, "me") == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvSlashMe?"Players can use /me commands the famous IRC Command":"Players Can't use the /me command"); - } - else if(str_comp(pArg, "timeout") == 0) - { - str_format(aBuf, sizeof(aBuf), "The Server Timeout is currently set to %d", g_Config.m_ConnTimeout); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", aBuf); - } - else if(str_comp(pArg, "votes") == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvVoteKick?"Players can use Callvote menu tab to kick offenders":"Players Can't use the Callvote menu tab to kick offenders"); - if(g_Config.m_SvVoteKick) - str_format(aBuf, sizeof(aBuf), "Players are banned for %d second(s) if they get voted off", g_Config.m_SvVoteKickBantime); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvVoteKickBantime?aBuf:"Players are just kicked and not banned if they get voted off"); - } - else if(str_comp(pArg, "pause") == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvPauseable?g_Config.m_SvPauseTime?"/pause is available on this server and it pauses your time too":"/pause is available on this server but it doesn't pause your time":"/pause is NOT available on this server"); - } - else if(str_comp(pArg, "scores") == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvHideScore?"Scores are private on this server":"Scores are public on this server"); - } - } -} - -void CGameContext::ConRules(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - bool Printed = false; - if(g_Config.m_SvDDRaceRules) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "No blocking."); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "No insulting / spamming."); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "No fun voting / vote spamming."); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Breaking any of these rules will result in a penalty, decided by server admins."); - Printed = true; - } - if(g_Config.m_SvRulesLine1[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine1); - Printed = true; - } - if(g_Config.m_SvRulesLine2[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine2); - Printed = true; - } - if(g_Config.m_SvRulesLine3[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine3); - Printed = true; - } - if(g_Config.m_SvRulesLine4[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine4); - Printed = true; - } - if(g_Config.m_SvRulesLine5[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine5); - Printed = true; - } - if(g_Config.m_SvRulesLine6[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine6); - Printed = true; - } - if(g_Config.m_SvRulesLine7[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine7); - Printed = true; - } - if(g_Config.m_SvRulesLine8[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine8); - Printed=true; - } - if(g_Config.m_SvRulesLine9[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine9); - Printed=true; - } - if(g_Config.m_SvRulesLine10[0]) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", g_Config.m_SvRulesLine10); - Printed = true; - } - if(!Printed) - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "No Rules Defined, Kill em all!!"); -} - void CGameContext::ConKill(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; @@ -443,55 +260,6 @@ void CGameContext::ConKill(IConsole::IResult *pResult, void *pUserData) //pPlayer->m_RespawnTick = pSelf->Server()->Tick() + pSelf->Server()->TickSpeed() * g_Config.m_SvSuicidePenalty; } -void CGameContext::ConTogglePause(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - if(!CheckClientID(pResult->m_ClientID)) return; - char aBuf[128]; - - CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; - if(!pPlayer) - return; - - if(g_Config.m_SvPauseable) - { - CCharacter* pChr = pPlayer->GetCharacter(); - if(!pPlayer->GetTeam() && pChr && (!pChr->GetWeaponGot(WEAPON_NINJA) || pChr->m_FreezeTime) && pChr->IsGrounded() && pChr->m_Pos==pChr->m_PrevPos && !pPlayer->m_InfoSaved) - { - if(pPlayer->m_LastSetTeam + pSelf->Server()->TickSpeed() * g_Config.m_SvPauseFrequency <= pSelf->Server()->Tick()) - { - pPlayer->SaveCharacter(); - pPlayer->m_InfoSaved = true; - pPlayer->SetTeam(TEAM_SPECTATORS); - } - else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You can\'t pause that often."); - } - else if(pPlayer->GetTeam()==TEAM_SPECTATORS && pPlayer->m_InfoSaved && pPlayer->m_ForcePauseTime == 0) - { - pPlayer->m_PauseInfo.m_Respawn = true; - pPlayer->SetTeam(TEAM_RED); - pPlayer->m_InfoSaved = false; - //pPlayer->LoadCharacter();//TODO:Check if this system Works - } - else if(pChr) - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", pChr->GetWeaponGot(WEAPON_NINJA)?"You can't use /pause while you are a ninja":(!pChr->IsGrounded())?"You can't use /pause while you are a in air":"You can't use /pause while you are moving"); - else if(pPlayer->m_ForcePauseTime > 0) - { - str_format(aBuf, sizeof(aBuf), "You have been force-paused. %ds left.", pPlayer->m_ForcePauseTime/pSelf->Server()->TickSpeed()); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", aBuf); - } - else if(pPlayer->m_ForcePauseTime < 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You have been force-paused."); - } - else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "No pause data saved."); - } - else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Pause isn't allowed on this server."); -} - void CGameContext::ConForcePause(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; @@ -527,244 +295,6 @@ void CGameContext::ConForcePause(IConsole::IResult *pResult, void *pUserData) pSelf->SendChat(-1, CHAT_ALL, aBuf); } -void CGameContext::ConTop5(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - if(!CheckClientID(pResult->m_ClientID)) return; - - CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; - if(!pPlayer) - return; - - if(g_Config.m_SvHideScore) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Showing the top 5 is not allowed on this server."); - return; - } - - if(pResult->NumArguments() > 0) - pSelf->Score()->ShowTop5(pResult, pPlayer->GetCID(), pUserData, pResult->GetInteger(0)); - else - pSelf->Score()->ShowTop5(pResult, pPlayer->GetCID(), pUserData); -} -#if defined(CONF_SQL) -void CGameContext::ConTimes(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - if(!CheckClientID(pResult->m_ClientID)) return; - - if(g_Config.m_SvUseSQL) - { - CGameContext *pSelf = (CGameContext *)pUserData; - CSqlScore *pScore = (CSqlScore *)pSelf->Score(); - CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; - if(!pPlayer) - return; - - if(pResult->NumArguments() == 0) - { - pScore->ShowTimes(pPlayer->GetCID(),1); - return; - } - - else if(pResult->NumArguments() < 3) - { - if (pResult->NumArguments() == 1) - { - if(pResult->GetInteger(0) != 0) - pScore->ShowTimes(pPlayer->GetCID(),pResult->GetInteger(0)); - else - pScore->ShowTimes(pPlayer->GetCID(), (str_comp(pResult->GetString(0), "me") == 0) ? pSelf->Server()->ClientName(pResult->m_ClientID) : pResult->GetString(0),1); - return; - } - else if (pResult->GetInteger(1) != 0) - { - pScore->ShowTimes(pPlayer->GetCID(), (str_comp(pResult->GetString(0), "me") == 0) ? pSelf->Server()->ClientName(pResult->m_ClientID) : pResult->GetString(0),pResult->GetInteger(1)); - return; - } - } - - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "/times needs 0, 1 or 2 parameter. 1. = name, 2. = start number"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Example: /times, /times me, /times Hans, /times \"Papa Smurf\" 5"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Bad: /times Papa Smurf 5 # Good: /times \"Papa Smurf\" 5 "); - } -} -#endif - -void CGameContext::ConRank(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - if(!CheckClientID(pResult->m_ClientID)) return; - - CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; - if(!pPlayer) - return; - - if(pResult->NumArguments() > 0) - if(!g_Config.m_SvHideScore) - pSelf->Score()->ShowRank(pResult->m_ClientID, pResult->GetString(0), true); - else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Showing the rank of other players is not allowed on this server."); - else - pSelf->Score()->ShowRank(pResult->m_ClientID, pSelf->Server()->ClientName(pResult->m_ClientID)); -} - -void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - if(!CheckClientID(pResult->m_ClientID)) return; - - if(pSelf->m_VoteCloseTime && pSelf->m_VoteCreator == pResult->m_ClientID) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You are running a vote please try again after the vote is done!"); - return; - } - else if(g_Config.m_SvTeam == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Admin has disabled teams"); - return; - } - else if (g_Config.m_SvTeam == 2) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You must join to any team and play with anybody or you will not play"); - } - CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; - - if(pResult->NumArguments() > 0) - { - if(pPlayer->GetCharacter() == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You can't change teams while you are dead/a spectator."); - } - else - { - if(((CGameControllerDDRace*)pSelf->m_pController)->m_Teams.SetCharacterTeam(pPlayer->GetCID(), pResult->GetInteger(0))) - { - if(pPlayer->m_Last_Team + pSelf->Server()->TickSpeed() * g_Config.m_SvTeamChangeDelay <= pSelf->Server()->Tick()) - { - char aBuf[512]; - str_format(aBuf, sizeof(aBuf), "%s joined team %d", pSelf->Server()->ClientName(pPlayer->GetCID()), pResult->GetInteger(0)); - pSelf->SendChat(-1, CGameContext::CHAT_ALL, aBuf); - pPlayer->m_Last_Team = pSelf->Server()->Tick(); - } - else - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You can\'t join teams that fast!"); - } - } - else - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You cannot join this team at this time"); - } - } - } - else - { - char aBuf[512]; - if(!pPlayer->IsPlaying()) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You can't check your team while you are dead/a spectator."); - } - else - { - str_format(aBuf, sizeof(aBuf), "You are in team %d", ((CGameControllerDDRace*)pSelf->m_pController)->m_Teams.m_Core.Team(pResult->m_ClientID)); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", aBuf); - } - } -} - -void CGameContext::ConMe(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - if(!CheckClientID(pResult->m_ClientID)) return; - - char aBuf[256 + 24]; - - str_format(aBuf, 256 + 24, "'%s' %s", pSelf->Server()->ClientName(pResult->m_ClientID), pResult->GetString(0)); - if(g_Config.m_SvSlashMe) - pSelf->SendChat(-2, CGameContext::CHAT_ALL, aBuf, pResult->m_ClientID); - else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "/me is disabled on this server, admin can enable it by using sv_slash_me"); -} - -void CGameContext::ConToggleEyeEmote(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - if(!CheckClientID(pResult->m_ClientID)) return; - - CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; - if(!pPlayer) - return; - CCharacter* pChr = pPlayer->GetCharacter(); - if(!pChr) - return; - - pChr->m_EyeEmote = !pChr->m_EyeEmote; - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", (pChr->m_EyeEmote) ? "You can now use the preset eye emotes." : "You don't have any eye emotes, remember to bind some. (until you die)"); -} - -void CGameContext::ConToggleBroadcast(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - if(!CheckClientID(pResult->m_ClientID)) return; - - CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; - if(!pPlayer) - return; - CCharacter* pChr = pPlayer->GetCharacter(); - if(!pChr) - return; - - pChr->m_BroadCast = !pChr->m_BroadCast; -} - -void CGameContext::ConEyeEmote(IConsole::IResult *pResult, void *pUserData) -{ - CGameContext *pSelf = (CGameContext *)pUserData; - if(!CheckClientID(pResult->m_ClientID)) return; - - CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; - if(!pPlayer) - return; - CCharacter* pChr = pPlayer->GetCharacter(); - if(!pChr) - return; - - if (pResult->NumArguments() == 0) - { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Emote commands are: /emote surprise /emote blink /emote close /emote angry /emote happy /emote pain"); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Example: /emote surprise 10 for 10 seconds or /emote surprise (default 1 second)"); - } - else - { - if (pChr) - { - if (!str_comp(pResult->GetString(0), "angry")) - pChr->m_DefEmote = EMOTE_ANGRY; - else if (!str_comp(pResult->GetString(0), "blink")) - pChr->m_DefEmote = EMOTE_BLINK; - else if (!str_comp(pResult->GetString(0), "close")) - pChr->m_DefEmote = EMOTE_BLINK; - else if (!str_comp(pResult->GetString(0), "happy")) - pChr->m_DefEmote = EMOTE_HAPPY; - else if (!str_comp(pResult->GetString(0), "pain")) - pChr->m_DefEmote = EMOTE_PAIN; - else if (!str_comp(pResult->GetString(0), "surprise")) - pChr->m_DefEmote = EMOTE_SURPRISE; - else if (!str_comp(pResult->GetString(0), "normal")) - pChr->m_DefEmote = EMOTE_NORMAL; - else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Unknown emote... Say /emote"); - - int Duration = 1; - if (pResult->NumArguments() > 1) - Duration = pResult->GetInteger(1); - - pChr->m_DefEmoteReset = pSelf->Server()->Tick() + Duration * pSelf->Server()->TickSpeed(); - } - } -} - void CGameContext::ConShowOthers(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; @@ -887,10 +417,3 @@ void CGameContext::ConMutes(IConsole::IResult *pResult, void *pUserData) pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "mutes", aBuf); } } - -bool CheckClientID(int ClientID) -{ - dbg_assert(ClientID >= 0 || ClientID < MAX_CLIENTS, "The Client ID is wrong"); - if(ClientID < 0 || ClientID >= MAX_CLIENTS) return false; - return true; -} diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 8141aa2cd..650d219ad 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -1546,7 +1546,6 @@ void CCharacter::DDRaceInit() { m_DDRaceState = DDRACE_NONE; m_PrevPos = m_Pos; - m_BroadCast = true; m_EyeEmote = true; m_LastBroadcast = 0; m_TeamBeforeSuper = 0; diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index fbca61629..e75351aa1 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -178,7 +178,6 @@ public: int m_CpTick; int m_CpActive; float m_CpCurrent[25]; - bool m_BroadCast; int m_TileIndex; int m_TileFlags; int m_TileFIndex; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 71e1118d4..1ff86cee3 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -49,6 +49,7 @@ void CGameContext::Construct(int Resetting) m_pVoteOptionHeap = new CHeap(); m_pScore = 0; m_NumMutes = 0; + m_pChatCommands = CreateConsole(CFGFLAG_CHAT); } } @@ -754,7 +755,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) else Console()->SetAccessLevel(IConsole::ACCESS_LEVEL_USER); // Todo(Shereef Marzouk): Follow up on the RCON/Chat redirection - if(!Console()->ExecuteLine(pMsg->m_pMessage + 1, ClientID)) + if(!m_pChatCommands->ExecuteLine(pMsg->m_pMessage + 1, ClientID)) { char aBuf[128]; str_format(aBuf, sizeof(aBuf), "The execution of the line '%s' has been denied (maybe the admin didn't allow the command for users).", pMsg->m_pMessage + 1); @@ -1659,6 +1660,8 @@ void CGameContext::OnConsoleInit() #define CONSOLE_COMMAND(name, params, flags, callback, userdata, help) m_pConsole->Register(name, params, flags, callback, userdata, help); #include "game/ddracecommands.h" +#define CHAT_COMMAND(name, params, flags, callback, userdata, help) m_pChatCommands->Register(name, params, flags, callback, userdata, help); +#include "ddracechat.h" } void CGameContext::OnInit(/*class IKernel *pKernel*/) diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index f09ba532c..ad47e0afe 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -174,6 +174,7 @@ public: private: + IConsole* m_pChatCommands; bool m_VoteWillPass; class IScore *m_pScore; @@ -230,6 +231,7 @@ private: static void ConToggleBroadcast(IConsole::IResult *pResult, void *pUserData); static void ConEyeEmote(IConsole::IResult *pResult, void *pUserData); static void ConShowOthers(IConsole::IResult *pResult, void *pUserData); + static void ConShowOthersChat(IConsole::IResult *pResult, void *pUserData); static void ConMute(IConsole::IResult *pResult, void *pUserData); static void ConMuteID(IConsole::IResult *pResult, void *pUserData);