forked from hereisderek/SourceMod.js
/
SMJS_Client.cpp
96 lines (77 loc) · 2.47 KB
/
SMJS_Client.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "SMJS_Client.h"
#include "SMJS_Plugin.h"
WRAPPED_CLS_CPP(SMJS_Client, SMJS_Entity)
SMJS_Client::SMJS_Client(edict_t *edict) : SMJS_Entity(NULL) {
this->edict = edict;
inGame = false;
authStage = 0;
entIndex = gamehelpers->IndexOfEdict(edict);
}
void SMJS_Client::OnWrapperAttached(SMJS_Plugin *plugin, v8::Persistent<v8::Value> wrapper){
SMJS_Entity::OnWrapperAttached(plugin, wrapper);
}
void SMJS_Client::ReattachEntity(){
auto tmp = edict->GetNetworkable();
if(tmp != NULL){
SetEntity(tmp->GetBaseEntity());
}
}
FUNCTION_M(SMJS_Client::printToChat)
GET_INTERNAL(SMJS_Client*, self);
if(!self->valid) THROW("Invalid entity");
PSTR(str);
gamehelpers->TextMsg(self->entIndex, TEXTMSG_DEST_CHAT, *str);
RETURN_UNDEF;
END
FUNCTION_M(SMJS_Client::printToConsole)
GET_INTERNAL(SMJS_Client*, self);
if(!self->valid) THROW("Invalid entity");
PSTR(str);
gamehelpers->TextMsg(self->entIndex, TEXTMSG_DEST_CONSOLE, *str);
RETURN_UNDEF;
END
FUNCTION_M(SMJS_Client::isInGame)
GET_INTERNAL(SMJS_Client*, self);
if(!self->valid) return v8::Boolean::New(false);
return v8::Boolean::New(self->inGame);
END
FUNCTION_M(SMJS_Client::isFake)
GET_INTERNAL(SMJS_Client*, self);
if(self->edict == NULL) THROW("Invalid edict");
return v8::Boolean::New(playerhelpers->GetGamePlayer(self->edict)->IsFakeClient());
END
FUNCTION_M(SMJS_Client::isReplay)
GET_INTERNAL(SMJS_Client*, self);
if(self->edict == NULL) THROW("Invalid edict");
return v8::Boolean::New(playerhelpers->GetGamePlayer(self->edict)->IsReplay());
END
FUNCTION_M(SMJS_Client::isSourceTV)
GET_INTERNAL(SMJS_Client*, self);
if(self->edict == NULL) THROW("Invalid edict");
return v8::Boolean::New(playerhelpers->GetGamePlayer(self->edict)->IsSourceTV());
END
FUNCTION_M(SMJS_Client::fakeCommand)
GET_INTERNAL(SMJS_Client*, self);
if(!self->valid) THROW("Invalid entity");
PSTR(str);
engine->ClientCommand(self->edict, *str);
RETURN_UNDEF;
END
FUNCTION_M(SMJS_Client::getAuthString)
GET_INTERNAL(SMJS_Client*, self);
if(self->edict == NULL) THROW("Invalid edict");
return v8::String::New(engine->GetPlayerNetworkIDString(self->edict));
END
FUNCTION_M(SMJS_Client::kick)
GET_INTERNAL(SMJS_Client*, self);
if(!self->valid) THROW("Invalid entity");
PSTR(str);
char *kickReason = new char[str.length() + 1];
strcpy(kickReason, *str);
auto gameplayer = playerhelpers->GetGamePlayer(self->edict);
if(gameplayer == NULL){
THROW("Client cannot be kicked at this time");
}
gameplayer->Kick(kickReason);
RETURN_UNDEF;
END