Skip to content

Commit ccd4810

Browse files
committed
Crash fix and Server class
1 parent 4b262ef commit ccd4810

File tree

4 files changed

+50
-47
lines changed

4 files changed

+50
-47
lines changed

VCMP-LUA/vcmpWrap/Classes/Bind.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include "Bind.h"
22

33
extern PluginFuncs* g_Funcs;
4+
extern sol::state Lua;
45

56
std::vector<Bind*> Bind::s_Binds;
67

78
void Bind::clearAllBinds() {
89
g_Funcs->RemoveAllKeyBinds();
10+
s_Binds.clear();
911
}
1012

1113
void Bind::Register(Bind* bind) {
@@ -58,8 +60,10 @@ sol::table Bind::getData() const {
5860
sol::table data;
5961
int32_t key1, key2, key3;
6062
uint8_t signalsOnRelease;
61-
g_Funcs->GetKeyBindData(m_ID, &signalsOnRelease, &key1, &key2, &key3);
63+
if (g_Funcs->GetKeyBindData(m_ID, &signalsOnRelease, &key1, &key2, &key3) == vcmpError::vcmpErrorNoSuchEntity)
64+
return sol::nil;
6265

66+
data = Lua.create_table();
6367
data["keyOne"] = key1;
6468
data["keyTwo"] = key2;
6569
data["keyThree"] = key3;
@@ -91,6 +95,7 @@ void Bind::Init(sol::state* L) {
9195
userdata["type"] = &Bind::getStaticType;
9296
userdata["findByID"] = &Bind::Get;
9397
userdata["findByTag"] = &Bind::GetByTag;
98+
userdata["clearAllBinds"] = &Bind::clearAllBinds;
9499

95100
/*** METHODS ***/
96101

VCMP-LUA/vcmpWrap/Classes/Server.cpp

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,15 @@
33
extern PluginFuncs* g_Funcs;
44
extern sol::state Lua;
55

6-
optionUMType Server::s_OptionCode = {
7-
{"DeathMessages", vcmpServerOption::vcmpServerOptionDeathMessages},
8-
{"DriveBy", vcmpServerOption::vcmpServerOptionDisableDriveBy},
9-
{"DriveOnWater", vcmpServerOption::vcmpServerOptionDriveOnWater},
10-
{"FastSwitch", vcmpServerOption::vcmpServerOptionFastSwitch},
11-
{"FlyingCars", vcmpServerOption::vcmpServerOptionFlyingCars},
12-
{"FrameLimit", vcmpServerOption::vcmpServerOptionFrameLimiter},
13-
{"FriendlyFire", vcmpServerOption::vcmpServerOptionFriendlyFire},
14-
{"JoinMessages", vcmpServerOption::vcmpServerOptionJoinMessages},
15-
{"JumpSwitch", vcmpServerOption::vcmpServerOptionJumpSwitch},
16-
{"ShootInAir", vcmpServerOption::vcmpServerOptionShootInAir},
17-
{"Nametags", vcmpServerOption::vcmpServerOptionShowNameTags},
18-
{"TeamMarkersOnly", vcmpServerOption::vcmpServerOptionOnlyShowTeamMarkers},
19-
{"StuntBike", vcmpServerOption::vcmpServerOptionStuntBike},
20-
{"SyncFrameLimiter", vcmpServerOption::vcmpServerOptionSyncFrameLimiter},
21-
{"TaxiBoostJump", vcmpServerOption::vcmpServerOptionTaxiBoostJump},
22-
{"WallGlitch", vcmpServerOption::vcmpServerOptionWallGlitch},
23-
{"DeathMessages", vcmpServerOption::vcmpServerOptionDeathMessages},
24-
{"Classes", vcmpServerOption::vcmpServerOptionUseClasses},
25-
{"ChatTags", vcmpServerOption::vcmpServerOptionChatTagsEnabled},
26-
{"BackfaceCulling", vcmpServerOption::vcmpServerOptionDisableBackfaceCulling},
27-
{"HeliBladeDamage", vcmpServerOption::vcmpServerOptionDisableHeliBladeDamage},
28-
{"PerfectHandling", vcmpServerOption::vcmpServerOptionPerfectHandling},
29-
{"Markers", vcmpServerOption::vcmpServerOptionShowMarkers}
30-
};
31-
326
static ServerSettings s_Settings;
337

34-
bool Server::getOption(const std::string& option) {
35-
if (s_OptionCode.find(option) != s_OptionCode.end()) {
36-
return g_Funcs->GetServerOption(s_OptionCode[option]);
37-
}
38-
return false;
8+
bool Server::getOption(vcmpServerOption option) {
9+
return g_Funcs->GetServerOption(option);
3910
}
4011

41-
bool Server::setOption(const std::string& option, bool toggle) {
42-
if (s_OptionCode.find(option) != s_OptionCode.end()) {
43-
g_Funcs->SetServerOption(s_OptionCode[option], toggle);
44-
return true;
45-
}
46-
return false;
12+
bool Server::setOption(vcmpServerOption option, bool toggle) {
13+
g_Funcs->SetServerOption(option, toggle);
14+
return true;
4715
}
4816

4917
sol::object Server::getSettings() {
@@ -53,15 +21,17 @@ sol::object Server::getSettings() {
5321
}
5422
sol::table settings = Lua.create_table();
5523

56-
settings["maxPlayers"] = s_Settings.maxPlayers;;
24+
settings["maxPlayers"] = s_Settings.maxPlayers;
5725
settings["port"] = s_Settings.port;
5826
settings["serverName"] = std::string(s_Settings.serverName);
27+
settings["flags"] = s_Settings.flags;
5928

6029
return settings;
6130
}
6231

6332
void Server::Init(sol::state* L) {
6433
sol::state& state = *L;
6534
L->set("Server", L->create_table_with("getSettings", &Server::getSettings));
66-
state["Server"]["option"] = sol::property(&Server::getOption, &Server::setOption);
35+
state["Server"]["getOption"] = &Server::getOption;
36+
state["Server"]["setOption"] = &Server::setOption;
6737
}

VCMP-LUA/vcmpWrap/Classes/Server.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#pragma once
22
#include "pch.h"
33

4-
typedef std::unordered_map<std::string, vcmpServerOption> optionUMType;
5-
64
class Server {
75
public:
86
static void Init(sol::state*);
97

108
private:
11-
static bool getOption(const std::string& option);
12-
static bool setOption(const std::string& option, bool toggle);
9+
static bool getOption(vcmpServerOption option);
10+
static bool setOption(vcmpServerOption option, bool toggle);
1311
static sol::object getSettings();
14-
15-
public:
16-
static optionUMType s_OptionCode;
1712
};

VCMP-LUA/vcmpWrap/globalTables.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,33 @@ void RegisterClasses(sol::state* Lua) {
8282
}
8383

8484
void InitGlobals(sol::state* Lua) {
85+
/*** GENERIC CONSTANTS ***/
86+
Lua->new_enum("ServerOption",
87+
"deathMessages", vcmpServerOption::vcmpServerOptionDeathMessages,
88+
"driveBy", vcmpServerOption::vcmpServerOptionDisableDriveBy,
89+
"driveOnWater", vcmpServerOption::vcmpServerOptionDriveOnWater,
90+
"fastSwitch", vcmpServerOption::vcmpServerOptionFastSwitch,
91+
"flyingCars", vcmpServerOption::vcmpServerOptionFlyingCars,
92+
"frameLimit", vcmpServerOption::vcmpServerOptionFrameLimiter,
93+
"friendlyFire", vcmpServerOption::vcmpServerOptionFriendlyFire,
94+
"joinMessages", vcmpServerOption::vcmpServerOptionJoinMessages,
95+
"jumpSwitch", vcmpServerOption::vcmpServerOptionJumpSwitch,
96+
"shootInAir", vcmpServerOption::vcmpServerOptionShootInAir,
97+
"nametags", vcmpServerOption::vcmpServerOptionShowNameTags,
98+
"teamMarkersOnly", vcmpServerOption::vcmpServerOptionOnlyShowTeamMarkers,
99+
"stuntBike", vcmpServerOption::vcmpServerOptionStuntBike,
100+
"syncFrameLimiter", vcmpServerOption::vcmpServerOptionSyncFrameLimiter,
101+
"taxiBoostJump", vcmpServerOption::vcmpServerOptionTaxiBoostJump,
102+
"wallGlitch", vcmpServerOption::vcmpServerOptionWallGlitch,
103+
"deathMessages", vcmpServerOption::vcmpServerOptionDeathMessages,
104+
"classes", vcmpServerOption::vcmpServerOptionUseClasses,
105+
"chatTags", vcmpServerOption::vcmpServerOptionChatTagsEnabled,
106+
"backfaceCulling", vcmpServerOption::vcmpServerOptionDisableBackfaceCulling,
107+
"heliBladeDamage", vcmpServerOption::vcmpServerOptionDisableHeliBladeDamage,
108+
"perfectHandling", vcmpServerOption::vcmpServerOptionPerfectHandling,
109+
"showMarkers", vcmpServerOption::vcmpServerOptionShowMarkers
110+
);
111+
85112
Lua->new_enum("DisconnectReason",
86113
"timeout", vcmpDisconnectReason::vcmpDisconnectReasonTimeout,
87114
"quit", vcmpDisconnectReason::vcmpDisconnectReasonQuit,
@@ -105,6 +132,8 @@ void InitGlobals(sol::state* Lua) {
105132
"inVehicle", vcmpBodyPart::vcmpBodyPartInVehicle
106133
);
107134

135+
/*** PLAYER CONSTANTS ***/
136+
108137
Lua->new_enum("PlayerState",
109138
"none", vcmpPlayerState::vcmpPlayerStateNone,
110139
"normal", vcmpPlayerState::vcmpPlayerStateNormal,
@@ -140,6 +169,8 @@ void InitGlobals(sol::state* Lua) {
140169
"drunkEffects", vcmpPlayerOption::vcmpPlayerOptionDrunkEffects
141170
);
142171

172+
/*** VEHICLE CONSTANTS ***/
173+
143174
Lua->new_enum("VehicleUpdate",
144175
"driverSync", vcmpVehicleUpdate::vcmpVehicleUpdateDriverSync,
145176
"otherSync", vcmpVehicleUpdate::vcmpVehicleUpdateOtherSync,
@@ -169,6 +200,8 @@ void InitGlobals(sol::state* Lua) {
169200
"turnRelative", vcmpVehicleSpeed::TurnRelative
170201
);
171202

203+
/*** PICKUP CONSTANTS ***/
204+
172205
Lua->new_enum("PickupOption",
173206
"singleUse", vcmpPickupOption::vcmpPickupOptionSingleUse,
174207
"forceSize", vcmpPickupOption::forceSizeVcmpPickupOption

0 commit comments

Comments
 (0)