PREDEFINED = \
"USING(name, T)=using name = T" \
"CLASS(name, base)=class name : public base { public:" \
+ "INIT(class)=class::class()" \
"CONSTRUCTOR(class)=class::class(" \
"DESTRUCTOR(class)=class::~class()" \
"ATTRIB(class, name, T, val)=T name = val;" \
EXPAND_AS_DEFINED = \
USING \
CLASS \
- CONSTRUCTOR \
- DESTRUCTOR \
+ INIT CONSTRUCTOR DESTRUCTOR \
ATTRIB ATTRIB_STRZONE \
STATIC_ATTRIB STATIC_ATTRIB_STRZONE \
METHOD \
// self
void RestoreGame();
+// Called when a client connects to the server
// input:
// time
// self
// parm1..n
void ClientConnect();
+// Called when a client spawns in the server
// input:
// time
// self
// Classes have a `spawn##cname(entity)` constructor
// The parameter is used across [[accumulate]] functions
+.bool transmute;
+
// Macros to hide this implementation detail:
#ifdef __STDC__
#define NEW(cname, ...) \
OVERLOAD_(spawn##cname, new_pure(cname) P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
+
+ #define TRANSMUTE(cname, this, ...) \
+ OVERLOAD_(spawn##cname, (this.transmute = true, this.classname = #cname, this) P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
+
#define CONSTRUCT(cname, ...) \
OVERLOAD_(spawn##cname, this P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
#else
#define NEW(cname, ...) \
OVERLOAD(spawn##cname, new_pure(cname),##__VA_ARGS__)
+ #define TRANSMUTE(cname, this, ...) \
+ OVERLOAD(spawn##cname, (this.transmute = true, this.classname = #cname, this),##__VA_ARGS__)
+
#define CONSTRUCT(cname, ...) \
OVERLOAD(spawn##cname, this,##__VA_ARGS__)
#endif
#define CLASS(cname, base) \
entityclass(cname, base); \
- class(cname).bool instanceOf##cname; \
+ class(cname).bool instanceOf##cname; \
bool is_##cname(entity e) { return e.instanceOf##cname; } \
VTBL(cname, base) \
- _INIT_STATIC(cname) \
- { \
- if (cname##_vtbl) \
- { \
+ _INIT_STATIC(cname) \
+ { \
+ if (cname##_vtbl && !this.transmute)\
+ { \
copyentity(cname##_vtbl, this); \
return; \
} \
spawn##base##_static(this); \
this.instanceOf##cname = true; \
} \
- INIT(cname) \
- { \
+ INIT(cname) \
+ { \
/* Only statically initialize the current class, it contains everything it inherits */ \
if (cname##_vtbl.vtblname == this.classname) \
- { \
+ { \
spawn##cname##_static(this); \
+ this.transmute = false; \
this.classname = #cname; \
this.vtblname = string_null; \
this.vtblbase = cname##_vtbl; \
#define IS_OBSERVER(v) ((v).classname == STR_OBSERVER)
#define IS_CLIENT(v) (v.flags & FL_CLIENT)
-#define is_Client IS_CLIENT
#define IS_BOT_CLIENT(v) (clienttype(v) == CLIENTTYPE_BOT)
#define IS_REAL_CLIENT(v) (clienttype(v) == CLIENTTYPE_REAL)
#define IS_NOT_A_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT)
if (Ban_MaybeEnforceBanOnce(this)) return;
assert(!IS_CLIENT(this), return);
assert(player_count >= 0, player_count = 0);
+ TRANSMUTE(Client, this);
this.classname = "player_joining";
- this.flags = FL_CLIENT;
#ifdef WATERMARK
Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_WATERMARK, WATERMARK);
#pragma once
+CLASS(Client, Object)
+ /** Client name */
+ ATTRIB(Client, netname, string, this.netname)
+ ATTRIB(Client, colormap, int, this.colormap)
+ ATTRIB(Client, team, int, this.team)
+ ATTRIB(Client, clientcolors, int, this.clientcolors)
+ /** Client IP */
+ ATTRIB(Client, netaddress, string, this.netaddress)
+ ATTRIB(Client, playermodel, string, this.playermodel)
+ ATTRIB(Client, playerskin, int, this.playerskin)
+
+ /** fingerprint of CA key the player used to authenticate */
+ ATTRIB(Client, crypto_keyfp, string, this.crypto_keyfp)
+ /** fingerprint of CA key the server used to authenticate to the player */
+ ATTRIB(Client, crypto_mykeyfp, string, this.crypto_mykeyfp)
+ /** fingerprint of ID used by the player entity, or string_null if not identified */
+ ATTRIB(Client, crypto_idfp, string, this.crypto_idfp)
+ /** set if the player's ID has been signed */
+ ATTRIB(Client, crypto_idfp_signed, bool, this.crypto_idfp_signed)
+ /** the string "AES128" if encrypting, and string_null if plaintext */
+ ATTRIB(Client, crypto_encryptmethod, string, this.crypto_encryptmethod)
+ /** the string "HMAC-SHA256" if signing, and string_null if plaintext */
+ ATTRIB(Client, crypto_signmethod, string, this.crypto_signmethod)
+ INIT(Client) {
+ this.flags = FL_CLIENT;
+ }
+ENDCLASS(Client)
+
float c1, c2, c3, c4;
void play_countdown(float finished, Sound samp);