Add update shop & owner, get shop, better error handling
This commit is contained in:
parent
083c6a7f6e
commit
c42b29af5d
@ -33,3 +33,37 @@ bool CreateOwner(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedS
|
||||
thread.detach();
|
||||
return true;
|
||||
}
|
||||
|
||||
int UpdateOwnerImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::BSFixedString name, uint32_t mod_version, RE::TESQuest* quest)
|
||||
{
|
||||
logger::info("Entered UpdateOwnerImpl");
|
||||
if (!quest) {
|
||||
logger::error("UpdateOwner quest is null!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SKSE::RegistrationMap<int> regMap = SKSE::RegistrationMap<int>();
|
||||
regMap.Register(quest, RE::BSFixedString("OnUpdateOwner"));
|
||||
|
||||
logger::info(FMT_STRING("UpdateOwner api_url: {}"), api_url);
|
||||
logger::info(FMT_STRING("UpdateOwner api_key: {}"), api_key);
|
||||
logger::info(FMT_STRING("UpdateOwner name: {}"), name);
|
||||
logger::info(FMT_STRING("UpdateOwner mod_version: {}"), mod_version);
|
||||
int owner_id = update_owner(api_url.c_str(), api_key.c_str(), id, name.c_str(), mod_version);
|
||||
logger::info(FMT_STRING("UpdateOwner result: {}"), owner_id);
|
||||
regMap.SendEvent(owner_id);
|
||||
regMap.Unregister(quest);
|
||||
return owner_id;
|
||||
}
|
||||
|
||||
bool UpdateOwner(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::BSFixedString name, uint32_t mod_version, RE::TESQuest* quest) {
|
||||
logger::info("Entered CreateOwner");
|
||||
if (!quest) {
|
||||
logger::error("UpdateOwner quest is null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::thread thread(UpdateOwnerImpl, api_url, api_key, id, name, mod_version, quest);
|
||||
thread.detach();
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
bool CreateOwner(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, RE::BSFixedString name, uint32_t mod_version, RE::TESQuest* quest);
|
||||
bool UpdateOwner(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::BSFixedString name, uint32_t mod_version, RE::TESQuest* quest);
|
||||
|
114
src/BRShop.cpp
114
src/BRShop.cpp
@ -1,25 +1,35 @@
|
||||
#include "bindings.h"
|
||||
|
||||
int CreateShopImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest)
|
||||
void CreateShopImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest)
|
||||
{
|
||||
logger::info("Entered CreateShopImpl");
|
||||
if (!quest) {
|
||||
logger::error("CreateShop quest is null!");
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
SKSE::RegistrationMap<int> regMap = SKSE::RegistrationMap<int>();
|
||||
regMap.Register(quest, RE::BSFixedString("OnCreateShop"));
|
||||
SKSE::RegistrationMap<int, RE::BSFixedString, RE::BSFixedString> successReg = SKSE::RegistrationMap<int, RE::BSFixedString, RE::BSFixedString>();
|
||||
successReg.Register(quest, RE::BSFixedString("OnCreateShopSuccess"));
|
||||
SKSE::RegistrationMap<RE::BSFixedString> failReg = SKSE::RegistrationMap<RE::BSFixedString>();
|
||||
failReg.Register(quest, RE::BSFixedString("OnCreateShopFail"));
|
||||
|
||||
logger::info(FMT_STRING("CreateShop api_url: {}"), api_url);
|
||||
logger::info(FMT_STRING("CreateShop api_key: {}"), api_key);
|
||||
logger::info(FMT_STRING("CreateShop name: {}"), name);
|
||||
logger::info(FMT_STRING("CreateShop description: {}"), description);
|
||||
int shop_id = create_shop(api_url.c_str(), api_key.c_str(), name.c_str(), description.c_str());
|
||||
logger::info(FMT_STRING("CreateShop result: {}"), shop_id);
|
||||
regMap.SendEvent(shop_id);
|
||||
regMap.Unregister(quest);
|
||||
return shop_id;
|
||||
FFIResult<ShopRecord> result = create_shop(api_url.c_str(), api_key.c_str(), name.c_str(), description.c_str());
|
||||
if (result.IsOk()) {
|
||||
ShopRecord shop = result.AsOk();
|
||||
logger::info(FMT_STRING("CreateShop result Ok: {:d}"), shop.id);
|
||||
successReg.SendEvent(shop.id, RE::BSFixedString(shop.name), RE::BSFixedString(shop.description));
|
||||
}
|
||||
else {
|
||||
const char* error = result.AsErr();
|
||||
logger::error(FMT_STRING("CreateShop result Err: {}"), error);
|
||||
failReg.SendEvent(RE::BSFixedString(error));
|
||||
}
|
||||
successReg.Unregister(quest);
|
||||
failReg.Unregister(quest);
|
||||
}
|
||||
|
||||
bool CreateShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest) {
|
||||
@ -33,3 +43,89 @@ bool CreateShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedSt
|
||||
thread.detach();
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdateShopImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest)
|
||||
{
|
||||
logger::info("Entered UpdateShopImpl");
|
||||
if (!quest) {
|
||||
logger::error("UpdateShop quest is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
SKSE::RegistrationMap<int, RE::BSFixedString, RE::BSFixedString> successReg = SKSE::RegistrationMap<int, RE::BSFixedString, RE::BSFixedString>();
|
||||
successReg.Register(quest, RE::BSFixedString("OnUpdateShopSuccess"));
|
||||
SKSE::RegistrationMap<RE::BSFixedString> failReg = SKSE::RegistrationMap<RE::BSFixedString>();
|
||||
failReg.Register(quest, RE::BSFixedString("OnUpdateShopFail"));
|
||||
|
||||
logger::info(FMT_STRING("UpdateShop api_url: {}"), api_url);
|
||||
logger::info(FMT_STRING("UpdateShop api_key: {}"), api_key);
|
||||
logger::info(FMT_STRING("UpdateShop name: {}"), name);
|
||||
logger::info(FMT_STRING("UpdateShop description: {}"), description);
|
||||
FFIResult<ShopRecord> result = update_shop(api_url.c_str(), api_key.c_str(), id, name.c_str(), description.c_str());
|
||||
if (result.IsOk()) {
|
||||
ShopRecord shop = result.AsOk();
|
||||
logger::info(FMT_STRING("UpdateShop result Ok: {:d}"), shop.id);
|
||||
successReg.SendEvent(shop.id, RE::BSFixedString(shop.name), RE::BSFixedString(shop.description));
|
||||
}
|
||||
else {
|
||||
const char* error = result.AsErr();
|
||||
logger::error(FMT_STRING("UpdateShop result Err: {}"), error);
|
||||
failReg.SendEvent(RE::BSFixedString(error));
|
||||
}
|
||||
successReg.Unregister(quest);
|
||||
failReg.Unregister(quest);
|
||||
}
|
||||
|
||||
bool UpdateShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest) {
|
||||
logger::info("Entered UpdateShop");
|
||||
if (!quest) {
|
||||
logger::error("UpdateShop quest is null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::thread thread(UpdateShopImpl, api_url, api_key, id, name, description, quest);
|
||||
thread.detach();
|
||||
return true;
|
||||
}
|
||||
|
||||
void GetShopImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::TESQuest* quest)
|
||||
{
|
||||
logger::info("Entered GetShopImpl");
|
||||
if (!quest) {
|
||||
logger::error("GetShop quest is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
SKSE::RegistrationMap<int, RE::BSFixedString, RE::BSFixedString> successReg = SKSE::RegistrationMap<int, RE::BSFixedString, RE::BSFixedString>();
|
||||
successReg.Register(quest, RE::BSFixedString("OnGetShopSuccess"));
|
||||
SKSE::RegistrationMap<RE::BSFixedString> failReg = SKSE::RegistrationMap<RE::BSFixedString>();
|
||||
failReg.Register(quest, RE::BSFixedString("OnGetShopFail"));
|
||||
|
||||
logger::info(FMT_STRING("GetShop api_url: {}"), api_url);
|
||||
logger::info(FMT_STRING("GetShop api_key: {}"), api_key);
|
||||
FFIResult<ShopRecord> result = get_shop(api_url.c_str(), api_key.c_str(), id);
|
||||
if (result.IsOk()) {
|
||||
ShopRecord shop = result.AsOk();
|
||||
logger::info(FMT_STRING("GetShop result Ok: {:d}"), shop.id);
|
||||
successReg.SendEvent(shop.id, RE::BSFixedString(shop.name), RE::BSFixedString(shop.description));
|
||||
}
|
||||
else {
|
||||
const char* error = result.AsErr();
|
||||
logger::error(FMT_STRING("GetShop result Err: {}"), error);
|
||||
failReg.SendEvent(RE::BSFixedString(error));
|
||||
}
|
||||
successReg.Unregister(quest);
|
||||
failReg.Unregister(quest);
|
||||
}
|
||||
|
||||
bool GetShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::TESQuest* quest) {
|
||||
logger::info("Entered GetShop");
|
||||
if (!quest) {
|
||||
logger::error("GetShop quest is null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::thread thread(GetShopImpl, api_url, api_key, id, quest);
|
||||
thread.detach();
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
bool CreateShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest);
|
||||
bool UpdateShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::BSFixedString name, RE::BSFixedString description, RE::TESQuest* quest);
|
||||
bool GetShop(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t id, RE::TESQuest* quest);
|
||||
|
@ -13,7 +13,10 @@ bool RegisterFuncs(RE::BSScript::IVirtualMachine* a_vm)
|
||||
a_vm->RegisterFunction("StatusCheck", "BRClient", StatusCheck);
|
||||
a_vm->RegisterFunction("GenerateApiKey", "BRClient", GenerateApiKey);
|
||||
a_vm->RegisterFunction("Create", "BROwner", CreateOwner);
|
||||
a_vm->RegisterFunction("Update", "BROwner", UpdateOwner);
|
||||
a_vm->RegisterFunction("Create", "BRShop", CreateShop);
|
||||
a_vm->RegisterFunction("Update", "BRShop", UpdateShop);
|
||||
a_vm->RegisterFunction("Get", "BRShop", GetShop);
|
||||
a_vm->RegisterFunction("Create", "BRInteriorRefList", CreateInteriorRefList);
|
||||
a_vm->RegisterFunction("ClearCell", "BRInteriorRefList", ClearCell);
|
||||
a_vm->RegisterFunction("Load", "BRInteriorRefList", LoadInteriorRefList);
|
||||
|
Loading…
Reference in New Issue
Block a user