-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
2,077 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
"ServerCfg" | ||
{ | ||
"defaultMode" "Classic" | ||
"defaultStyle" "Normal" | ||
"defaultLanguage" "en" | ||
"tipInterval" "75" | ||
"defaultJSBroadcastMinTier" "4" | ||
"defaultJSSoundMinTier" "4" | ||
"chatPrefix" "{lime}KZ {grey}|{default}" | ||
"defaultMode" "Classic" | ||
"defaultStyle" "Normal" | ||
"defaultLanguage" "en" | ||
"tipInterval" "75" | ||
"defaultJSBroadcastMinTier" "4" | ||
"defaultJSSoundMinTier" "4" | ||
"chatPrefix" "{lime}KZ {grey}|{default}" | ||
"apiUrl" "http://localhost:42069" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "kz_global.h" | ||
#include "kz/language/kz_language.h" | ||
#include "utils/simplecmds.h" | ||
|
||
static_function SCMD_CALLBACK(Command_KzProfile) | ||
{ | ||
KZPlayer *player = g_pKZPlayerManager->ToPlayer(controller); | ||
|
||
auto onSuccess = [player](std::optional<KZ::API::Player> info) { | ||
if (!info) | ||
{ | ||
player->languageService->PrintChat(true, false, "Player not found"); | ||
return; | ||
} | ||
|
||
const char *name = info->name.c_str(); | ||
const char *steamID = info->steamID.c_str(); | ||
const char *isBanned = info->isBanned ? info->isBanned.value() ? "" : "not " : "maybe "; | ||
|
||
player->languageService->PrintChat(true, false, "Display PlayerInfo", name, steamID, isBanned); | ||
}; | ||
|
||
auto onError = [player](KZ::API::Error error) { | ||
player->languageService->PrintError(error); | ||
}; | ||
|
||
const char *playerIdentifier = args->Arg(1); | ||
|
||
if (playerIdentifier[0] == '\0') | ||
{ | ||
KZGlobalService::FetchPlayer(player->GetSteamId64(), onSuccess, onError); | ||
} | ||
else | ||
{ | ||
KZGlobalService::FetchPlayer(playerIdentifier, onSuccess, onError); | ||
} | ||
|
||
return MRES_SUPERCEDE; | ||
} | ||
|
||
static_function SCMD_CALLBACK(Command_KzMapInfo) | ||
{ | ||
KZPlayer *player = g_pKZPlayerManager->ToPlayer(controller); | ||
const char *mapIdentifier = args->Arg(1); | ||
|
||
if (mapIdentifier[0] != '\0') | ||
{ | ||
auto onSuccess = [player](std::optional<KZ::API::Map> map) { | ||
if (!map) | ||
{ | ||
player->languageService->PrintChat(true, false, "MapNotGlobal"); | ||
return; | ||
} | ||
|
||
player->languageService->PrintMap(map.value()); | ||
}; | ||
|
||
auto onError = [player](KZ::API::Error error) { | ||
player->languageService->PrintError(error); | ||
}; | ||
|
||
KZGlobalService::FetchMap(mapIdentifier, onSuccess, onError); | ||
} | ||
else if (KZGlobalService::currentMap) | ||
{ | ||
player->languageService->PrintMap(KZGlobalService::currentMap.value()); | ||
} | ||
else | ||
{ | ||
player->languageService->PrintChat(true, false, "MapNotGlobal"); | ||
} | ||
|
||
return MRES_SUPERCEDE; | ||
} | ||
|
||
void KZGlobalService::RegisterCommands() | ||
{ | ||
scmd::RegisterCmd("kz_profile", Command_KzProfile); | ||
scmd::RegisterCmd("kz_mapinfo", Command_KzMapInfo); | ||
scmd::RegisterCmd("kz_minfo", Command_KzMapInfo); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "error.h" | ||
#include "kz/language/kz_language.h" | ||
|
||
namespace KZ::API | ||
{ | ||
Error::Error(u16 status, std::string message) : status(status) | ||
{ | ||
if (!json::accept(message)) | ||
{ | ||
this->message = message; | ||
return; | ||
} | ||
|
||
const json error = json::parse(message); | ||
|
||
if (!error.is_object()) | ||
{ | ||
META_CONPRINTF("[KZ::Global] API error is not an object: `%s`\n", error.dump().c_str()); | ||
return; | ||
} | ||
|
||
if (!error.contains("message")) | ||
{ | ||
META_CONPRINTF("[KZ::Global] API error does not contain a message: `%s`\n", error.dump().c_str()); | ||
return; | ||
} | ||
|
||
if (!error["message"].is_string()) | ||
{ | ||
META_CONPRINTF("[KZ::Global] API error message is not a string: `%s`\n", error.dump().c_str()); | ||
return; | ||
} | ||
|
||
this->message = error["message"]; | ||
|
||
if (error.contains("details")) | ||
{ | ||
this->details = error["details"]; | ||
} | ||
} | ||
} // namespace KZ::API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <string> | ||
#include "common.h" | ||
#include "utils/json.h" | ||
|
||
namespace KZ::API | ||
{ | ||
/// An error object returned by the API. | ||
struct Error | ||
{ | ||
/// The HTTP status code returned alongside the error. | ||
u16 status; | ||
|
||
/// The error message. | ||
std::string message; | ||
|
||
/// Additional details that may or may not exist. | ||
json details; | ||
|
||
/// Parses an error from a response. | ||
/// | ||
/// If `message` is JSON, it will be deserialized. | ||
Error(u16 status, std::string message); | ||
}; | ||
|
||
/// An error that occurred while parsing JSON. | ||
struct ParseError | ||
{ | ||
/// The reason we failed. | ||
std::string reason; | ||
|
||
ParseError(std::string reason) : reason(reason) {} | ||
}; | ||
} // namespace KZ::API |
Oops, something went wrong.