1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-04-25 13:47:12 +02:00

Adjust some of the miscellaneous functions to use the new method of receiving formatted strings.

This commit is contained in:
Sandu Liviu Catalin 2016-11-16 12:15:46 +02:00
parent c318dbf1da
commit 000133b2ba
3 changed files with 53 additions and 68 deletions

View File

@ -108,9 +108,9 @@ CSStr GetKeyCodeName(Uint8 keycode)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SetKeyCodeName(Uint8 keycode, CSStr name) void SetKeyCodeName(Uint8 keycode, StackStrF & name)
{ {
CS_Keycode_Names[keycode].assign(name); CS_Keycode_Names[keycode].assign(name.mPtr);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -162,15 +162,15 @@ Table GetPluginInfo(Int32 plugin_id)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Int32 FindPlugin(CSStr name) Int32 FindPlugin(StackStrF & name)
{ {
return _Func->FindPlugin(name); return _Func->FindPlugin(name.mPtr);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SendPluginCommand(Uint32 identifier, CSStr payload) void SendPluginCommand(Uint32 identifier, StackStrF & payload)
{ {
_Func->SendPluginCommand(identifier, payload); _Func->SendPluginCommand(identifier, payload.mPtr);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -180,28 +180,12 @@ const ULongInt & GetTime()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQInteger SendLogMessage(HSQUIRRELVM vm) void SendLogMessage(StackStrF & msg)
{ {
const Int32 top = sq_gettop(vm); if (_Func->LogMessage("%s", msg.mPtr) == vcmpErrorTooLargeInput)
// Was the message value specified?
if (top <= 1)
{
return sq_throwerror(vm, "Missing message value");
}
// Attempt to generate the string value
StackStrF val(vm, 2);
// Have we failed to retrieve the string?
if (SQ_FAILED(val.mRes))
{
return val.mRes; // Propagate the error!
}
// Forward the resulted string value
else if (_Func->LogMessage("%s", val.mPtr) == vcmpErrorTooLargeInput)
{ {
STHROWF("Input is too big"); STHROWF("Input is too big");
} }
// This function does not return a value
return 0;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -283,9 +267,9 @@ CSStr GetServerName()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SetServerName(CSStr name) void SetServerName(StackStrF & name)
{ {
_Func->SetServerName(name); _Func->SetServerName(name.mPtr);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -301,9 +285,9 @@ CSStr GetServerPassword()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SetServerPassword(CSStr passwd) void SetServerPassword(StackStrF & passwd)
{ {
_Func->SetServerPassword(passwd); _Func->SetServerPassword(passwd.mPtr);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -319,24 +303,24 @@ CSStr GetGameModeText()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SetGameModeText(CSStr text) void SetGameModeText(StackStrF & text)
{ {
_Func->SetGameModeText(text); _Func->SetGameModeText(text.mPtr);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CreateRadioStream(CSStr name, CSStr url, bool listed) void CreateRadioStream(bool listed, const StackStrF & name, StackStrF & url)
{ {
if (_Func->AddRadioStream(-1, name, url, listed) == vcmpErrorArgumentOutOfBounds) if (_Func->AddRadioStream(-1, name.mPtr, url.mPtr, listed) == vcmpErrorArgumentOutOfBounds)
{ {
STHROWF("Invalid radio stream identifier"); STHROWF("Invalid radio stream identifier");
} }
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CreateRadioStreamEx(Int32 id, CSStr name, CSStr url, bool listed) void CreateRadioStreamEx(Int32 id, bool listed, const StackStrF & name, StackStrF & url)
{ {
if (_Func->AddRadioStream(id, name, url, listed) == vcmpErrorArgumentOutOfBounds) if (_Func->AddRadioStream(id, name.mPtr, url.mPtr, listed) == vcmpErrorArgumentOutOfBounds)
{ {
STHROWF("Invalid radio stream identifier"); STHROWF("Invalid radio stream identifier");
} }
@ -760,27 +744,27 @@ void SetSpawnCameraLookAtEx(Float32 x, Float32 y, Float32 z)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void BanIP(CSStr addr) void BanIP(StackStrF & addr)
{ {
_Func->BanIP(const_cast< SStr >(addr)); _Func->BanIP(const_cast< SStr >(addr.mPtr));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool UnbanIP(CSStr addr) bool UnbanIP(StackStrF & addr)
{ {
return _Func->UnbanIP(const_cast< SStr >(addr)); return _Func->UnbanIP(const_cast< SStr >(addr.mPtr));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool IsIPBanned(CSStr addr) bool IsIPBanned(StackStrF & addr)
{ {
return _Func->IsIPBanned(const_cast< SStr >(addr)); return _Func->IsIPBanned(const_cast< SStr >(addr.mPtr));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Int32 GetPlayerIdFromName(CSStr name) Int32 GetPlayerIdFromName(StackStrF & name)
{ {
return _Func->GetPlayerIdFromName(name); return _Func->GetPlayerIdFromName(name.mPtr);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -15,7 +15,7 @@ CSStr GetKeyCodeName(Uint8 keycode);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Modify the name of a certain key-code. * Modify the name of a certain key-code.
*/ */
void SetKeyCodeName(Uint8 keycode, CSStr name); void SetKeyCodeName(Uint8 keycode, StackStrF & name);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Retrieve the server version. * Retrieve the server version.
@ -40,12 +40,12 @@ Table GetPluginInfo(Int32 plugin_id);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Attempt to find a plug-in identifier by it's name. * Attempt to find a plug-in identifier by it's name.
*/ */
Int32 FindPlugin(CSStr name); Int32 FindPlugin(StackStrF & name);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Send a custom command to the loaded plug-ins. * Send a custom command to the loaded plug-ins.
*/ */
void SendPluginCommand(Uint32 identifier, CSStr payload); void SendPluginCommand(Uint32 identifier, StackStrF & payload);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Retrieve the server time. * Retrieve the server time.
@ -55,7 +55,7 @@ const ULongInt & GetTime();
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Send a log message to the server. * Send a log message to the server.
*/ */
SQInteger SendLogMessage(HSQUIRRELVM vm); void SendLogMessage(StackStrF & msg);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Retrieve the last error that occurred on the server. * Retrieve the last error that occurred on the server.
@ -115,7 +115,7 @@ CSStr GetServerName();
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Modify the server name. * Modify the server name.
*/ */
void SetServerName(CSStr name); void SetServerName(StackStrF & name);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Retrieve the server password. * Retrieve the server password.
@ -125,7 +125,7 @@ CSStr GetServerPassword();
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Modify the server password. * Modify the server password.
*/ */
void SetServerPassword(CSStr passwd); void SetServerPassword(StackStrF & passwd);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Retrieve the game-mode text. * Retrieve the game-mode text.
@ -135,17 +135,17 @@ CSStr GetGameModeText();
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Modify the game-mode text. * Modify the game-mode text.
*/ */
void SetGameModeText(CSStr text); void SetGameModeText(StackStrF & text);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Create a radio stream. * Create a radio stream.
*/ */
void CreateRadioStream(CSStr name, CSStr url, bool listed); void CreateRadioStream(bool listed, const StackStrF & name, StackStrF & url);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Create a radio stream. * Create a radio stream.
*/ */
void CreateRadioStreamEx(Int32 id, CSStr name, CSStr url, bool listed); void CreateRadioStreamEx(Int32 id, bool listed, const StackStrF & name, StackStrF & url);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Remove a radio stream. * Remove a radio stream.
@ -422,22 +422,22 @@ void SetSpawnCameraLookAtEx(Float32 x, Float32 y, Float32 z);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Ban an IP address from the server. * Ban an IP address from the server.
*/ */
void BanIP(CSStr addr); void BanIP(StackStrF & addr);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Unban an IP address from the server. * Unban an IP address from the server.
*/ */
bool UnbanIP(CSStr addr); bool UnbanIP(StackStrF & addr);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* See if an IP address is banned from the server. * See if an IP address is banned from the server.
*/ */
bool IsIPBanned(CSStr addr); bool IsIPBanned(StackStrF & addr);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Retrieve the identifier of the player with the specified name. * Retrieve the identifier of the player with the specified name.
*/ */
Int32 GetPlayerIdFromName(CSStr name); Int32 GetPlayerIdFromName(StackStrF & name);
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* See if a player with the specified identifier is connected. * See if a player with the specified identifier is connected.

View File

@ -56,13 +56,14 @@ void Register_Misc(HSQUIRRELVM vm)
{ {
Table srvns(vm); Table srvns(vm);
srvns.SquirrelFunc(_SC("SendLogMessage"), &SendLogMessage) srvns
.FmtFunc(_SC("SendLogMessage"), &SendLogMessage)
.Func(_SC("GetVersion"), &GetServerVersion) .Func(_SC("GetVersion"), &GetServerVersion)
.Func(_SC("GetSettings"), &GetServerSettings) .Func(_SC("GetSettings"), &GetServerSettings)
.Func(_SC("GetNumberOfPlugins"), &GetNumberOfPlugins) .Func(_SC("GetNumberOfPlugins"), &GetNumberOfPlugins)
.Func(_SC("GetPluginInfo"), &GetPluginInfo) .Func(_SC("GetPluginInfo"), &GetPluginInfo)
.Func(_SC("FindPlugin"), &FindPlugin) .FmtFunc(_SC("FindPlugin"), &FindPlugin)
.Func(_SC("SendPluginCommand"), &SendPluginCommand) .FmtFunc(_SC("SendPluginCommand"), &SendPluginCommand)
.Func(_SC("GetTime"), &GetTime) .Func(_SC("GetTime"), &GetTime)
.Func(_SC("GetLastError"), &GetLastError) .Func(_SC("GetLastError"), &GetLastError)
.Func(_SC("GetPluginVersion"), &GetPluginVersion) .Func(_SC("GetPluginVersion"), &GetPluginVersion)
@ -75,13 +76,13 @@ void Register_Misc(HSQUIRRELVM vm)
.Func(_SC("GetMaxPlayers"), &GetMaxPlayers) .Func(_SC("GetMaxPlayers"), &GetMaxPlayers)
.Func(_SC("SetMaxPlayers"), &SetMaxPlayers) .Func(_SC("SetMaxPlayers"), &SetMaxPlayers)
.Func(_SC("GetServerName"), &GetServerName) .Func(_SC("GetServerName"), &GetServerName)
.Func(_SC("SetServerName"), &SetServerName) .FmtFunc(_SC("SetServerName"), &SetServerName)
.Func(_SC("GetPassword"), &GetServerPassword) .Func(_SC("GetPassword"), &GetServerPassword)
.Func(_SC("SetPassword"), &SetServerPassword) .FmtFunc(_SC("SetPassword"), &SetServerPassword)
.Func(_SC("GetGameModeText"), &GetGameModeText) .Func(_SC("GetGameModeText"), &GetGameModeText)
.Func(_SC("SetGameModeText"), &SetGameModeText) .FmtFunc(_SC("SetGameModeText"), &SetGameModeText)
.Func(_SC("CreateRadioStream"), &CreateRadioStream) .FmtFunc(_SC("CreateRadioStream"), &CreateRadioStream)
.Func(_SC("CreateRadioStreamEx"), &CreateRadioStreamEx) .FmtFunc(_SC("CreateRadioStreamEx"), &CreateRadioStreamEx)
.Func(_SC("RemoveRadioStream"), &RemoveRadioStream) .Func(_SC("RemoveRadioStream"), &RemoveRadioStream)
.Func(_SC("Shutdown"), &ShutdownServer) .Func(_SC("Shutdown"), &ShutdownServer)
.Func(_SC("GetOption"), &GetServerOption) .Func(_SC("GetOption"), &GetServerOption)
@ -136,10 +137,10 @@ void Register_Misc(HSQUIRRELVM vm)
.Func(_SC("SetSpawnPlayerPositionEx"), &SetSpawnPlayerPositionEx) .Func(_SC("SetSpawnPlayerPositionEx"), &SetSpawnPlayerPositionEx)
.Func(_SC("SetSpawnCameraPositionEx"), &SetSpawnCameraPositionEx) .Func(_SC("SetSpawnCameraPositionEx"), &SetSpawnCameraPositionEx)
.Func(_SC("SetSpawnCameraLookAtEx"), &SetSpawnCameraLookAtEx) .Func(_SC("SetSpawnCameraLookAtEx"), &SetSpawnCameraLookAtEx)
.Func(_SC("BanIP"), &BanIP) .FmtFunc(_SC("BanIP"), &BanIP)
.Func(_SC("UnbanIP"), &UnbanIP) .FmtFunc(_SC("UnbanIP"), &UnbanIP)
.Func(_SC("IsIPBanned"), &IsIPBanned) .FmtFunc(_SC("IsIPBanned"), &IsIPBanned)
.Func(_SC("GetPlayerIdFromName"), &GetPlayerIdFromName) .FmtFunc(_SC("GetPlayerIdFromName"), &GetPlayerIdFromName)
.Func(_SC("IsPlayerConnected"), &IsPlayerConnected) .Func(_SC("IsPlayerConnected"), &IsPlayerConnected)
.Func(_SC("ForceAllSelect"), &ForceAllSelect) .Func(_SC("ForceAllSelect"), &ForceAllSelect)
.Func(_SC("CheckEntityExists"), &CheckEntityExists) .Func(_SC("CheckEntityExists"), &CheckEntityExists)
@ -151,7 +152,7 @@ void Register_Misc(HSQUIRRELVM vm)
RootTable(vm) RootTable(vm)
.Func(_SC("FindPlayer"), &FindPlayer) .Func(_SC("FindPlayer"), &FindPlayer)
.Func(_SC("GetKeyCodeName"), &GetKeyCodeName) .Func(_SC("GetKeyCodeName"), &GetKeyCodeName)
.Func(_SC("SetKeyCodeName"), &SetKeyCodeName) .FmtFunc(_SC("SetKeyCodeName"), &SetKeyCodeName)
.Func(_SC("GetModelName"), &GetModelName) .Func(_SC("GetModelName"), &GetModelName)
.Func(_SC("SetModelName"), &SetModelName) .Func(_SC("SetModelName"), &SetModelName)
.Func(_SC("IsModelWeapon"), &IsModelWeapon) .Func(_SC("IsModelWeapon"), &IsModelWeapon)