| 1 | /* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */ |
| 2 | #include "gamecontext.h" |
| 3 | #include "player.h" |
| 4 | #include "score.h" |
| 5 | |
| 6 | #include <base/log.h> |
| 7 | #include <base/time.h> |
| 8 | |
| 9 | #include <engine/shared/config.h> |
| 10 | #include <engine/shared/protocol.h> |
| 11 | |
| 12 | #include <game/server/entities/character.h> |
| 13 | #include <game/server/gamemodes/ddnet.h> |
| 14 | #include <game/server/teams.h> |
| 15 | #include <game/team_state.h> |
| 16 | #include <game/teamscore.h> |
| 17 | #include <game/version.h> |
| 18 | |
| 19 | void CGameContext::ConInfo(IConsole::IResult *pResult, void *pUserData) |
| 20 | { |
| 21 | log_info("chatresp" , "DDraceNetwork Mod. Version: " GAME_VERSION); |
| 22 | if(GIT_SHORTREV_HASH) |
| 23 | { |
| 24 | char aBuf[64]; |
| 25 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "Git revision hash: %s" , GIT_SHORTREV_HASH); |
| 26 | log_info("chatresp" , "%s" , aBuf); |
| 27 | } |
| 28 | log_info("chatresp" , "Official site: DDNet.org" ); |
| 29 | log_info("chatresp" , "For more info: /cmdlist" ); |
| 30 | log_info("chatresp" , "Or visit DDNet.org" ); |
| 31 | } |
| 32 | |
| 33 | void CGameContext::ConList(IConsole::IResult *pResult, void *pUserData) |
| 34 | { |
| 35 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 36 | int ClientId = pResult->m_ClientId; |
| 37 | if(!CheckClientId(ClientId)) |
| 38 | return; |
| 39 | |
| 40 | if(pResult->NumArguments() > 0) |
| 41 | pSelf->List(ClientId, pFilter: pResult->GetString(Index: 0)); |
| 42 | else |
| 43 | pSelf->List(ClientId, pFilter: "" ); |
| 44 | } |
| 45 | |
| 46 | void CGameContext::ConHelp(IConsole::IResult *pResult, void *pUserData) |
| 47 | { |
| 48 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 49 | |
| 50 | if(pResult->NumArguments() == 0) |
| 51 | { |
| 52 | log_info("chatresp" , "/cmdlist will show a list of all chat commands" ); |
| 53 | log_info("chatresp" , "/help + any command will show you the help for this command" ); |
| 54 | log_info("chatresp" , "Example /help settings will display the help about /settings" ); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | const char *pArg = pResult->GetString(Index: 0); |
| 59 | const IConsole::ICommandInfo *pCmdInfo = |
| 60 | pSelf->Console()->GetCommandInfo(pName: pArg, FlagMask: CFGFLAG_SERVER | CFGFLAG_CHAT, Temp: false); |
| 61 | if(pCmdInfo) |
| 62 | { |
| 63 | if(pCmdInfo->Params()) |
| 64 | { |
| 65 | char aBuf[256]; |
| 66 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "Usage: %s %s" , pCmdInfo->Name(), pCmdInfo->Params()); |
| 67 | log_info("chatresp" , "%s" , aBuf); |
| 68 | } |
| 69 | |
| 70 | if(pCmdInfo->Help()) |
| 71 | log_info("chatresp" , "%s" , pCmdInfo->Help()); |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | char aBuf[256]; |
| 76 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "Unknown command %s" , pArg); |
| 77 | log_info("chatresp" , "%s" , aBuf); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void CGameContext::ConSettings(IConsole::IResult *pResult, void *pUserData) |
| 82 | { |
| 83 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 84 | |
| 85 | if(pResult->NumArguments() == 0) |
| 86 | { |
| 87 | log_info("chatresp" , "to check a server setting say /settings and setting's name, setting names are:" ); |
| 88 | log_info("chatresp" , "teams, cheats, collision, hooking, endlesshooking," ); |
| 89 | log_info("chatresp" , "hitting, oldlaser, timeout, votes, pause and scores" ); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | const char *pArg = pResult->GetString(Index: 0); |
| 94 | char aBuf[256]; |
| 95 | float ColTemp; |
| 96 | float HookTemp; |
| 97 | pSelf->GlobalTuning()->Get(pName: "player_collision" , pValue: &ColTemp); |
| 98 | pSelf->GlobalTuning()->Get(pName: "player_hooking" , pValue: &HookTemp); |
| 99 | if(str_comp_nocase(a: pArg, b: "teams" ) == 0) |
| 100 | { |
| 101 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s %s" , |
| 102 | g_Config.m_SvTeam == SV_TEAM_ALLOWED ? |
| 103 | "Teams are available on this server" : |
| 104 | (g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) ? |
| 105 | "Teams are not available on this server" : |
| 106 | "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" : */ |
| 107 | "and all of your team will die if the team is locked" ); |
| 108 | log_info("chatresp" , "%s" , aBuf); |
| 109 | } |
| 110 | else if(str_comp_nocase(a: pArg, b: "cheats" ) == 0) |
| 111 | { |
| 112 | log_info("chatresp" , g_Config.m_SvTestingCommands ? |
| 113 | "Cheats are enabled on this server" : |
| 114 | "Cheats are disabled on this server" ); |
| 115 | } |
| 116 | else if(str_comp_nocase(a: pArg, b: "collision" ) == 0) |
| 117 | { |
| 118 | log_info("chatresp" , ColTemp ? |
| 119 | "Players can collide on this server" : |
| 120 | "Players can't collide on this server" ); |
| 121 | } |
| 122 | else if(str_comp_nocase(a: pArg, b: "hooking" ) == 0) |
| 123 | { |
| 124 | log_info("chatresp" , HookTemp ? |
| 125 | "Players can hook each other on this server" : |
| 126 | "Players can't hook each other on this server" ); |
| 127 | } |
| 128 | else if(str_comp_nocase(a: pArg, b: "endlesshooking" ) == 0) |
| 129 | { |
| 130 | log_info("chatresp" , g_Config.m_SvEndlessDrag ? |
| 131 | "Players hook time is unlimited" : |
| 132 | "Players hook time is limited" ); |
| 133 | } |
| 134 | else if(str_comp_nocase(a: pArg, b: "hitting" ) == 0) |
| 135 | { |
| 136 | log_info("chatresp" , g_Config.m_SvHit ? |
| 137 | "Players weapons affect others" : |
| 138 | "Players weapons has no affect on others" ); |
| 139 | } |
| 140 | else if(str_comp_nocase(a: pArg, b: "oldlaser" ) == 0) |
| 141 | { |
| 142 | log_info("chatresp" , g_Config.m_SvOldLaser ? |
| 143 | "Lasers can hit you if you shot them and they pull you towards the bounce origin (Like DDRace Beta)" : |
| 144 | "Lasers can't hit you if you shot them, and they pull others towards the shooter" ); |
| 145 | } |
| 146 | else if(str_comp_nocase(a: pArg, b: "timeout" ) == 0) |
| 147 | { |
| 148 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "The Server Timeout is currently set to %d seconds" , g_Config.m_ConnTimeout); |
| 149 | log_info("chatresp" , "%s" , aBuf); |
| 150 | } |
| 151 | else if(str_comp_nocase(a: pArg, b: "votes" ) == 0) |
| 152 | { |
| 153 | log_info("chatresp" , g_Config.m_SvVoteKick ? |
| 154 | "Players can use Callvote menu tab to kick offenders" : |
| 155 | "Players can't use the Callvote menu tab to kick offenders" ); |
| 156 | if(g_Config.m_SvVoteKick) |
| 157 | { |
| 158 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), |
| 159 | format: "Players are banned for %d minute(s) if they get voted off" , g_Config.m_SvVoteKickBantime); |
| 160 | |
| 161 | log_info("chatresp" , "%s" , g_Config.m_SvVoteKickBantime ? aBuf : "Players are just kicked and not banned if they get voted off" ); |
| 162 | } |
| 163 | } |
| 164 | else if(str_comp_nocase(a: pArg, b: "pause" ) == 0) |
| 165 | { |
| 166 | log_info("chatresp" , g_Config.m_SvPauseable ? |
| 167 | "/spec will pause you and your tee will vanish" : |
| 168 | "/spec will pause you but your tee will not vanish" ); |
| 169 | } |
| 170 | else if(str_comp_nocase(a: pArg, b: "scores" ) == 0) |
| 171 | { |
| 172 | log_info("chatresp" , g_Config.m_SvHideScore ? |
| 173 | "Scores are private on this server" : |
| 174 | "Scores are public on this server" ); |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | log_info("chatresp" , "no matching settings found, type /settings to view them" ); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | void CGameContext::ConRules(IConsole::IResult *pResult, void *pUserData) |
| 183 | { |
| 184 | bool Printed = false; |
| 185 | if(g_Config.m_SvDDRaceRules) |
| 186 | { |
| 187 | log_info("chatresp" , "Be nice." ); |
| 188 | Printed = true; |
| 189 | } |
| 190 | char *apRuleLines[] = { |
| 191 | g_Config.m_SvRulesLine1, |
| 192 | g_Config.m_SvRulesLine2, |
| 193 | g_Config.m_SvRulesLine3, |
| 194 | g_Config.m_SvRulesLine4, |
| 195 | g_Config.m_SvRulesLine5, |
| 196 | g_Config.m_SvRulesLine6, |
| 197 | g_Config.m_SvRulesLine7, |
| 198 | g_Config.m_SvRulesLine8, |
| 199 | g_Config.m_SvRulesLine9, |
| 200 | g_Config.m_SvRulesLine10, |
| 201 | }; |
| 202 | for(auto &pRuleLine : apRuleLines) |
| 203 | { |
| 204 | if(pRuleLine[0]) |
| 205 | { |
| 206 | log_info("chatresp" , "%s" , pRuleLine); |
| 207 | Printed = true; |
| 208 | } |
| 209 | } |
| 210 | if(!Printed) |
| 211 | { |
| 212 | log_info("chatresp" , "No Rules Defined, Kill em all!!" ); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | static void ToggleSpecPause(IConsole::IResult *pResult, void *pUserData, int PauseType) |
| 217 | { |
| 218 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 219 | return; |
| 220 | |
| 221 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 222 | IServer *pServ = pSelf->Server(); |
| 223 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 224 | if(!pPlayer) |
| 225 | return; |
| 226 | |
| 227 | int PauseState = pPlayer->IsPaused(); |
| 228 | if(PauseState > 0) |
| 229 | { |
| 230 | char aBuf[128]; |
| 231 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "You are force-paused for %d seconds." , (PauseState - pServ->Tick()) / pServ->TickSpeed()); |
| 232 | log_info("chatresp" , "%s" , aBuf); |
| 233 | } |
| 234 | else if(pResult->NumArguments() > 0) |
| 235 | { |
| 236 | if(-PauseState == PauseType && pPlayer->SpectatorId() != pResult->m_ClientId && pServ->ClientIngame(ClientId: pPlayer->SpectatorId()) && !str_comp(a: pServ->ClientName(ClientId: pPlayer->SpectatorId()), b: pResult->GetString(Index: 0))) |
| 237 | { |
| 238 | pPlayer->Pause(State: CPlayer::PAUSE_NONE, Force: false); |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | pPlayer->Pause(State: PauseType, Force: false); |
| 243 | pPlayer->SpectatePlayerName(pName: pResult->GetString(Index: 0)); |
| 244 | } |
| 245 | } |
| 246 | else if(-PauseState != CPlayer::PAUSE_NONE && PauseType != CPlayer::PAUSE_NONE) |
| 247 | { |
| 248 | pPlayer->Pause(State: CPlayer::PAUSE_NONE, Force: false); |
| 249 | } |
| 250 | else if(-PauseState != PauseType) |
| 251 | { |
| 252 | pPlayer->Pause(State: PauseType, Force: false); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | static void ToggleSpecPauseVoted(IConsole::IResult *pResult, void *pUserData, int PauseType) |
| 257 | { |
| 258 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 259 | return; |
| 260 | |
| 261 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 262 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 263 | if(!pPlayer) |
| 264 | return; |
| 265 | |
| 266 | int PauseState = pPlayer->IsPaused(); |
| 267 | if(PauseState > 0) |
| 268 | { |
| 269 | IServer *pServ = pSelf->Server(); |
| 270 | char aBuf[128]; |
| 271 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "You are force-paused for %d seconds." , (PauseState - pServ->Tick()) / pServ->TickSpeed()); |
| 272 | log_info("chatresp" , "%s" , aBuf); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | bool IsPlayerBeingVoted = pSelf->m_VoteCloseTime && |
| 277 | (pSelf->IsKickVote() || pSelf->IsSpecVote()) && |
| 278 | pResult->m_ClientId != pSelf->m_VoteVictim; |
| 279 | if((!IsPlayerBeingVoted && -PauseState == PauseType) || |
| 280 | (IsPlayerBeingVoted && PauseState && pPlayer->SpectatorId() == pSelf->m_VoteVictim)) |
| 281 | { |
| 282 | pPlayer->Pause(State: CPlayer::PAUSE_NONE, Force: false); |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | pPlayer->Pause(State: PauseType, Force: false); |
| 287 | if(IsPlayerBeingVoted) |
| 288 | pPlayer->SetSpectatorId(pSelf->m_VoteVictim); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | void CGameContext::ConToggleSpec(IConsole::IResult *pResult, void *pUserData) |
| 293 | { |
| 294 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 295 | return; |
| 296 | |
| 297 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 298 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 299 | if(!pPlayer) |
| 300 | return; |
| 301 | |
| 302 | int PauseType = g_Config.m_SvPauseable ? CPlayer::PAUSE_SPEC : CPlayer::PAUSE_PAUSED; |
| 303 | |
| 304 | if(pPlayer->GetCharacter()) |
| 305 | { |
| 306 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 307 | if(Teams.IsPractice(Team: Teams.m_Core.Team(ClientId: pResult->m_ClientId))) |
| 308 | PauseType = CPlayer::PAUSE_SPEC; |
| 309 | } |
| 310 | |
| 311 | ToggleSpecPause(pResult, pUserData, PauseType); |
| 312 | } |
| 313 | |
| 314 | void CGameContext::ConToggleSpecVoted(IConsole::IResult *pResult, void *pUserData) |
| 315 | { |
| 316 | ToggleSpecPauseVoted(pResult, pUserData, PauseType: g_Config.m_SvPauseable ? CPlayer::PAUSE_SPEC : CPlayer::PAUSE_PAUSED); |
| 317 | } |
| 318 | |
| 319 | void CGameContext::ConTogglePause(IConsole::IResult *pResult, void *pUserData) |
| 320 | { |
| 321 | ToggleSpecPause(pResult, pUserData, PauseType: CPlayer::PAUSE_PAUSED); |
| 322 | } |
| 323 | |
| 324 | void CGameContext::ConTogglePauseVoted(IConsole::IResult *pResult, void *pUserData) |
| 325 | { |
| 326 | ToggleSpecPauseVoted(pResult, pUserData, PauseType: CPlayer::PAUSE_PAUSED); |
| 327 | } |
| 328 | |
| 329 | void CGameContext::ConTeamTop5(IConsole::IResult *pResult, void *pUserData) |
| 330 | { |
| 331 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 332 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 333 | return; |
| 334 | |
| 335 | if(g_Config.m_SvHideScore) |
| 336 | { |
| 337 | log_info("chatresp" , "Showing the team top 5 is not allowed on this server." ); |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | if(pResult->NumArguments() == 0) |
| 342 | { |
| 343 | pSelf->Score()->ShowTeamTop5(ClientId: pResult->m_ClientId, Offset: 1); |
| 344 | } |
| 345 | else if(pResult->NumArguments() == 1) |
| 346 | { |
| 347 | if(pResult->GetInteger(Index: 0) != 0) |
| 348 | { |
| 349 | pSelf->Score()->ShowTeamTop5(ClientId: pResult->m_ClientId, Offset: pResult->GetInteger(Index: 0)); |
| 350 | } |
| 351 | else |
| 352 | { |
| 353 | const char *pRequestedName = (str_comp_nocase(a: pResult->GetString(Index: 0), b: "me" ) == 0) ? |
| 354 | pSelf->Server()->ClientName(ClientId: pResult->m_ClientId) : |
| 355 | pResult->GetString(Index: 0); |
| 356 | pSelf->Score()->ShowPlayerTeamTop5(ClientId: pResult->m_ClientId, pName: pRequestedName, Offset: 0); |
| 357 | } |
| 358 | } |
| 359 | else if(pResult->NumArguments() == 2 && pResult->GetInteger(Index: 1) != 0) |
| 360 | { |
| 361 | const char *pRequestedName = (str_comp_nocase(a: pResult->GetString(Index: 0), b: "me" ) == 0) ? |
| 362 | pSelf->Server()->ClientName(ClientId: pResult->m_ClientId) : |
| 363 | pResult->GetString(Index: 0); |
| 364 | pSelf->Score()->ShowPlayerTeamTop5(ClientId: pResult->m_ClientId, pName: pRequestedName, Offset: pResult->GetInteger(Index: 1)); |
| 365 | } |
| 366 | else |
| 367 | { |
| 368 | log_info("chatresp" , "/top5team needs 0, 1 or 2 parameter. 1. = name, 2. = start number" ); |
| 369 | log_info("chatresp" , "Example: /top5team, /top5team me, /top5team Hans, /top5team \"Papa Smurf\" 5" ); |
| 370 | log_info("chatresp" , "Bad: /top5team Papa Smurf 5 # Good: /top5team \"Papa Smurf\" 5 " ); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | void CGameContext::ConTop(IConsole::IResult *pResult, void *pUserData) |
| 375 | { |
| 376 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 377 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 378 | return; |
| 379 | |
| 380 | if(g_Config.m_SvHideScore) |
| 381 | { |
| 382 | log_info("chatresp" , "Showing the top is not allowed on this server." ); |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | if(pResult->NumArguments() > 0) |
| 387 | pSelf->Score()->ShowTop(ClientId: pResult->m_ClientId, Offset: pResult->GetInteger(Index: 0)); |
| 388 | else |
| 389 | pSelf->Score()->ShowTop(ClientId: pResult->m_ClientId); |
| 390 | } |
| 391 | |
| 392 | void CGameContext::ConTimes(IConsole::IResult *pResult, void *pUserData) |
| 393 | { |
| 394 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 395 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 396 | return; |
| 397 | |
| 398 | int Offset = 1; |
| 399 | const char *pRequestedName = nullptr; |
| 400 | |
| 401 | // input validation |
| 402 | if(pResult->NumArguments() == 1) |
| 403 | { |
| 404 | if(pResult->GetInteger(Index: 0) != 0) |
| 405 | { |
| 406 | Offset = pResult->GetInteger(Index: 0); |
| 407 | } |
| 408 | else |
| 409 | { |
| 410 | pRequestedName = pResult->GetString(Index: 0); |
| 411 | } |
| 412 | } |
| 413 | else if(pResult->NumArguments() == 2) |
| 414 | { |
| 415 | pRequestedName = pResult->GetString(Index: 0); |
| 416 | Offset = pResult->GetInteger(Index: 1); |
| 417 | } |
| 418 | else if(pResult->NumArguments() > 2) |
| 419 | { |
| 420 | log_info("chatresp" , "/times needs 0, 1 or 2 parameter. 1. = name, 2. = start number" ); |
| 421 | log_info("chatresp" , "Example: /times, /times me, /times Hans, /times \"Papa Smurf\" 5" ); |
| 422 | log_info("chatresp" , "Bad: /times Papa Smurf 5 # Good: /times \"Papa Smurf\" 5 " ); |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | // execution |
| 427 | if(g_Config.m_SvHideScore) |
| 428 | { |
| 429 | if(pRequestedName && str_comp_nocase(a: pRequestedName, b: "me" ) != 0 && str_comp_nocase(a: pRequestedName, b: pSelf->Server()->ClientName(ClientId: pResult->m_ClientId)) != 0) |
| 430 | { |
| 431 | log_info("chatresp" , "Showing the times of others is not allowed on this server." ); |
| 432 | return; |
| 433 | } |
| 434 | pRequestedName = pSelf->Server()->ClientName(ClientId: pResult->m_ClientId); |
| 435 | pSelf->Score()->ShowTimes(ClientId: pResult->m_ClientId, pName: pRequestedName, Offset); |
| 436 | } |
| 437 | else if(!pRequestedName) |
| 438 | { |
| 439 | pSelf->Score()->ShowTimes(ClientId: pResult->m_ClientId, Offset); |
| 440 | } |
| 441 | else |
| 442 | { |
| 443 | if(str_comp_nocase(a: pRequestedName, b: "me" ) == 0) |
| 444 | pRequestedName = pSelf->Server()->ClientName(ClientId: pResult->m_ClientId); |
| 445 | pSelf->Score()->ShowTimes(ClientId: pResult->m_ClientId, pName: pRequestedName, Offset); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | void CGameContext::ConDND(IConsole::IResult *pResult, void *pUserData) |
| 450 | { |
| 451 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 452 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 453 | return; |
| 454 | |
| 455 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 456 | if(!pPlayer) |
| 457 | return; |
| 458 | |
| 459 | pPlayer->m_DND = pResult->NumArguments() == 0 ? !pPlayer->m_DND : pResult->GetInteger(Index: 0); |
| 460 | log_info("chatresp" , pPlayer->m_DND ? "You will not receive any further global chat and server messages" : "You will receive global chat and server messages" ); |
| 461 | } |
| 462 | |
| 463 | void CGameContext::ConWhispers(IConsole::IResult *pResult, void *pUserData) |
| 464 | { |
| 465 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 466 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 467 | return; |
| 468 | |
| 469 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 470 | if(!pPlayer) |
| 471 | return; |
| 472 | |
| 473 | pPlayer->m_Whispers = pResult->NumArguments() == 0 ? !pPlayer->m_Whispers : pResult->GetInteger(Index: 0); |
| 474 | log_info("chatresp" , pPlayer->m_Whispers ? "You will receive whispers" : "You will not receive any further whispers" ); |
| 475 | } |
| 476 | |
| 477 | void CGameContext::ConMap(IConsole::IResult *pResult, void *pUserData) |
| 478 | { |
| 479 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 480 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 481 | return; |
| 482 | |
| 483 | if(g_Config.m_SvMapVote == 0) |
| 484 | { |
| 485 | log_info("chatresp" , "/map is disabled" ); |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | if(pResult->NumArguments() <= 0) |
| 490 | { |
| 491 | log_info("chatresp" , "Example: /map adr3 to call vote for Adrenaline 3. This means that the map name must start with 'a' and contain the characters 'd', 'r' and '3' in that order" ); |
| 492 | return; |
| 493 | } |
| 494 | |
| 495 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 496 | if(!pPlayer) |
| 497 | return; |
| 498 | |
| 499 | if(pSelf->RateLimitPlayerVote(ClientId: pResult->m_ClientId) || pSelf->RateLimitPlayerMapVote(ClientId: pResult->m_ClientId)) |
| 500 | return; |
| 501 | |
| 502 | pSelf->Score()->MapVote(ClientId: pResult->m_ClientId, pMapName: pResult->GetString(Index: 0)); |
| 503 | } |
| 504 | |
| 505 | void CGameContext::ConMapInfo(IConsole::IResult *pResult, void *pUserData) |
| 506 | { |
| 507 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 508 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 509 | return; |
| 510 | |
| 511 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 512 | if(!pPlayer) |
| 513 | return; |
| 514 | |
| 515 | // use cached map info for current map |
| 516 | const bool IsCurrentMap = pResult->NumArguments() == 0 || str_comp_nocase(a: pResult->GetString(Index: 0), b: pSelf->Map()->BaseName()) == 0; |
| 517 | if(IsCurrentMap && pSelf->m_aMapInfoMessage[0] != '\0') |
| 518 | { |
| 519 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: pSelf->m_aMapInfoMessage); |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | if(pResult->NumArguments() > 0) |
| 524 | pSelf->Score()->MapInfo(ClientId: pResult->m_ClientId, pMapName: pResult->GetString(Index: 0)); |
| 525 | else |
| 526 | pSelf->Score()->MapInfo(ClientId: pResult->m_ClientId, pMapName: pSelf->Map()->BaseName()); |
| 527 | } |
| 528 | |
| 529 | void CGameContext::ConTimeout(IConsole::IResult *pResult, void *pUserData) |
| 530 | { |
| 531 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 532 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 533 | return; |
| 534 | |
| 535 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 536 | if(!pPlayer) |
| 537 | return; |
| 538 | |
| 539 | const char *pTimeout = pResult->NumArguments() > 0 ? pResult->GetString(Index: 0) : pPlayer->m_aTimeoutCode; |
| 540 | |
| 541 | for(int i = 0; i < pSelf->Server()->MaxClients(); i++) |
| 542 | { |
| 543 | if(i == pResult->m_ClientId) |
| 544 | continue; |
| 545 | if(!pSelf->m_apPlayers[i]) |
| 546 | continue; |
| 547 | if(str_comp(a: pSelf->m_apPlayers[i]->m_aTimeoutCode, b: pTimeout)) |
| 548 | continue; |
| 549 | if(pSelf->Server()->SetTimedOut(ClientId: i, OrigId: pResult->m_ClientId)) |
| 550 | { |
| 551 | if(pSelf->m_apPlayers[i]->GetCharacter()) |
| 552 | pSelf->SendTuningParams(ClientId: i, Zone: pSelf->m_apPlayers[i]->GetCharacter()->m_TuneZone); |
| 553 | return; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | pSelf->Server()->SetTimeoutProtected(pResult->m_ClientId); |
| 558 | str_copy(dst&: pPlayer->m_aTimeoutCode, src: pResult->GetString(Index: 0)); |
| 559 | } |
| 560 | |
| 561 | void CGameContext::ConPractice(IConsole::IResult *pResult, void *pUserData) |
| 562 | { |
| 563 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 564 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 565 | return; |
| 566 | |
| 567 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 568 | if(!pPlayer) |
| 569 | return; |
| 570 | |
| 571 | if(pSelf->ProcessSpamProtection(ClientId: pResult->m_ClientId, RespectChatInitialDelay: false)) |
| 572 | return; |
| 573 | |
| 574 | if(!g_Config.m_SvPractice) |
| 575 | { |
| 576 | log_info("chatresp" , "Practice mode is disabled" ); |
| 577 | return; |
| 578 | } |
| 579 | |
| 580 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 581 | |
| 582 | int Team = Teams.m_Core.Team(ClientId: pResult->m_ClientId); |
| 583 | |
| 584 | if(!Teams.IsValidTeamNumber(Team) || (Team == TEAM_FLOCK && g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO)) |
| 585 | { |
| 586 | log_info("chatresp" , "Join a team to enable practice mode, which means you can use /r, but can't earn a rank." ); |
| 587 | return; |
| 588 | } |
| 589 | |
| 590 | if(Teams.TeamFlock(Team)) |
| 591 | { |
| 592 | log_info("chatresp" , "Practice mode can't be enabled in team 0 mode." ); |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | if(Teams.GetSaving(TeamId: Team)) |
| 597 | { |
| 598 | log_info("chatresp" , "Practice mode can't be enabled while team save or load is in progress" ); |
| 599 | return; |
| 600 | } |
| 601 | |
| 602 | if(Teams.IsPractice(Team)) |
| 603 | { |
| 604 | log_info("chatresp" , "Team is already in practice mode" ); |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | bool VotedForPractice = pResult->NumArguments() == 0 || pResult->GetInteger(Index: 0); |
| 609 | |
| 610 | if(VotedForPractice == pPlayer->m_VotedForPractice) |
| 611 | return; |
| 612 | |
| 613 | pPlayer->m_VotedForPractice = VotedForPractice; |
| 614 | |
| 615 | int NumCurrentVotes = 0; |
| 616 | int TeamSize = 0; |
| 617 | |
| 618 | for(int i = 0; i < MAX_CLIENTS; i++) |
| 619 | { |
| 620 | if(Teams.m_Core.Team(ClientId: i) == Team) |
| 621 | { |
| 622 | CPlayer *pPlayer2 = pSelf->m_apPlayers[i]; |
| 623 | if(pPlayer2 && pPlayer2->m_VotedForPractice) |
| 624 | NumCurrentVotes++; |
| 625 | TeamSize++; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | int NumRequiredVotes = TeamSize / 2 + 1; |
| 630 | |
| 631 | char aBuf[512]; |
| 632 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' voted to %s /practice mode for your team, which means you can use practice commands, but you can't earn a rank. Type /practice to vote (%d/%d required votes)" , pSelf->Server()->ClientName(ClientId: pResult->m_ClientId), VotedForPractice ? "enable" : "disable" , NumCurrentVotes, NumRequiredVotes); |
| 633 | pSelf->SendChatTeam(Team, pText: aBuf); |
| 634 | |
| 635 | if(NumCurrentVotes >= NumRequiredVotes) |
| 636 | { |
| 637 | Teams.SetPractice(Team, Enabled: true); |
| 638 | pSelf->SendChatTeam(Team, pText: "Practice mode enabled for your team, happy practicing!" ); |
| 639 | pSelf->SendChatTeam(Team, pText: "See /practicecmdlist for a list of all available practice commands. Most commonly used ones are /telecursor, /lasttp and /rescue" ); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | void CGameContext::ConUnPractice(IConsole::IResult *pResult, void *pUserData) |
| 644 | { |
| 645 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 646 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 647 | return; |
| 648 | |
| 649 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 650 | if(!pPlayer) |
| 651 | return; |
| 652 | |
| 653 | if(pSelf->ProcessSpamProtection(ClientId: pResult->m_ClientId, RespectChatInitialDelay: false)) |
| 654 | return; |
| 655 | |
| 656 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 657 | |
| 658 | int Team = Teams.m_Core.Team(ClientId: pResult->m_ClientId); |
| 659 | |
| 660 | if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK) |
| 661 | { |
| 662 | log_info("chatresp" , "Practice mode can't be disabled for team 0" ); |
| 663 | return; |
| 664 | } |
| 665 | |
| 666 | if(!Teams.IsPractice(Team)) |
| 667 | { |
| 668 | log_info("chatresp" , "Team isn't in practice mode" ); |
| 669 | return; |
| 670 | } |
| 671 | |
| 672 | if(Teams.GetSaving(TeamId: Team)) |
| 673 | { |
| 674 | log_info("chatresp" , "Practice mode can't be disabled while team save or load is in progress" ); |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | if(Teams.TeamSize(Team) > g_Config.m_SvMaxTeamSize && pSelf->m_pController->Teams().TeamLocked(Team)) |
| 679 | { |
| 680 | log_info("chatresp" , "Can't disable practice. This team exceeds the maximum allowed size of %d players for regular team" , g_Config.m_SvMaxTeamSize); |
| 681 | return; |
| 682 | } |
| 683 | |
| 684 | int RespawnTick = pSelf->Server()->Tick() - pSelf->Server()->TickSpeed() * 3 - 2; |
| 685 | for(int i = 0; i < MAX_CLIENTS; i++) |
| 686 | { |
| 687 | if(Teams.m_Core.Team(ClientId: i) == Team) |
| 688 | { |
| 689 | CPlayer *pPlayer2 = pSelf->m_apPlayers[i]; |
| 690 | if(pPlayer2) |
| 691 | { |
| 692 | if(pPlayer2->m_VotedForPractice) |
| 693 | pPlayer2->m_VotedForPractice = false; |
| 694 | |
| 695 | if(!g_Config.m_SvPauseable && pPlayer2->IsPaused() == -1 * CPlayer::PAUSE_SPEC) |
| 696 | pPlayer2->Pause(State: CPlayer::PAUSE_PAUSED, Force: true); |
| 697 | |
| 698 | pPlayer2->m_DieTick = RespawnTick; |
| 699 | pPlayer2->m_PreviousDieTick = RespawnTick; |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | // send before kill, in case team isn't locked |
| 705 | char aBuf[256]; |
| 706 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' disabled practice mode for your team" , pSelf->Server()->ClientName(ClientId: pResult->m_ClientId)); |
| 707 | pSelf->SendChatTeam(Team, pText: aBuf); |
| 708 | |
| 709 | Teams.KillCharacterOrTeam(ClientId: pResult->m_ClientId, Team); |
| 710 | Teams.SetPractice(Team, Enabled: false); |
| 711 | Teams.ResetSwitchers(Team); |
| 712 | pPlayer->Respawn(); // set spawn as strong hook |
| 713 | } |
| 714 | |
| 715 | void CGameContext::ConPracticeCmdList(IConsole::IResult *pResult, void *pUserData) |
| 716 | { |
| 717 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 718 | |
| 719 | char aPracticeCommands[256] = "Available practice commands: " ; |
| 720 | for(const IConsole::ICommandInfo *pCmd = pSelf->Console()->FirstCommandInfo(ClientId: pResult->m_ClientId, FlagMask: CMDFLAG_PRACTICE); |
| 721 | pCmd; pCmd = pSelf->Console()->NextCommandInfo(pInfo: pCmd, ClientId: pResult->m_ClientId, FlagMask: CMDFLAG_PRACTICE)) |
| 722 | { |
| 723 | char aCommand[64]; |
| 724 | |
| 725 | str_format(buffer: aCommand, buffer_size: sizeof(aCommand), format: "/%s%s" , pCmd->Name(), pSelf->Console()->NextCommandInfo(pInfo: pCmd, ClientId: pResult->m_ClientId, FlagMask: CMDFLAG_PRACTICE) ? ", " : "" ); |
| 726 | |
| 727 | if(str_length(str: aCommand) + str_length(str: aPracticeCommands) > 255) |
| 728 | { |
| 729 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: aPracticeCommands); |
| 730 | aPracticeCommands[0] = '\0'; |
| 731 | } |
| 732 | str_append(dst&: aPracticeCommands, src: aCommand); |
| 733 | } |
| 734 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: aPracticeCommands); |
| 735 | } |
| 736 | |
| 737 | void CGameContext::ConSwap(IConsole::IResult *pResult, void *pUserData) |
| 738 | { |
| 739 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 740 | const char *pName = pResult->GetString(Index: 0); |
| 741 | |
| 742 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 743 | return; |
| 744 | |
| 745 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 746 | if(!pPlayer) |
| 747 | return; |
| 748 | |
| 749 | if(!g_Config.m_SvSwap) |
| 750 | { |
| 751 | log_info("chatresp" , "Swap is disabled on this server." ); |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) |
| 756 | { |
| 757 | log_info("chatresp" , "Swap is not available on forced solo servers." ); |
| 758 | return; |
| 759 | } |
| 760 | |
| 761 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 762 | |
| 763 | int Team = Teams.m_Core.Team(ClientId: pResult->m_ClientId); |
| 764 | |
| 765 | if(Team == TEAM_SUPER) |
| 766 | { |
| 767 | log_info( |
| 768 | "chatresp" , |
| 769 | "Turn off super to use swap feature, which means you can swap positions with each other." ); |
| 770 | return; |
| 771 | } |
| 772 | |
| 773 | int TargetClientId = -1; |
| 774 | if(pResult->NumArguments() == 1) |
| 775 | { |
| 776 | TargetClientId = pSelf->FindClientIdByName(pName).value_or(u: -1); |
| 777 | } |
| 778 | else |
| 779 | { |
| 780 | int TeamSize = 1; |
| 781 | for(int i = 0; i < MAX_CLIENTS; i++) |
| 782 | { |
| 783 | if(pSelf->m_apPlayers[i] && Teams.m_Core.Team(ClientId: i) == Team && i != pResult->m_ClientId) |
| 784 | { |
| 785 | TargetClientId = i; |
| 786 | TeamSize++; |
| 787 | } |
| 788 | } |
| 789 | if(TeamSize != 2) |
| 790 | TargetClientId = -1; |
| 791 | } |
| 792 | |
| 793 | if(TargetClientId < 0) |
| 794 | { |
| 795 | log_info("chatresp" , "Player not found" ); |
| 796 | return; |
| 797 | } |
| 798 | |
| 799 | if(TargetClientId == pResult->m_ClientId) |
| 800 | { |
| 801 | log_info("chatresp" , "Can't swap with yourself" ); |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | int TargetTeam = Teams.m_Core.Team(ClientId: TargetClientId); |
| 806 | if(TargetTeam != Team) |
| 807 | { |
| 808 | log_info("chatresp" , "Player is on a different team" ); |
| 809 | return; |
| 810 | } |
| 811 | |
| 812 | CPlayer *pSwapPlayer = pSelf->m_apPlayers[TargetClientId]; |
| 813 | if(Team == TEAM_FLOCK || Teams.TeamFlock(Team)) |
| 814 | { |
| 815 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 816 | CCharacter *pSwapChr = pSwapPlayer->GetCharacter(); |
| 817 | if(!pChr || !pSwapChr || pChr->m_DDRaceState != ERaceState::STARTED || pSwapChr->m_DDRaceState != ERaceState::STARTED) |
| 818 | { |
| 819 | log_info("chatresp" , "You and other player need to have started the map" ); |
| 820 | return; |
| 821 | } |
| 822 | } |
| 823 | else if(!Teams.IsStarted(Team) && !Teams.TeamFlock(Team)) |
| 824 | { |
| 825 | log_info("chatresp" , "Need to have started the map to swap with a player." ); |
| 826 | return; |
| 827 | } |
| 828 | if(pSelf->m_World.m_Core.m_apCharacters[pResult->m_ClientId] == nullptr || pSelf->m_World.m_Core.m_apCharacters[TargetClientId] == nullptr) |
| 829 | { |
| 830 | log_info("chatresp" , "You and the other player must not be paused." ); |
| 831 | return; |
| 832 | } |
| 833 | |
| 834 | bool SwapPending = pSwapPlayer->m_SwapTargetsClientId != pResult->m_ClientId; |
| 835 | if(SwapPending) |
| 836 | { |
| 837 | if(pSelf->ProcessSpamProtection(ClientId: pResult->m_ClientId)) |
| 838 | return; |
| 839 | |
| 840 | Teams.RequestTeamSwap(pPlayer, pTargetPlayer: pSwapPlayer, Team); |
| 841 | return; |
| 842 | } |
| 843 | |
| 844 | Teams.SwapTeamCharacters(pPrimaryPlayer: pPlayer, pTargetPlayer: pSwapPlayer, Team); |
| 845 | } |
| 846 | |
| 847 | void CGameContext::ConCancelSwap(IConsole::IResult *pResult, void *pUserData) |
| 848 | { |
| 849 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 850 | |
| 851 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 852 | return; |
| 853 | |
| 854 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 855 | if(!pPlayer) |
| 856 | return; |
| 857 | |
| 858 | if(!g_Config.m_SvSwap) |
| 859 | { |
| 860 | log_info("chatresp" , "Swap is disabled on this server." ); |
| 861 | return; |
| 862 | } |
| 863 | |
| 864 | if(g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) |
| 865 | { |
| 866 | log_info("chatresp" , "Swap is not available on forced solo servers." ); |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 871 | |
| 872 | int Team = Teams.m_Core.Team(ClientId: pResult->m_ClientId); |
| 873 | |
| 874 | bool SwapPending = pPlayer->m_SwapTargetsClientId != -1 && !pSelf->Server()->ClientSlotEmpty(ClientId: pPlayer->m_SwapTargetsClientId); |
| 875 | |
| 876 | if(!SwapPending) |
| 877 | { |
| 878 | log_info("chatresp" , "You do not have a pending swap request." ); |
| 879 | return; |
| 880 | } |
| 881 | |
| 882 | Teams.CancelTeamSwap(pPlayer, Team); |
| 883 | } |
| 884 | |
| 885 | void CGameContext::ConSave(IConsole::IResult *pResult, void *pUserData) |
| 886 | { |
| 887 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 888 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 889 | return; |
| 890 | |
| 891 | if(!g_Config.m_SvSaveGames) |
| 892 | { |
| 893 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: "Save-function is disabled on this server" ); |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | const char *pCode = "" ; |
| 898 | if(pResult->NumArguments() > 0) |
| 899 | pCode = pResult->GetString(Index: 0); |
| 900 | |
| 901 | pSelf->Score()->SaveTeam(ClientId: pResult->m_ClientId, pCode, pServer: g_Config.m_SvSqlServerName); |
| 902 | } |
| 903 | |
| 904 | void CGameContext::ConLoad(IConsole::IResult *pResult, void *pUserData) |
| 905 | { |
| 906 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 907 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 908 | return; |
| 909 | |
| 910 | if(!g_Config.m_SvSaveGames) |
| 911 | { |
| 912 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: "Save-function is disabled on this server" ); |
| 913 | return; |
| 914 | } |
| 915 | |
| 916 | if(pResult->NumArguments() > 0) |
| 917 | pSelf->Score()->LoadTeam(pCode: pResult->GetString(Index: 0), ClientId: pResult->m_ClientId); |
| 918 | else |
| 919 | pSelf->Score()->GetSaves(ClientId: pResult->m_ClientId); |
| 920 | } |
| 921 | |
| 922 | void CGameContext::ConTeamRank(IConsole::IResult *pResult, void *pUserData) |
| 923 | { |
| 924 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 925 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 926 | return; |
| 927 | |
| 928 | if(pResult->NumArguments() > 0) |
| 929 | { |
| 930 | if(!g_Config.m_SvHideScore) |
| 931 | pSelf->Score()->ShowTeamRank(ClientId: pResult->m_ClientId, pName: pResult->GetString(Index: 0)); |
| 932 | else |
| 933 | log_info("chatresp" , "Showing the team rank of other players is not allowed on this server." ); |
| 934 | } |
| 935 | else |
| 936 | pSelf->Score()->ShowTeamRank(ClientId: pResult->m_ClientId, |
| 937 | pName: pSelf->Server()->ClientName(ClientId: pResult->m_ClientId)); |
| 938 | } |
| 939 | |
| 940 | void CGameContext::ConRank(IConsole::IResult *pResult, void *pUserData) |
| 941 | { |
| 942 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 943 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 944 | return; |
| 945 | |
| 946 | if(pResult->NumArguments() > 0) |
| 947 | { |
| 948 | if(!g_Config.m_SvHideScore) |
| 949 | pSelf->Score()->ShowRank(ClientId: pResult->m_ClientId, pName: pResult->GetString(Index: 0)); |
| 950 | else |
| 951 | log_info("chatresp" , "Showing the rank of other players is not allowed on this server." ); |
| 952 | } |
| 953 | else |
| 954 | pSelf->Score()->ShowRank(ClientId: pResult->m_ClientId, |
| 955 | pName: pSelf->Server()->ClientName(ClientId: pResult->m_ClientId)); |
| 956 | } |
| 957 | |
| 958 | void CGameContext::ConLock(IConsole::IResult *pResult, void *pUserData) |
| 959 | { |
| 960 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 961 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 962 | return; |
| 963 | |
| 964 | if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) |
| 965 | { |
| 966 | log_info("chatresp" , "Teams are disabled" ); |
| 967 | return; |
| 968 | } |
| 969 | |
| 970 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 971 | |
| 972 | bool Lock = pSelf->m_pController->Teams().TeamLocked(Team); |
| 973 | |
| 974 | if(pResult->NumArguments() > 0) |
| 975 | Lock = !pResult->GetInteger(Index: 0); |
| 976 | |
| 977 | if(Team == TEAM_FLOCK || !pSelf->m_pController->Teams().IsValidTeamNumber(Team)) |
| 978 | { |
| 979 | log_info("chatresp" , "This team can't be locked" ); |
| 980 | return; |
| 981 | } |
| 982 | |
| 983 | if(pSelf->ProcessSpamProtection(ClientId: pResult->m_ClientId, RespectChatInitialDelay: false)) |
| 984 | return; |
| 985 | |
| 986 | char aBuf[512]; |
| 987 | if(Lock) |
| 988 | { |
| 989 | pSelf->UnlockTeam(ClientId: pResult->m_ClientId, Team); |
| 990 | } |
| 991 | else |
| 992 | { |
| 993 | pSelf->m_pController->Teams().SetTeamLock(Team, Lock: true); |
| 994 | |
| 995 | if(pSelf->m_pController->Teams().TeamFlock(Team)) |
| 996 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' locked your team." , pSelf->Server()->ClientName(ClientId: pResult->m_ClientId)); |
| 997 | else |
| 998 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' locked your team. After the race starts, killing will kill everyone in your team." , pSelf->Server()->ClientName(ClientId: pResult->m_ClientId)); |
| 999 | pSelf->SendChatTeam(Team, pText: aBuf); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | void CGameContext::ConUnlock(IConsole::IResult *pResult, void *pUserData) |
| 1004 | { |
| 1005 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1006 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1007 | return; |
| 1008 | |
| 1009 | if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) |
| 1010 | { |
| 1011 | log_info("chatresp" , "Teams are disabled" ); |
| 1012 | return; |
| 1013 | } |
| 1014 | |
| 1015 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1016 | |
| 1017 | if(Team == TEAM_FLOCK || !pSelf->m_pController->Teams().IsValidTeamNumber(Team)) |
| 1018 | return; |
| 1019 | |
| 1020 | if(pSelf->ProcessSpamProtection(ClientId: pResult->m_ClientId, RespectChatInitialDelay: false)) |
| 1021 | return; |
| 1022 | |
| 1023 | pSelf->UnlockTeam(ClientId: pResult->m_ClientId, Team); |
| 1024 | } |
| 1025 | |
| 1026 | void CGameContext::UnlockTeam(int ClientId, int Team) const |
| 1027 | { |
| 1028 | m_pController->Teams().SetTeamLock(Team, Lock: false); |
| 1029 | |
| 1030 | char aBuf[512]; |
| 1031 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' unlocked your team." , Server()->ClientName(ClientId)); |
| 1032 | SendChatTeam(Team, pText: aBuf); |
| 1033 | } |
| 1034 | |
| 1035 | void CGameContext::AttemptJoinTeam(int ClientId, int Team) |
| 1036 | { |
| 1037 | CPlayer *pPlayer = m_apPlayers[ClientId]; |
| 1038 | if(!pPlayer) |
| 1039 | return; |
| 1040 | |
| 1041 | if(IsRunningKickOrSpecVote(ClientId)) |
| 1042 | { |
| 1043 | log_info("chatresp" , "You are running a vote, please try again after the vote is done!" ); |
| 1044 | return; |
| 1045 | } |
| 1046 | else if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) |
| 1047 | { |
| 1048 | log_info("chatresp" , "Teams are disabled" ); |
| 1049 | return; |
| 1050 | } |
| 1051 | else if(g_Config.m_SvTeam == SV_TEAM_MANDATORY && Team == 0 && pPlayer->GetCharacter() && pPlayer->GetCharacter()->m_LastStartWarning < Server()->Tick() - 3 * Server()->TickSpeed()) |
| 1052 | { |
| 1053 | log_info("chatresp" , "You must join a team and play with somebody or else you can't play" ); |
| 1054 | pPlayer->GetCharacter()->m_LastStartWarning = Server()->Tick(); |
| 1055 | } |
| 1056 | |
| 1057 | if(!m_pController->Teams().IsValidTeamNumber(Team)) |
| 1058 | { |
| 1059 | auto EmptyTeam = m_pController->Teams().GetFirstEmptyTeam(); |
| 1060 | if(!EmptyTeam.has_value()) |
| 1061 | { |
| 1062 | log_info("chatresp" , "No empty team left." ); |
| 1063 | return; |
| 1064 | } |
| 1065 | Team = EmptyTeam.value(); |
| 1066 | } |
| 1067 | |
| 1068 | char aError[512]; |
| 1069 | if(pPlayer->m_LastDDRaceTeamChange.has_value() && pPlayer->m_LastDDRaceTeamChange.value() + (int64_t)Server()->TickSpeed() * g_Config.m_SvTeamChangeDelay > Server()->Tick()) |
| 1070 | { |
| 1071 | log_info("chatresp" , "You can't change teams that fast!" ); |
| 1072 | } |
| 1073 | else if(Team != TEAM_FLOCK && m_pController->Teams().TeamLocked(Team) && !m_pController->Teams().IsInvited(Team, ClientId)) |
| 1074 | { |
| 1075 | log_info("chatresp" , g_Config.m_SvInvite ? |
| 1076 | "This team is locked using /lock. Only members of the team can unlock it using /lock." : |
| 1077 | "This team is locked using /lock. Only members of the team can invite you or unlock it using /lock." ); |
| 1078 | } |
| 1079 | else if(Team != TEAM_FLOCK && m_pController->Teams().TeamSize(Team) >= g_Config.m_SvMaxTeamSize && !m_pController->Teams().TeamFlock(Team) && !m_pController->Teams().IsPractice(Team)) |
| 1080 | { |
| 1081 | char aBuf[512]; |
| 1082 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "This team already has the maximum allowed size of %d players" , g_Config.m_SvMaxTeamSize); |
| 1083 | log_info("chatresp" , "%s" , aBuf); |
| 1084 | } |
| 1085 | else if(!m_pController->Teams().SetCharacterTeam(ClientId: pPlayer->GetCid(), Team, pError: aError, ErrorSize: sizeof(aError))) |
| 1086 | { |
| 1087 | log_info("chatresp" , "%s" , aError); |
| 1088 | } |
| 1089 | else |
| 1090 | { |
| 1091 | if(PracticeByDefault()) |
| 1092 | { |
| 1093 | // joined an empty team |
| 1094 | if(m_pController->Teams().TeamSize(Team) == 1) |
| 1095 | m_pController->Teams().SetPractice(Team, Enabled: true); |
| 1096 | } |
| 1097 | |
| 1098 | char aBuf[512]; |
| 1099 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' joined team %d" , |
| 1100 | Server()->ClientName(ClientId: pPlayer->GetCid()), |
| 1101 | Team); |
| 1102 | SendChat(ClientId: -1, Team: TEAM_ALL, pText: aBuf); |
| 1103 | pPlayer->m_LastDDRaceTeamChange = Server()->Tick(); |
| 1104 | |
| 1105 | if(m_pController->Teams().IsPractice(Team)) |
| 1106 | SendChatTarget(To: pPlayer->GetCid(), pText: "Practice mode enabled for your team, happy practicing!" ); |
| 1107 | |
| 1108 | if(m_pController->Teams().TeamFlock(Team)) |
| 1109 | SendChatTarget(To: pPlayer->GetCid(), pText: "Team 0 mode enabled for your team. This will make your team behave like team 0." ); |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | void CGameContext::ConInvite(IConsole::IResult *pResult, void *pUserData) |
| 1114 | { |
| 1115 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1116 | auto *pController = pSelf->m_pController; |
| 1117 | const char *pName = pResult->GetString(Index: 0); |
| 1118 | |
| 1119 | if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) |
| 1120 | { |
| 1121 | log_info("chatresp" , "Teams are disabled" ); |
| 1122 | return; |
| 1123 | } |
| 1124 | |
| 1125 | if(!g_Config.m_SvInvite) |
| 1126 | { |
| 1127 | log_info("chatresp" , "Invites are disabled" ); |
| 1128 | return; |
| 1129 | } |
| 1130 | |
| 1131 | int Team = pController->Teams().m_Core.Team(ClientId: pResult->m_ClientId); |
| 1132 | if(Team != TEAM_FLOCK && pController->Teams().IsValidTeamNumber(Team)) |
| 1133 | { |
| 1134 | int Target = pSelf->FindClientIdByName(pName).value_or(u: -1); |
| 1135 | if(Target == -1) |
| 1136 | { |
| 1137 | log_info("chatresp" , "Player not found" ); |
| 1138 | return; |
| 1139 | } |
| 1140 | |
| 1141 | if(pController->Teams().IsInvited(Team, ClientId: Target)) |
| 1142 | { |
| 1143 | log_info("chatresp" , "Player already invited" ); |
| 1144 | return; |
| 1145 | } |
| 1146 | |
| 1147 | if(pSelf->m_apPlayers[pResult->m_ClientId] && pSelf->m_apPlayers[pResult->m_ClientId]->m_LastInvited + g_Config.m_SvInviteFrequency * pSelf->Server()->TickSpeed() > pSelf->Server()->Tick()) |
| 1148 | { |
| 1149 | log_info("chatresp" , "Can't invite this quickly" ); |
| 1150 | return; |
| 1151 | } |
| 1152 | |
| 1153 | pController->Teams().SetClientInvited(Team, ClientId: Target, Invited: true); |
| 1154 | pSelf->m_apPlayers[pResult->m_ClientId]->m_LastInvited = pSelf->Server()->Tick(); |
| 1155 | |
| 1156 | char aBuf[512]; |
| 1157 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' invited you to team %d. Use /team %d to join." , pSelf->Server()->ClientName(ClientId: pResult->m_ClientId), Team, Team); |
| 1158 | pSelf->SendChatTarget(To: Target, pText: aBuf); |
| 1159 | |
| 1160 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' invited '%s' to your team." , pSelf->Server()->ClientName(ClientId: pResult->m_ClientId), pSelf->Server()->ClientName(ClientId: Target)); |
| 1161 | pSelf->SendChatTeam(Team, pText: aBuf); |
| 1162 | } |
| 1163 | else |
| 1164 | log_info("chatresp" , "Can't invite players to this team" ); |
| 1165 | } |
| 1166 | |
| 1167 | void CGameContext::ConTeam0Mode(IConsole::IResult *pResult, void *pUserData) |
| 1168 | { |
| 1169 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1170 | auto *pController = pSelf->m_pController; |
| 1171 | |
| 1172 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1173 | return; |
| 1174 | |
| 1175 | if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO || g_Config.m_SvTeam == SV_TEAM_MANDATORY) |
| 1176 | { |
| 1177 | log_info("chatresp" , "Team mode change disabled" ); |
| 1178 | return; |
| 1179 | } |
| 1180 | |
| 1181 | if(!g_Config.m_SvTeam0Mode) |
| 1182 | { |
| 1183 | log_info("chatresp" , "Team mode change is disabled on this server." ); |
| 1184 | return; |
| 1185 | } |
| 1186 | |
| 1187 | int Team = pController->Teams().m_Core.Team(ClientId: pResult->m_ClientId); |
| 1188 | bool Mode = pController->Teams().TeamFlock(Team); |
| 1189 | |
| 1190 | if(Team == TEAM_FLOCK || !pController->Teams().IsValidTeamNumber(Team)) |
| 1191 | { |
| 1192 | log_info("chatresp" , "This team can't have the mode changed" ); |
| 1193 | return; |
| 1194 | } |
| 1195 | |
| 1196 | if(pController->Teams().GetTeamState(Team) != ETeamState::OPEN || pController->Teams().GetSaving(TeamId: Team)) |
| 1197 | { |
| 1198 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: "Team mode can't be changed while racing" ); |
| 1199 | return; |
| 1200 | } |
| 1201 | |
| 1202 | if(pResult->NumArguments() > 0) |
| 1203 | Mode = !pResult->GetInteger(Index: 0); |
| 1204 | |
| 1205 | if(pSelf->ProcessSpamProtection(ClientId: pResult->m_ClientId, RespectChatInitialDelay: false)) |
| 1206 | return; |
| 1207 | |
| 1208 | char aBuf[512]; |
| 1209 | if(Mode) |
| 1210 | { |
| 1211 | if(pController->Teams().TeamSize(Team) > g_Config.m_SvMaxTeamSize) |
| 1212 | { |
| 1213 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "Can't disable team 0 mode. This team exceeds the maximum allowed size of %d players for regular team" , g_Config.m_SvMaxTeamSize); |
| 1214 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: aBuf); |
| 1215 | } |
| 1216 | else |
| 1217 | { |
| 1218 | pController->Teams().SetTeamFlock(Team, Mode: false); |
| 1219 | |
| 1220 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' disabled team 0 mode." , pSelf->Server()->ClientName(ClientId: pResult->m_ClientId)); |
| 1221 | pSelf->SendChatTeam(Team, pText: aBuf); |
| 1222 | } |
| 1223 | } |
| 1224 | else |
| 1225 | { |
| 1226 | if(pController->Teams().IsPractice(Team)) |
| 1227 | { |
| 1228 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: "Can't enable team 0 mode with practice mode on." ); |
| 1229 | } |
| 1230 | else |
| 1231 | { |
| 1232 | pController->Teams().SetTeamFlock(Team, Mode: true); |
| 1233 | |
| 1234 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "'%s' enabled team 0 mode. This will make your team behave like team 0." , pSelf->Server()->ClientName(ClientId: pResult->m_ClientId)); |
| 1235 | pSelf->SendChatTeam(Team, pText: aBuf); |
| 1236 | } |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | void CGameContext::ConTeam(IConsole::IResult *pResult, void *pUserData) |
| 1241 | { |
| 1242 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1243 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1244 | return; |
| 1245 | |
| 1246 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1247 | if(!pPlayer) |
| 1248 | return; |
| 1249 | |
| 1250 | if(pResult->NumArguments() > 0) |
| 1251 | { |
| 1252 | pSelf->AttemptJoinTeam(ClientId: pResult->m_ClientId, Team: pResult->GetInteger(Index: 0)); |
| 1253 | return; |
| 1254 | } |
| 1255 | |
| 1256 | char aBuf[512]; |
| 1257 | if(!pPlayer->IsPlaying()) |
| 1258 | { |
| 1259 | log_info("chatresp" , "You can't check your team while you are dead/a spectator." ); |
| 1260 | } |
| 1261 | else |
| 1262 | { |
| 1263 | int TeamSize = 0; |
| 1264 | const int PlayerTeam = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1265 | |
| 1266 | // Count players in team |
| 1267 | for(int ClientId = 0; ClientId < MAX_CLIENTS; ClientId++) |
| 1268 | { |
| 1269 | const CPlayer *pOtherPlayer = pSelf->m_apPlayers[ClientId]; |
| 1270 | if(!pOtherPlayer || !pOtherPlayer->IsPlaying()) |
| 1271 | continue; |
| 1272 | |
| 1273 | if(pSelf->GetDDRaceTeam(ClientId) == PlayerTeam) |
| 1274 | TeamSize++; |
| 1275 | } |
| 1276 | |
| 1277 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "You are in team %d having %d %s" , PlayerTeam, TeamSize, TeamSize > 1 ? "players" : "player" ); |
| 1278 | log_info("chatresp" , "%s" , aBuf); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | void CGameContext::ConJoin(IConsole::IResult *pResult, void *pUserData) |
| 1283 | { |
| 1284 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1285 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1286 | return; |
| 1287 | |
| 1288 | const char *pName = pResult->GetString(Index: 0); |
| 1289 | int Target = pSelf->FindClientIdByName(pName).value_or(u: -1); |
| 1290 | if(Target == -1) |
| 1291 | { |
| 1292 | log_info("chatresp" , "Player not found" ); |
| 1293 | return; |
| 1294 | } |
| 1295 | |
| 1296 | int Team = pSelf->GetDDRaceTeam(ClientId: Target); |
| 1297 | if(pSelf->ProcessSpamProtection(ClientId: pResult->m_ClientId, RespectChatInitialDelay: false)) |
| 1298 | return; |
| 1299 | |
| 1300 | pSelf->AttemptJoinTeam(ClientId: pResult->m_ClientId, Team); |
| 1301 | } |
| 1302 | |
| 1303 | void CGameContext::ConConverse(IConsole::IResult *pResult, void *pUserData) |
| 1304 | { |
| 1305 | // This will never be called |
| 1306 | } |
| 1307 | |
| 1308 | void CGameContext::ConWhisper(IConsole::IResult *pResult, void *pUserData) |
| 1309 | { |
| 1310 | // This will never be called |
| 1311 | } |
| 1312 | |
| 1313 | void CGameContext::ConSetEyeEmote(IConsole::IResult *pResult, |
| 1314 | void *pUserData) |
| 1315 | { |
| 1316 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1317 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1318 | return; |
| 1319 | |
| 1320 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1321 | if(!pPlayer) |
| 1322 | return; |
| 1323 | if(pResult->NumArguments() == 0) |
| 1324 | { |
| 1325 | log_info("chatresp" , pPlayer->m_EyeEmoteEnabled ? |
| 1326 | "You can now use the preset eye emotes." : |
| 1327 | "You don't have any eye emotes, remember to bind some." ); |
| 1328 | return; |
| 1329 | } |
| 1330 | else if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "on" ) == 0) |
| 1331 | pPlayer->m_EyeEmoteEnabled = true; |
| 1332 | else if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "off" ) == 0) |
| 1333 | pPlayer->m_EyeEmoteEnabled = false; |
| 1334 | else if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "toggle" ) == 0) |
| 1335 | pPlayer->m_EyeEmoteEnabled = !pPlayer->m_EyeEmoteEnabled; |
| 1336 | log_info("chatresp" , pPlayer->m_EyeEmoteEnabled ? |
| 1337 | "You can now use the preset eye emotes." : |
| 1338 | "You don't have any eye emotes, remember to bind some." ); |
| 1339 | } |
| 1340 | |
| 1341 | void CGameContext::ConEyeEmote(IConsole::IResult *pResult, void *pUserData) |
| 1342 | { |
| 1343 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1344 | if(g_Config.m_SvEmotionalTees == -1) |
| 1345 | { |
| 1346 | log_info("chatresp" , "Emotes are disabled." ); |
| 1347 | return; |
| 1348 | } |
| 1349 | |
| 1350 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1351 | return; |
| 1352 | |
| 1353 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1354 | if(!pPlayer) |
| 1355 | return; |
| 1356 | |
| 1357 | if(pResult->NumArguments() == 0) |
| 1358 | { |
| 1359 | log_info("chatresp" , "Emote commands are: /emote surprise /emote blink /emote close /emote angry /emote happy /emote pain /emote normal" ); |
| 1360 | log_info("chatresp" , "Example: /emote surprise 10 for 10 seconds or /emote surprise (default 1 second)" ); |
| 1361 | return; |
| 1362 | } |
| 1363 | |
| 1364 | if(!pPlayer->CanOverrideDefaultEmote()) |
| 1365 | return; |
| 1366 | |
| 1367 | int EmoteType = 0; |
| 1368 | if(!str_comp_nocase(a: pResult->GetString(Index: 0), b: "angry" )) |
| 1369 | EmoteType = EMOTE_ANGRY; |
| 1370 | else if(!str_comp_nocase(a: pResult->GetString(Index: 0), b: "blink" )) |
| 1371 | EmoteType = EMOTE_BLINK; |
| 1372 | else if(!str_comp_nocase(a: pResult->GetString(Index: 0), b: "close" )) |
| 1373 | EmoteType = EMOTE_BLINK; |
| 1374 | else if(!str_comp_nocase(a: pResult->GetString(Index: 0), b: "happy" )) |
| 1375 | EmoteType = EMOTE_HAPPY; |
| 1376 | else if(!str_comp_nocase(a: pResult->GetString(Index: 0), b: "pain" )) |
| 1377 | EmoteType = EMOTE_PAIN; |
| 1378 | else if(!str_comp_nocase(a: pResult->GetString(Index: 0), b: "surprise" )) |
| 1379 | EmoteType = EMOTE_SURPRISE; |
| 1380 | else if(!str_comp_nocase(a: pResult->GetString(Index: 0), b: "normal" )) |
| 1381 | EmoteType = EMOTE_NORMAL; |
| 1382 | else |
| 1383 | { |
| 1384 | log_info("chatresp" , "Unknown emote... Say /emote" ); |
| 1385 | return; |
| 1386 | } |
| 1387 | |
| 1388 | int Duration = 1; |
| 1389 | if(pResult->NumArguments() > 1) |
| 1390 | Duration = std::clamp(val: pResult->GetInteger(Index: 1), lo: 1, hi: 86400); |
| 1391 | |
| 1392 | pPlayer->OverrideDefaultEmote(Emote: EmoteType, Tick: pSelf->Server()->Tick() + Duration * pSelf->Server()->TickSpeed()); |
| 1393 | } |
| 1394 | |
| 1395 | void CGameContext::ConNinjaJetpack(IConsole::IResult *pResult, void *pUserData) |
| 1396 | { |
| 1397 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1398 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1399 | return; |
| 1400 | |
| 1401 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1402 | if(!pPlayer) |
| 1403 | return; |
| 1404 | if(pResult->NumArguments()) |
| 1405 | pPlayer->m_NinjaJetpack = pResult->GetInteger(Index: 0); |
| 1406 | else |
| 1407 | pPlayer->m_NinjaJetpack = !pPlayer->m_NinjaJetpack; |
| 1408 | } |
| 1409 | |
| 1410 | void CGameContext::ConShowOthers(IConsole::IResult *pResult, void *pUserData) |
| 1411 | { |
| 1412 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1413 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1414 | return; |
| 1415 | |
| 1416 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1417 | if(!pPlayer) |
| 1418 | return; |
| 1419 | if(g_Config.m_SvShowOthers) |
| 1420 | { |
| 1421 | if(pResult->NumArguments()) |
| 1422 | pPlayer->m_ShowOthers = pResult->GetInteger(Index: 0); |
| 1423 | else |
| 1424 | pPlayer->m_ShowOthers = !pPlayer->m_ShowOthers; |
| 1425 | } |
| 1426 | else |
| 1427 | log_info("chatresp" , "Showing players from other teams is disabled" ); |
| 1428 | } |
| 1429 | |
| 1430 | void CGameContext::ConShowAll(IConsole::IResult *pResult, void *pUserData) |
| 1431 | { |
| 1432 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1433 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1434 | return; |
| 1435 | |
| 1436 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1437 | if(!pPlayer) |
| 1438 | return; |
| 1439 | |
| 1440 | if(pResult->NumArguments()) |
| 1441 | { |
| 1442 | if(pPlayer->m_ShowAll == (bool)pResult->GetInteger(Index: 0)) |
| 1443 | return; |
| 1444 | |
| 1445 | pPlayer->m_ShowAll = pResult->GetInteger(Index: 0); |
| 1446 | } |
| 1447 | else |
| 1448 | { |
| 1449 | pPlayer->m_ShowAll = !pPlayer->m_ShowAll; |
| 1450 | } |
| 1451 | |
| 1452 | if(pPlayer->m_ShowAll) |
| 1453 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: "You will now see all tees on this server, no matter the distance" ); |
| 1454 | else |
| 1455 | pSelf->SendChatTarget(To: pResult->m_ClientId, pText: "You will no longer see all tees on this server" ); |
| 1456 | } |
| 1457 | |
| 1458 | void CGameContext::ConSpecTeam(IConsole::IResult *pResult, void *pUserData) |
| 1459 | { |
| 1460 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1461 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1462 | return; |
| 1463 | |
| 1464 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1465 | if(!pPlayer) |
| 1466 | return; |
| 1467 | |
| 1468 | if(pResult->NumArguments()) |
| 1469 | pPlayer->m_SpecTeam = pResult->GetInteger(Index: 0); |
| 1470 | else |
| 1471 | pPlayer->m_SpecTeam = !pPlayer->m_SpecTeam; |
| 1472 | } |
| 1473 | |
| 1474 | void CGameContext::ConSayTime(IConsole::IResult *pResult, void *pUserData) |
| 1475 | { |
| 1476 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1477 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1478 | return; |
| 1479 | |
| 1480 | int ClientId; |
| 1481 | char aBufName[MAX_NAME_LENGTH]; |
| 1482 | |
| 1483 | if(pResult->NumArguments() > 0) |
| 1484 | { |
| 1485 | ClientId = pSelf->FindClientIdByName(pName: pResult->GetString(Index: 0)).value_or(u: -1); |
| 1486 | if(ClientId == -1) |
| 1487 | return; |
| 1488 | |
| 1489 | str_format(buffer: aBufName, buffer_size: sizeof(aBufName), format: "%s's" , pSelf->Server()->ClientName(ClientId)); |
| 1490 | } |
| 1491 | else |
| 1492 | { |
| 1493 | str_copy(dst&: aBufName, src: "Your" ); |
| 1494 | ClientId = pResult->m_ClientId; |
| 1495 | } |
| 1496 | |
| 1497 | CPlayer *pPlayer = pSelf->m_apPlayers[ClientId]; |
| 1498 | if(!pPlayer) |
| 1499 | return; |
| 1500 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 1501 | if(!pChr) |
| 1502 | return; |
| 1503 | if(pChr->m_DDRaceState != ERaceState::STARTED) |
| 1504 | return; |
| 1505 | |
| 1506 | char aBufTime[32]; |
| 1507 | char aBuf[64]; |
| 1508 | int64_t Time = (int64_t)100 * (float)(pSelf->Server()->Tick() - pChr->m_StartTime) / ((float)pSelf->Server()->TickSpeed()); |
| 1509 | str_time(centisecs: Time, format: ETimeFormat::HOURS, buffer: aBufTime, buffer_size: sizeof(aBufTime)); |
| 1510 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s current race time is %s" , aBufName, aBufTime); |
| 1511 | log_info("chatresp" , "%s" , aBuf); |
| 1512 | } |
| 1513 | |
| 1514 | void CGameContext::ConSayTimeAll(IConsole::IResult *pResult, void *pUserData) |
| 1515 | { |
| 1516 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1517 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1518 | return; |
| 1519 | |
| 1520 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1521 | if(!pPlayer) |
| 1522 | return; |
| 1523 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 1524 | if(!pChr) |
| 1525 | return; |
| 1526 | if(pChr->m_DDRaceState != ERaceState::STARTED) |
| 1527 | return; |
| 1528 | |
| 1529 | char aBufTime[32]; |
| 1530 | char aBuf[64]; |
| 1531 | int64_t Time = (int64_t)100 * (float)(pSelf->Server()->Tick() - pChr->m_StartTime) / ((float)pSelf->Server()->TickSpeed()); |
| 1532 | const char *pName = pSelf->Server()->ClientName(ClientId: pResult->m_ClientId); |
| 1533 | str_time(centisecs: Time, format: ETimeFormat::HOURS, buffer: aBufTime, buffer_size: sizeof(aBufTime)); |
| 1534 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s's current race time is %s" , pName, aBufTime); |
| 1535 | pSelf->SendChat(ClientId: -1, Team: TEAM_ALL, pText: aBuf, SpamProtectionClientId: pResult->m_ClientId); |
| 1536 | } |
| 1537 | |
| 1538 | void CGameContext::ConTime(IConsole::IResult *pResult, void *pUserData) |
| 1539 | { |
| 1540 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1541 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1542 | return; |
| 1543 | |
| 1544 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1545 | if(!pPlayer) |
| 1546 | return; |
| 1547 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 1548 | if(!pChr) |
| 1549 | return; |
| 1550 | |
| 1551 | char aBufTime[32]; |
| 1552 | char aBuf[64]; |
| 1553 | int64_t Time = (int64_t)100 * (float)(pSelf->Server()->Tick() - pChr->m_StartTime) / ((float)pSelf->Server()->TickSpeed()); |
| 1554 | str_time(centisecs: Time, format: ETimeFormat::HOURS, buffer: aBufTime, buffer_size: sizeof(aBufTime)); |
| 1555 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "Your time is %s" , aBufTime); |
| 1556 | pSelf->SendBroadcast(pText: aBuf, ClientId: pResult->m_ClientId); |
| 1557 | } |
| 1558 | |
| 1559 | static const char s_aaMsg[4][128] = {"game/round timer." , "broadcast." , "both game/round timer and broadcast." , "racetime." }; |
| 1560 | |
| 1561 | void CGameContext::ConSetTimerType(IConsole::IResult *pResult, void *pUserData) |
| 1562 | { |
| 1563 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1564 | |
| 1565 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1566 | return; |
| 1567 | |
| 1568 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1569 | if(!pPlayer) |
| 1570 | return; |
| 1571 | |
| 1572 | char aBuf[128]; |
| 1573 | |
| 1574 | if(pResult->NumArguments() > 0) |
| 1575 | { |
| 1576 | int OldType = pPlayer->m_TimerType; |
| 1577 | bool Result = false; |
| 1578 | |
| 1579 | if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "default" ) == 0) |
| 1580 | Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_DEFAULT); |
| 1581 | else if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "gametimer" ) == 0) |
| 1582 | Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_GAMETIMER); |
| 1583 | else if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "broadcast" ) == 0) |
| 1584 | Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_BROADCAST); |
| 1585 | else if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "both" ) == 0) |
| 1586 | Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST); |
| 1587 | else if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "none" ) == 0) |
| 1588 | Result = pPlayer->SetTimerType(CPlayer::TIMERTYPE_NONE); |
| 1589 | else |
| 1590 | { |
| 1591 | log_info("chatresp" , "Unknown parameter. Accepted values: default, gametimer, broadcast, both, none" ); |
| 1592 | return; |
| 1593 | } |
| 1594 | |
| 1595 | if(!Result) |
| 1596 | { |
| 1597 | log_info("chatresp" , "Selected timertype is not supported by your client" ); |
| 1598 | return; |
| 1599 | } |
| 1600 | |
| 1601 | if((OldType == CPlayer::TIMERTYPE_BROADCAST || OldType == CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST) && (pPlayer->m_TimerType == CPlayer::TIMERTYPE_GAMETIMER || pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE)) |
| 1602 | pSelf->SendBroadcast(pText: "" , ClientId: pResult->m_ClientId); |
| 1603 | } |
| 1604 | |
| 1605 | if(pPlayer->m_TimerType <= CPlayer::TIMERTYPE_SIXUP && pPlayer->m_TimerType >= CPlayer::TIMERTYPE_GAMETIMER) |
| 1606 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "Timer is displayed in %s" , s_aaMsg[pPlayer->m_TimerType]); |
| 1607 | else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE) |
| 1608 | str_copy(dst&: aBuf, src: "Timer isn't displayed." ); |
| 1609 | |
| 1610 | log_info("chatresp" , "%s" , aBuf); |
| 1611 | } |
| 1612 | |
| 1613 | void CGameContext::ConRescue(IConsole::IResult *pResult, void *pUserData) |
| 1614 | { |
| 1615 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1616 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1617 | return; |
| 1618 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1619 | if(!pPlayer) |
| 1620 | return; |
| 1621 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 1622 | if(!pChr) |
| 1623 | return; |
| 1624 | |
| 1625 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 1626 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1627 | if(!g_Config.m_SvRescue && !Teams.IsPractice(Team)) |
| 1628 | { |
| 1629 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "Rescue is not enabled on this server and you're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled." ); |
| 1630 | return; |
| 1631 | } |
| 1632 | |
| 1633 | bool GoRescue = true; |
| 1634 | |
| 1635 | if(pPlayer->m_RescueMode == RESCUEMODE_MANUAL) |
| 1636 | { |
| 1637 | // if character can't set their rescue state then we should rescue them instead |
| 1638 | GoRescue = !pChr->TrySetRescue(RescueMode: RESCUEMODE_MANUAL); |
| 1639 | } |
| 1640 | |
| 1641 | if(GoRescue) |
| 1642 | { |
| 1643 | if(pChr->Rescue()) |
| 1644 | pChr->Unfreeze(); |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | void CGameContext::ConRescueMode(IConsole::IResult *pResult, void *pUserData) |
| 1649 | { |
| 1650 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1651 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1652 | return; |
| 1653 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1654 | if(!pPlayer) |
| 1655 | return; |
| 1656 | |
| 1657 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 1658 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1659 | if(!g_Config.m_SvRescue && !Teams.IsPractice(Team)) |
| 1660 | { |
| 1661 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "Rescue is not enabled on this server and you're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled." ); |
| 1662 | return; |
| 1663 | } |
| 1664 | |
| 1665 | if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "auto" ) == 0) |
| 1666 | { |
| 1667 | if(pPlayer->m_RescueMode != RESCUEMODE_AUTO) |
| 1668 | { |
| 1669 | pPlayer->m_RescueMode = RESCUEMODE_AUTO; |
| 1670 | |
| 1671 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "Rescue mode changed to auto." ); |
| 1672 | } |
| 1673 | |
| 1674 | return; |
| 1675 | } |
| 1676 | |
| 1677 | if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "manual" ) == 0) |
| 1678 | { |
| 1679 | if(pPlayer->m_RescueMode != RESCUEMODE_MANUAL) |
| 1680 | { |
| 1681 | pPlayer->m_RescueMode = RESCUEMODE_MANUAL; |
| 1682 | |
| 1683 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "Rescue mode changed to manual." ); |
| 1684 | } |
| 1685 | |
| 1686 | return; |
| 1687 | } |
| 1688 | |
| 1689 | if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "list" ) == 0) |
| 1690 | { |
| 1691 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "Available rescue modes: auto, manual" ); |
| 1692 | } |
| 1693 | else if(str_comp_nocase(a: pResult->GetString(Index: 0), b: "" ) == 0) |
| 1694 | { |
| 1695 | char aBuf[64]; |
| 1696 | str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "Current rescue mode: %s." , pPlayer->m_RescueMode == RESCUEMODE_MANUAL ? "manual" : "auto" ); |
| 1697 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: aBuf); |
| 1698 | } |
| 1699 | else |
| 1700 | { |
| 1701 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "Unknown argument. Check '/rescuemode list'" ); |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | void CGameContext::ConBack(IConsole::IResult *pResult, void *pUserData) |
| 1706 | { |
| 1707 | auto *pSelf = static_cast<CGameContext *>(pUserData); |
| 1708 | auto *pChr = pSelf->GetPracticeCharacter(pResult); |
| 1709 | if(!pChr) |
| 1710 | return; |
| 1711 | |
| 1712 | auto *pPlayer = pChr->GetPlayer(); |
| 1713 | if(!pPlayer->m_LastDeath.has_value()) |
| 1714 | { |
| 1715 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "There is nowhere to go back to." ); |
| 1716 | return; |
| 1717 | } |
| 1718 | pChr->GetLastRescueTeeRef(Mode: pPlayer->m_RescueMode) = pPlayer->m_LastDeath.value(); |
| 1719 | if(pChr->Rescue()) |
| 1720 | pChr->Unfreeze(); |
| 1721 | } |
| 1722 | |
| 1723 | void CGameContext::ConTeleTo(IConsole::IResult *pResult, void *pUserData) |
| 1724 | { |
| 1725 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1726 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1727 | return; |
| 1728 | CPlayer *pCallingPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1729 | if(!pCallingPlayer) |
| 1730 | return; |
| 1731 | CCharacter *pCallingCharacter = pCallingPlayer->GetCharacter(); |
| 1732 | if(!pCallingCharacter) |
| 1733 | return; |
| 1734 | |
| 1735 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 1736 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1737 | if(!Teams.IsPractice(Team)) |
| 1738 | { |
| 1739 | pSelf->SendChatTarget(To: pCallingPlayer->GetCid(), pText: "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled." ); |
| 1740 | return; |
| 1741 | } |
| 1742 | |
| 1743 | vec2 Pos = {}; |
| 1744 | |
| 1745 | if(pResult->NumArguments() == 0) |
| 1746 | { |
| 1747 | // Set calling tee's position to the origin of its spectating viewport |
| 1748 | Pos = pCallingPlayer->m_ViewPos; |
| 1749 | } |
| 1750 | else |
| 1751 | { |
| 1752 | const CPlayer *pDestPlayer = pSelf->FindPlayerByName(pName: pResult->GetString(Index: 0)); |
| 1753 | if(!pDestPlayer) |
| 1754 | { |
| 1755 | pSelf->SendChatTarget(To: pCallingPlayer->GetCid(), pText: "No player with this name found." ); |
| 1756 | return; |
| 1757 | } |
| 1758 | const CCharacter *pDestCharacter = pDestPlayer->GetCharacter(); |
| 1759 | if(!pDestCharacter) |
| 1760 | return; |
| 1761 | |
| 1762 | // Set calling tee's position to that of the destination tee |
| 1763 | Pos = pDestCharacter->m_Pos; |
| 1764 | } |
| 1765 | |
| 1766 | // Teleport tee |
| 1767 | pSelf->Teleport(pChr: pCallingCharacter, Pos); |
| 1768 | pCallingCharacter->ResetJumps(); |
| 1769 | pCallingCharacter->Unfreeze(); |
| 1770 | pCallingCharacter->ResetVelocity(); |
| 1771 | pCallingPlayer->m_LastTeleTee.Save(pChr: pCallingCharacter); |
| 1772 | } |
| 1773 | |
| 1774 | void CGameContext::ConTeleXY(IConsole::IResult *pResult, void *pUserData) |
| 1775 | { |
| 1776 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1777 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1778 | return; |
| 1779 | CPlayer *pCallingPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1780 | if(!pCallingPlayer) |
| 1781 | return; |
| 1782 | CCharacter *pCallingCharacter = pCallingPlayer->GetCharacter(); |
| 1783 | if(!pCallingCharacter) |
| 1784 | return; |
| 1785 | |
| 1786 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 1787 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1788 | if(!Teams.IsPractice(Team)) |
| 1789 | { |
| 1790 | pSelf->SendChatTarget(To: pCallingPlayer->GetCid(), pText: "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled." ); |
| 1791 | return; |
| 1792 | } |
| 1793 | |
| 1794 | vec2 Pos = {}; |
| 1795 | |
| 1796 | if(pResult->NumArguments() != 2) |
| 1797 | { |
| 1798 | pSelf->SendChatTarget(To: pCallingPlayer->GetCid(), pText: "Can't recognize specified arguments. Usage: /tpxy x y, e.g. /tpxy 9 3." ); |
| 1799 | return; |
| 1800 | } |
| 1801 | |
| 1802 | float BaseX = 0.f, BaseY = 0.f; |
| 1803 | |
| 1804 | const auto DetermineCoordinateRelativity = [](const char *pInString, const float AbsoluteDefaultValue, float &OutFloat) -> bool { |
| 1805 | // mode 0 = abs, 1 = sub, 2 = add |
| 1806 | |
| 1807 | // Relative? |
| 1808 | const char *pStrDelta = str_startswith(str: pInString, prefix: "~" ); |
| 1809 | |
| 1810 | float d; |
| 1811 | if(!str_tofloat(str: pStrDelta ? pStrDelta : pInString, out: &d)) |
| 1812 | return false; |
| 1813 | |
| 1814 | // Is the number valid? |
| 1815 | if(std::isnan(x: d) || std::isinf(x: d)) |
| 1816 | return false; |
| 1817 | |
| 1818 | // Convert our gleaned 'display' coordinate to an actual map coordinate |
| 1819 | d *= 32.f; |
| 1820 | |
| 1821 | OutFloat = (pStrDelta ? AbsoluteDefaultValue : 0) + d; |
| 1822 | return true; |
| 1823 | }; |
| 1824 | |
| 1825 | if(!DetermineCoordinateRelativity(pResult->GetString(Index: 0), pCallingPlayer->m_ViewPos.x, BaseX)) |
| 1826 | { |
| 1827 | pSelf->SendChatTarget(To: pCallingPlayer->GetCid(), pText: "Invalid X coordinate." ); |
| 1828 | return; |
| 1829 | } |
| 1830 | if(!DetermineCoordinateRelativity(pResult->GetString(Index: 1), pCallingPlayer->m_ViewPos.y, BaseY)) |
| 1831 | { |
| 1832 | pSelf->SendChatTarget(To: pCallingPlayer->GetCid(), pText: "Invalid Y coordinate." ); |
| 1833 | return; |
| 1834 | } |
| 1835 | |
| 1836 | Pos = {BaseX, BaseY}; |
| 1837 | |
| 1838 | pSelf->PracticeTeleport(pChr: pCallingCharacter, Pos); |
| 1839 | } |
| 1840 | |
| 1841 | void CGameContext::ConTeleCursor(IConsole::IResult *pResult, void *pUserData) |
| 1842 | { |
| 1843 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1844 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1845 | return; |
| 1846 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1847 | if(!pPlayer) |
| 1848 | return; |
| 1849 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 1850 | if(!pChr) |
| 1851 | return; |
| 1852 | |
| 1853 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 1854 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1855 | if(!Teams.IsPractice(Team)) |
| 1856 | { |
| 1857 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled." ); |
| 1858 | return; |
| 1859 | } |
| 1860 | |
| 1861 | // default to view pos when character is not available |
| 1862 | vec2 Pos = pPlayer->m_ViewPos; |
| 1863 | if(pResult->NumArguments() == 0 && !pPlayer->IsPaused() && pPlayer->GetCharacter() && pPlayer->GetCharacter()->IsAlive()) |
| 1864 | { |
| 1865 | vec2 Target = vec2(pChr->Core()->m_Input.m_TargetX, pChr->Core()->m_Input.m_TargetY); |
| 1866 | Pos = pPlayer->m_CameraInfo.ConvertTargetToWorld(Position: pPlayer->GetCharacter()->GetPos(), Target); |
| 1867 | } |
| 1868 | else if(pResult->NumArguments() > 0) |
| 1869 | { |
| 1870 | const CPlayer *pPlayerTo = pSelf->FindPlayerByName(pName: pResult->GetString(Index: 0)); |
| 1871 | if(!pPlayerTo) |
| 1872 | { |
| 1873 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "No player with this name found." ); |
| 1874 | return; |
| 1875 | } |
| 1876 | const CCharacter *pChrTo = pPlayerTo->GetCharacter(); |
| 1877 | if(!pChrTo) |
| 1878 | return; |
| 1879 | Pos = pChrTo->m_Pos; |
| 1880 | } |
| 1881 | pSelf->Teleport(pChr, Pos); |
| 1882 | pChr->ResetJumps(); |
| 1883 | pChr->Unfreeze(); |
| 1884 | pChr->ResetVelocity(); |
| 1885 | pPlayer->m_LastTeleTee.Save(pChr); |
| 1886 | } |
| 1887 | |
| 1888 | void CGameContext::ConLastTele(IConsole::IResult *pResult, void *pUserData) |
| 1889 | { |
| 1890 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1891 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1892 | return; |
| 1893 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1894 | if(!pPlayer) |
| 1895 | return; |
| 1896 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 1897 | if(!pChr) |
| 1898 | return; |
| 1899 | |
| 1900 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 1901 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1902 | if(!Teams.IsPractice(Team)) |
| 1903 | { |
| 1904 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled." ); |
| 1905 | return; |
| 1906 | } |
| 1907 | if(!pPlayer->m_LastTeleTee.GetPos().x) |
| 1908 | { |
| 1909 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "You haven't previously teleported. Use /tp before using this command." ); |
| 1910 | return; |
| 1911 | } |
| 1912 | pPlayer->m_LastTeleTee.Load(pChr); |
| 1913 | pPlayer->Pause(State: CPlayer::PAUSE_NONE, Force: true); |
| 1914 | } |
| 1915 | |
| 1916 | CCharacter *CGameContext::GetPracticeCharacter(IConsole::IResult *pResult) |
| 1917 | { |
| 1918 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1919 | return nullptr; |
| 1920 | CPlayer *pPlayer = m_apPlayers[pResult->m_ClientId]; |
| 1921 | if(!pPlayer) |
| 1922 | return nullptr; |
| 1923 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 1924 | if(!pChr) |
| 1925 | return nullptr; |
| 1926 | |
| 1927 | CGameTeams &Teams = m_pController->Teams(); |
| 1928 | int Team = GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1929 | if(!Teams.IsPractice(Team)) |
| 1930 | { |
| 1931 | SendChatTarget(To: pPlayer->GetCid(), pText: "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled." ); |
| 1932 | return nullptr; |
| 1933 | } |
| 1934 | return pChr; |
| 1935 | } |
| 1936 | |
| 1937 | void CGameContext::ConPracticeToTeleporter(IConsole::IResult *pResult, void *pUserData) |
| 1938 | { |
| 1939 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1940 | CCharacter *pChr = pSelf->GetPracticeCharacter(pResult); |
| 1941 | if(!pChr) |
| 1942 | return; |
| 1943 | |
| 1944 | if(pSelf->Collision()->TeleOuts(Number: pResult->GetInteger(Index: 0) - 1).empty()) |
| 1945 | { |
| 1946 | pSelf->SendChatTarget(To: pChr->GetPlayer()->GetCid(), pText: "There is no teleporter with that index on the map." ); |
| 1947 | return; |
| 1948 | } |
| 1949 | |
| 1950 | ConToTeleporter(pResult, pUserData); |
| 1951 | pChr->ResetJumps(); |
| 1952 | pChr->Unfreeze(); |
| 1953 | pChr->ResetVelocity(); |
| 1954 | pChr->GetPlayer()->m_LastTeleTee.Save(pChr); |
| 1955 | } |
| 1956 | |
| 1957 | void CGameContext::ConPracticeToCheckTeleporter(IConsole::IResult *pResult, void *pUserData) |
| 1958 | { |
| 1959 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1960 | CCharacter *pChr = pSelf->GetPracticeCharacter(pResult); |
| 1961 | if(!pChr) |
| 1962 | return; |
| 1963 | |
| 1964 | if(pSelf->Collision()->TeleCheckOuts(Number: pResult->GetInteger(Index: 0) - 1).empty()) |
| 1965 | { |
| 1966 | pSelf->SendChatTarget(To: pChr->GetPlayer()->GetCid(), pText: "There is no checkpoint teleporter with that index on the map." ); |
| 1967 | return; |
| 1968 | } |
| 1969 | |
| 1970 | ConToCheckTeleporter(pResult, pUserData); |
| 1971 | pChr->ResetJumps(); |
| 1972 | pChr->Unfreeze(); |
| 1973 | pChr->ResetVelocity(); |
| 1974 | pChr->GetPlayer()->m_LastTeleTee.Save(pChr); |
| 1975 | } |
| 1976 | |
| 1977 | void CGameContext::ConPracticeUnSolo(IConsole::IResult *pResult, void *pUserData) |
| 1978 | { |
| 1979 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 1980 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 1981 | return; |
| 1982 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 1983 | if(!pPlayer) |
| 1984 | return; |
| 1985 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 1986 | if(!pChr) |
| 1987 | return; |
| 1988 | |
| 1989 | if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) |
| 1990 | { |
| 1991 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "Command is not available on solo servers" ); |
| 1992 | return; |
| 1993 | } |
| 1994 | |
| 1995 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 1996 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 1997 | if(!Teams.IsPractice(Team)) |
| 1998 | { |
| 1999 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled." ); |
| 2000 | return; |
| 2001 | } |
| 2002 | pChr->SetSolo(false); |
| 2003 | } |
| 2004 | |
| 2005 | void CGameContext::ConPracticeSolo(IConsole::IResult *pResult, void *pUserData) |
| 2006 | { |
| 2007 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2008 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 2009 | return; |
| 2010 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 2011 | if(!pPlayer) |
| 2012 | return; |
| 2013 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 2014 | if(!pChr) |
| 2015 | return; |
| 2016 | |
| 2017 | if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) |
| 2018 | { |
| 2019 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "Command is not available on solo servers" ); |
| 2020 | return; |
| 2021 | } |
| 2022 | |
| 2023 | CGameTeams &Teams = pSelf->m_pController->Teams(); |
| 2024 | int Team = pSelf->GetDDRaceTeam(ClientId: pResult->m_ClientId); |
| 2025 | if(!Teams.IsPractice(Team)) |
| 2026 | { |
| 2027 | pSelf->SendChatTarget(To: pPlayer->GetCid(), pText: "You're not in a team with /practice turned on. Note that you can't earn a rank with practice enabled." ); |
| 2028 | return; |
| 2029 | } |
| 2030 | pChr->SetSolo(true); |
| 2031 | } |
| 2032 | |
| 2033 | void CGameContext::ConPracticeUnDeep(IConsole::IResult *pResult, void *pUserData) |
| 2034 | { |
| 2035 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2036 | auto *pChr = pSelf->GetPracticeCharacter(pResult); |
| 2037 | if(!pChr) |
| 2038 | return; |
| 2039 | |
| 2040 | pChr->SetDeepFrozen(false); |
| 2041 | pChr->Unfreeze(); |
| 2042 | } |
| 2043 | |
| 2044 | void CGameContext::ConPracticeDeep(IConsole::IResult *pResult, void *pUserData) |
| 2045 | { |
| 2046 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2047 | auto *pChr = pSelf->GetPracticeCharacter(pResult); |
| 2048 | if(!pChr) |
| 2049 | return; |
| 2050 | |
| 2051 | pChr->SetDeepFrozen(true); |
| 2052 | } |
| 2053 | |
| 2054 | void CGameContext::ConPracticeUnLiveFreeze(IConsole::IResult *pResult, void *pUserData) |
| 2055 | { |
| 2056 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2057 | auto *pChr = pSelf->GetPracticeCharacter(pResult); |
| 2058 | if(!pChr) |
| 2059 | return; |
| 2060 | |
| 2061 | pChr->SetLiveFrozen(false); |
| 2062 | } |
| 2063 | |
| 2064 | void CGameContext::ConPracticeLiveFreeze(IConsole::IResult *pResult, void *pUserData) |
| 2065 | { |
| 2066 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2067 | auto *pChr = pSelf->GetPracticeCharacter(pResult); |
| 2068 | if(!pChr) |
| 2069 | return; |
| 2070 | |
| 2071 | pChr->SetLiveFrozen(true); |
| 2072 | } |
| 2073 | |
| 2074 | void CGameContext::ConPracticeShotgun(IConsole::IResult *pResult, void *pUserData) |
| 2075 | { |
| 2076 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2077 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2078 | ConShotgun(pResult, pUserData); |
| 2079 | } |
| 2080 | |
| 2081 | void CGameContext::ConPracticeGrenade(IConsole::IResult *pResult, void *pUserData) |
| 2082 | { |
| 2083 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2084 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2085 | ConGrenade(pResult, pUserData); |
| 2086 | } |
| 2087 | |
| 2088 | void CGameContext::ConPracticeLaser(IConsole::IResult *pResult, void *pUserData) |
| 2089 | { |
| 2090 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2091 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2092 | ConLaser(pResult, pUserData); |
| 2093 | } |
| 2094 | |
| 2095 | void CGameContext::ConPracticeJetpack(IConsole::IResult *pResult, void *pUserData) |
| 2096 | { |
| 2097 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2098 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2099 | ConJetpack(pResult, pUserData); |
| 2100 | } |
| 2101 | |
| 2102 | void CGameContext::ConPracticeEndlessJump(IConsole::IResult *pResult, void *pUserData) |
| 2103 | { |
| 2104 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2105 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2106 | ConEndlessJump(pResult, pUserData); |
| 2107 | } |
| 2108 | |
| 2109 | void CGameContext::ConPracticeSetJumps(IConsole::IResult *pResult, void *pUserData) |
| 2110 | { |
| 2111 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2112 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2113 | ConSetJumps(pResult, pUserData); |
| 2114 | } |
| 2115 | |
| 2116 | void CGameContext::ConPracticeWeapons(IConsole::IResult *pResult, void *pUserData) |
| 2117 | { |
| 2118 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2119 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2120 | ConWeapons(pResult, pUserData); |
| 2121 | } |
| 2122 | |
| 2123 | void CGameContext::ConPracticeUnShotgun(IConsole::IResult *pResult, void *pUserData) |
| 2124 | { |
| 2125 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2126 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2127 | ConUnShotgun(pResult, pUserData); |
| 2128 | } |
| 2129 | |
| 2130 | void CGameContext::ConPracticeUnGrenade(IConsole::IResult *pResult, void *pUserData) |
| 2131 | { |
| 2132 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2133 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2134 | ConUnGrenade(pResult, pUserData); |
| 2135 | } |
| 2136 | |
| 2137 | void CGameContext::ConPracticeUnLaser(IConsole::IResult *pResult, void *pUserData) |
| 2138 | { |
| 2139 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2140 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2141 | ConUnLaser(pResult, pUserData); |
| 2142 | } |
| 2143 | |
| 2144 | void CGameContext::ConPracticeUnJetpack(IConsole::IResult *pResult, void *pUserData) |
| 2145 | { |
| 2146 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2147 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2148 | ConUnJetpack(pResult, pUserData); |
| 2149 | } |
| 2150 | |
| 2151 | void CGameContext::ConPracticeUnEndlessJump(IConsole::IResult *pResult, void *pUserData) |
| 2152 | { |
| 2153 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2154 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2155 | ConUnEndlessJump(pResult, pUserData); |
| 2156 | } |
| 2157 | |
| 2158 | void CGameContext::ConPracticeUnWeapons(IConsole::IResult *pResult, void *pUserData) |
| 2159 | { |
| 2160 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2161 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2162 | ConUnWeapons(pResult, pUserData); |
| 2163 | } |
| 2164 | |
| 2165 | void CGameContext::ConPracticeNinja(IConsole::IResult *pResult, void *pUserData) |
| 2166 | { |
| 2167 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2168 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2169 | ConNinja(pResult, pUserData); |
| 2170 | } |
| 2171 | |
| 2172 | void CGameContext::ConPracticeUnNinja(IConsole::IResult *pResult, void *pUserData) |
| 2173 | { |
| 2174 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2175 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2176 | ConUnNinja(pResult, pUserData); |
| 2177 | } |
| 2178 | |
| 2179 | void CGameContext::ConPracticeEndlessHook(IConsole::IResult *pResult, void *pUserData) |
| 2180 | { |
| 2181 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2182 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2183 | ConEndlessHook(pResult, pUserData); |
| 2184 | } |
| 2185 | |
| 2186 | void CGameContext::ConPracticeUnEndlessHook(IConsole::IResult *pResult, void *pUserData) |
| 2187 | { |
| 2188 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2189 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2190 | ConUnEndlessHook(pResult, pUserData); |
| 2191 | } |
| 2192 | |
| 2193 | void CGameContext::ConPracticeSetSwitch(IConsole::IResult *pResult, void *pUserData) |
| 2194 | { |
| 2195 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2196 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2197 | ConSetSwitch(pResult, pUserData); |
| 2198 | } |
| 2199 | |
| 2200 | void CGameContext::ConPracticeToggleInvincible(IConsole::IResult *pResult, void *pUserData) |
| 2201 | { |
| 2202 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2203 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2204 | ConToggleInvincible(pResult, pUserData); |
| 2205 | } |
| 2206 | |
| 2207 | void CGameContext::ConPracticeToggleCollision(IConsole::IResult *pResult, void *pUserData) |
| 2208 | { |
| 2209 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2210 | auto *pChr = pSelf->GetPracticeCharacter(pResult); |
| 2211 | if(!pChr) |
| 2212 | return; |
| 2213 | |
| 2214 | pChr->SetCollisionDisabled(!pChr->Core()->m_CollisionDisabled); |
| 2215 | } |
| 2216 | |
| 2217 | void CGameContext::ConPracticeToggleHookCollision(IConsole::IResult *pResult, void *pUserData) |
| 2218 | { |
| 2219 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2220 | auto *pChr = pSelf->GetPracticeCharacter(pResult); |
| 2221 | if(!pChr) |
| 2222 | return; |
| 2223 | |
| 2224 | pChr->SetHookHitDisabled(!pChr->Core()->m_HookHitDisabled); |
| 2225 | } |
| 2226 | |
| 2227 | void CGameContext::ConPracticeToggleHitOthers(IConsole::IResult *pResult, void *pUserData) |
| 2228 | { |
| 2229 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2230 | auto *pChr = pSelf->GetPracticeCharacter(pResult); |
| 2231 | if(!pChr) |
| 2232 | return; |
| 2233 | |
| 2234 | if(pResult->NumArguments() == 0 || str_comp(a: pResult->GetString(Index: 0), b: "all" ) == 0) |
| 2235 | { |
| 2236 | bool IsEnabled = (pChr->HammerHitDisabled() && pChr->ShotgunHitDisabled() && |
| 2237 | pChr->GrenadeHitDisabled() && pChr->LaserHitDisabled()); |
| 2238 | pChr->SetHammerHitDisabled(!IsEnabled); |
| 2239 | pChr->SetShotgunHitDisabled(!IsEnabled); |
| 2240 | pChr->SetGrenadeHitDisabled(!IsEnabled); |
| 2241 | pChr->SetLaserHitDisabled(!IsEnabled); |
| 2242 | return; |
| 2243 | } |
| 2244 | |
| 2245 | if(str_comp(a: pResult->GetString(Index: 0), b: "hammer" ) == 0) |
| 2246 | pChr->SetHammerHitDisabled(!pChr->HammerHitDisabled()); |
| 2247 | else if(str_comp(a: pResult->GetString(Index: 0), b: "shotgun" ) == 0) |
| 2248 | pChr->SetShotgunHitDisabled(!pChr->ShotgunHitDisabled()); |
| 2249 | else if(str_comp(a: pResult->GetString(Index: 0), b: "grenade" ) == 0) |
| 2250 | pChr->SetGrenadeHitDisabled(!pChr->GrenadeHitDisabled()); |
| 2251 | else if(str_comp(a: pResult->GetString(Index: 0), b: "laser" ) == 0) |
| 2252 | pChr->SetLaserHitDisabled(!pChr->LaserHitDisabled()); |
| 2253 | } |
| 2254 | |
| 2255 | void CGameContext::ConPracticeAddWeapon(IConsole::IResult *pResult, void *pUserData) |
| 2256 | { |
| 2257 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2258 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2259 | ConAddWeapon(pResult, pUserData); |
| 2260 | } |
| 2261 | |
| 2262 | void CGameContext::ConPracticeRemoveWeapon(IConsole::IResult *pResult, void *pUserData) |
| 2263 | { |
| 2264 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2265 | if(pSelf->GetPracticeCharacter(pResult)) |
| 2266 | ConRemoveWeapon(pResult, pUserData); |
| 2267 | } |
| 2268 | |
| 2269 | void CGameContext::ConProtectedKill(IConsole::IResult *pResult, void *pUserData) |
| 2270 | { |
| 2271 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2272 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 2273 | return; |
| 2274 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 2275 | if(!pPlayer) |
| 2276 | return; |
| 2277 | CCharacter *pChr = pPlayer->GetCharacter(); |
| 2278 | if(!pChr) |
| 2279 | return; |
| 2280 | |
| 2281 | int CurrTime = (pSelf->Server()->Tick() - pChr->m_StartTime) / pSelf->Server()->TickSpeed(); |
| 2282 | if(g_Config.m_SvKillProtection != 0 && CurrTime >= (60 * g_Config.m_SvKillProtection) && pChr->m_DDRaceState == ERaceState::STARTED) |
| 2283 | { |
| 2284 | pPlayer->KillCharacter(Weapon: WEAPON_SELF); |
| 2285 | pPlayer->Respawn(); |
| 2286 | } |
| 2287 | } |
| 2288 | |
| 2289 | void CGameContext::ConPoints(IConsole::IResult *pResult, void *pUserData) |
| 2290 | { |
| 2291 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2292 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 2293 | return; |
| 2294 | |
| 2295 | if(pResult->NumArguments() > 0) |
| 2296 | { |
| 2297 | if(!g_Config.m_SvHideScore) |
| 2298 | pSelf->Score()->ShowPoints(ClientId: pResult->m_ClientId, pName: pResult->GetString(Index: 0)); |
| 2299 | else |
| 2300 | log_info("chatresp" , "Showing the global points of other players is not allowed on this server." ); |
| 2301 | } |
| 2302 | else |
| 2303 | pSelf->Score()->ShowPoints(ClientId: pResult->m_ClientId, |
| 2304 | pName: pSelf->Server()->ClientName(ClientId: pResult->m_ClientId)); |
| 2305 | } |
| 2306 | |
| 2307 | void CGameContext::ConTopPoints(IConsole::IResult *pResult, void *pUserData) |
| 2308 | { |
| 2309 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2310 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 2311 | return; |
| 2312 | |
| 2313 | if(g_Config.m_SvHideScore) |
| 2314 | { |
| 2315 | log_info("chatresp" , "Showing the global top points is not allowed on this server." ); |
| 2316 | return; |
| 2317 | } |
| 2318 | |
| 2319 | if(pResult->NumArguments() > 0) |
| 2320 | pSelf->Score()->ShowTopPoints(ClientId: pResult->m_ClientId, Offset: pResult->GetInteger(Index: 0)); |
| 2321 | else |
| 2322 | pSelf->Score()->ShowTopPoints(ClientId: pResult->m_ClientId); |
| 2323 | } |
| 2324 | |
| 2325 | void CGameContext::ConTimeCP(IConsole::IResult *pResult, void *pUserData) |
| 2326 | { |
| 2327 | CGameContext *pSelf = (CGameContext *)pUserData; |
| 2328 | if(!CheckClientId(ClientId: pResult->m_ClientId)) |
| 2329 | return; |
| 2330 | |
| 2331 | if(g_Config.m_SvHideScore) |
| 2332 | { |
| 2333 | log_info("chatresp" , "Showing the checkpoint times is not allowed on this server." ); |
| 2334 | return; |
| 2335 | } |
| 2336 | |
| 2337 | CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientId]; |
| 2338 | if(!pPlayer) |
| 2339 | return; |
| 2340 | |
| 2341 | const char *pName = pResult->GetString(Index: 0); |
| 2342 | pSelf->Score()->LoadPlayerTimeCp(ClientId: pResult->m_ClientId, pName); |
| 2343 | } |
| 2344 | |