-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSFS3_API.cpp
More file actions
1677 lines (1422 loc) · 57.8 KB
/
SFS3_API.cpp
File metadata and controls
1677 lines (1422 loc) · 57.8 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* SFS3 API — C++ bridge implementation
*
* Bridges the public C API (SFS3_API.h) to the hxcpp-generated Haxe classes.
* Compiled together with the hxcpp output and merged into SFS3_API.lib.
*
* BUILD NOTE: The compiler must force-include the generated HxcppConfig
* header (e.g. /FI"HxcppConfig-19.h") so that platform macros like
* HX_WINDOWS are defined before hxcpp.h is pulled in. The build_lib
* script handles this automatically.
*/
#if defined(_M_ARM64) && !defined(HXCPP_ARM64)
#define HXCPP_ARM64
#endif
#include <hxcpp.h>
#include <hx/GC.h>
#include <hx/Boot.h>
#include <com/smartfoxserver/v3/SmartFox.h>
#include <com/smartfoxserver/v3/ConfigData.h>
#include <com/smartfoxserver/v3/BlueBoxCfg.h>
#include <com/smartfoxserver/v3/core/ApiEvent.h>
#include <com/smartfoxserver/v3/core/EventDispatcher.h>
#include <com/smartfoxserver/v3/core/Logger.h>
#include <com/smartfoxserver/v3/entities/data/SFSObject.h>
#include <com/smartfoxserver/v3/entities/data/SFSArray.h>
#include <com/smartfoxserver/v3/requests/LoginRequest.h>
#include <com/smartfoxserver/v3/requests/LogoutRequest.h>
#include <com/smartfoxserver/v3/requests/JoinRoomRequest.h>
#include <com/smartfoxserver/v3/requests/LeaveRoomRequest.h>
#include <com/smartfoxserver/v3/requests/PublicMessageRequest.h>
#include <com/smartfoxserver/v3/requests/PrivateMessageRequest.h>
#include <com/smartfoxserver/v3/requests/ObjectMessageRequest.h>
#include <com/smartfoxserver/v3/bitswarm/TransportType.h>
#include <com/smartfoxserver/v3/requests/ExtensionRequest.h>
#include <com/smartfoxserver/v3/requests/SubscribeRoomGroupRequest.h>
#include <com/smartfoxserver/v3/requests/UnsubscribeRoomGroupRequest.h>
#include <com/smartfoxserver/v3/requests/SetRoomVariablesRequest.h>
#include <com/smartfoxserver/v3/requests/SetUserVariablesRequest.h>
#include <com/smartfoxserver/v3/entities/variables/SFSRoomVariable.h>
#include <com/smartfoxserver/v3/entities/variables/SFSUserVariable.h>
#include <com/smartfoxserver/v3/entities/SFSRoom.h>
#include "SFS3_API.h"
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <mutex>
/* ── hxcpp runtime entry points ──────────────────────────────────────── */
extern void __boot_all();
extern "C" {
void __hxcpp_main() {}
void __hxcpp_lib_main() {
HX_TOP_OF_STACK
hx::Boot();
__boot_all();
__hxcpp_main();
}
}
/*
* hxcpp only exports hxRunLibrary / hxcpp_set_top_of_stack when compiled
* in library mode (HXCPP_DLL_IMPORT). Our static lib is built in exe
* mode, so we provide equivalent helpers ourselves.
*/
static void sfs3_set_top_of_stack() {
int i;
hx::SetTopOfStack(&i, false);
}
static void sfs3_run_library() {
__hxcpp_lib_main();
}
/*
* Stack-boundary macros — nesting-safe.
*
* Every API function that touches hxcpp objects must bracket the hxcpp
* calls with SFS3_HX_BEGIN / SFS3_HX_END so the GC can walk the stack.
*
* Problem: if a user callback (dispatched from SFS3_update, which already
* holds HX_BEGIN) calls another SFS3 function (e.g. sendLogin), the inner
* SFS3_HX_END would call SetTopOfStack(nullptr) and deregister the thread
* from the GC while the outer block still accesses hxcpp objects.
*
* Fix: thread-local depth counter. Only the outermost pair actually
* calls SetTopOfStack; nested pairs are no-ops.
*
* The NOINLINE attribute prevents the compiler from inlining the caller
* and optimising away the stack variable whose address we hand to
* SetTopOfStack (pattern borrowed from the Loreline C++ bridge).
*/
#if defined(_MSC_VER)
#define SFS3_NOINLINE __declspec(noinline)
#else
#define SFS3_NOINLINE __attribute__((noinline))
#endif
static thread_local int g_hxDepth = 0;
#define SFS3_HX_BEGIN \
int _sfs3_stack_ = 99; \
if (g_hxDepth++ == 0) \
hx::SetTopOfStack(&_sfs3_stack_, true);
#define SFS3_HX_END \
if (--g_hxDepth == 0) \
hx::SetTopOfStack((int*)0, true);
/* ── SFS3_String ────────────────────────────────────────────────────────── */
struct SFS3_StringData {
::String hxStr;
int refCount;
};
static SFS3_String wrap_string(::String s) {
SFS3_String r;
if (s == null()) {
r.ptr = nullptr;
} else {
r.ptr = new SFS3_StringData();
r.ptr->hxStr = s;
r.ptr->refCount = 1;
}
return r;
}
static ::String unwrap_string(SFS3_String s) {
if (s.ptr == nullptr) return null();
return s.ptr->hxStr;
}
SFS3_String SFS3_String_create(const char* s) {
if (!s) { SFS3_String r; r.ptr = nullptr; return r; }
return wrap_string(::String(s));
}
SFS3_String SFS3_String_createLen(const char* s, size_t len) {
if (!s) { SFS3_String r; r.ptr = nullptr; return r; }
return wrap_string(::String(s, (int)len));
}
SFS3_String SFS3_String_copy(SFS3_String other) {
if (other.ptr) {
other.ptr->refCount++;
}
return other;
}
void SFS3_String_release(SFS3_String* s) {
if (s && s->ptr) {
s->ptr->refCount--;
if (s->ptr->refCount <= 0) {
delete s->ptr;
}
s->ptr = nullptr;
}
}
const char* SFS3_String_cstr(SFS3_String s) {
if (!s.ptr) return nullptr;
return s.ptr->hxStr.utf8_str();
}
size_t SFS3_String_length(SFS3_String s) {
if (!s.ptr) return 0;
return (size_t)s.ptr->hxStr.length;
}
bool SFS3_String_isNull(SFS3_String s) {
return s.ptr == nullptr;
}
/* ── SFS3_Value ─────────────────────────────────────────────────────────── */
SFS3_Value SFS3_Value_null(void) {
SFS3_Value v;
memset(&v, 0, sizeof(v));
v.type = SFS3_Null;
v.stringValue.ptr = nullptr;
v.userValue = nullptr;
v.roomValue = nullptr;
v.objectValue = nullptr;
return v;
}
SFS3_Value SFS3_Value_fromInt(int val) {
SFS3_Value v = SFS3_Value_null();
v.type = SFS3_Int;
v.intValue = val;
return v;
}
SFS3_Value SFS3_Value_fromFloat(double val) {
SFS3_Value v = SFS3_Value_null();
v.type = SFS3_Float;
v.floatValue = val;
return v;
}
SFS3_Value SFS3_Value_fromBool(bool val) {
SFS3_Value v = SFS3_Value_null();
v.type = SFS3_Bool;
v.boolValue = val;
return v;
}
SFS3_Value SFS3_Value_fromString(SFS3_String val) {
SFS3_Value v = SFS3_Value_null();
v.type = SFS3_StringVal;
v.stringValue = SFS3_String_copy(val);
return v;
}
/* ── Lifecycle ──────────────────────────────────────────────────────────── */
static bool g_sfs3_initialized = false;
/*
* GC strategy: inline in SFS3_update(), no dedicated thread.
*
* A background GC thread calling InternalCollect triggers a stop-the-world
* pause that blocks ALL registered threads — including the main thread —
* until every Haxe Executor thread reaches a GC safe point. If any
* Executor thread is stuck in blocking I/O (WebSocket processLoop /
* Socket read), the main thread freezes for seconds.
*
* Instead we accumulate wall-clock time and run a minor collection inside
* SFS3_update(), where the main thread is already in a safe state.
* The Executor threads may still trigger GC via allocation pressure,
* but those collections happen on threads that are already at safe points
* and do not artificially stall the main thread.
*/
static double g_gcAccum = 0.0;
static constexpr double GC_INTERVAL_SEC = 15.0;
void SFS3_init(void) {
if (g_sfs3_initialized) return;
g_sfs3_initialized = true;
sfs3_set_top_of_stack();
sfs3_run_library();
}
void SFS3_dispose(void) {
if (!g_sfs3_initialized) return;
g_sfs3_initialized = false;
}
void SFS3_gc(void) {
SFS3_HX_BEGIN
hx::InternalCollect(false, false);
SFS3_HX_END
}
/* SFS3_update is defined after the event infrastructure (PendingEvent, SFS3_Event) */
void SFS3_registerThread(void) {
int stackVar = 0;
hx::RegisterCurrentThread(&stackVar);
}
/* ── ConfigData ─────────────────────────────────────────────────────────── */
struct SFS3_ConfigData {
hx::Object* obj;
SFS3_ConfigData() : obj(nullptr) {}
void set(hx::Object* o) {
obj = o;
if (obj) hx::GCAddRoot(&obj);
}
~SFS3_ConfigData() {
if (obj && g_sfs3_initialized) { hx::GCRemoveRoot(&obj); }
obj = nullptr;
}
private:
SFS3_ConfigData(const SFS3_ConfigData&);
SFS3_ConfigData& operator=(const SFS3_ConfigData&);
};
SFS3_ConfigData* SFS3_ConfigData_create(void) {
SFS3_HX_BEGIN
auto cfg = new SFS3_ConfigData();
cfg->set(com::smartfoxserver::v3::ConfigData_obj::__new().GetPtr());
SFS3_HX_END
return cfg;
}
void SFS3_ConfigData_release(SFS3_ConfigData* cfg) {
if (cfg) delete cfg;
}
/* Helper to cast the raw hx::Object* back to the concrete ConfigData type */
#define CFG_OBJ(c) (static_cast<com::smartfoxserver::v3::ConfigData_obj*>((c)->obj))
void SFS3_ConfigData_setHost(SFS3_ConfigData* cfg, const char* host) {
if (cfg && host) CFG_OBJ(cfg)->host = ::String(host);
}
void SFS3_ConfigData_setPort(SFS3_ConfigData* cfg, int port) {
if (cfg) CFG_OBJ(cfg)->port = port;
}
void SFS3_ConfigData_setUdpPort(SFS3_ConfigData* cfg, int port) {
if (cfg) CFG_OBJ(cfg)->udpPort = port;
}
void SFS3_ConfigData_setHttpPort(SFS3_ConfigData* cfg, int port) {
if (cfg) CFG_OBJ(cfg)->httpPort = port;
}
void SFS3_ConfigData_setHttpsPort(SFS3_ConfigData* cfg, int port) {
if (cfg) CFG_OBJ(cfg)->httpsPort = port;
}
void SFS3_ConfigData_setZone(SFS3_ConfigData* cfg, const char* zone) {
if (cfg && zone) CFG_OBJ(cfg)->zone = ::String(zone);
}
void SFS3_ConfigData_setUseSSL(SFS3_ConfigData* cfg, bool useSSL) {
if (cfg) CFG_OBJ(cfg)->useSSL = useSSL;
}
void SFS3_ConfigData_setUseWebSocket(SFS3_ConfigData* cfg, bool useWS) {
if (cfg) CFG_OBJ(cfg)->useWebSocket = useWS;
}
void SFS3_ConfigData_setUseTcpFallback(SFS3_ConfigData* cfg, bool fallback) {
if (cfg) CFG_OBJ(cfg)->useTcpFallback = fallback;
}
void SFS3_ConfigData_setUseTcpNoDelay(SFS3_ConfigData* cfg, bool noDelay) {
if (cfg) CFG_OBJ(cfg)->useTcpNoDelay = noDelay;
}
void SFS3_ConfigData_setTcpConnectionTimeout(SFS3_ConfigData* cfg, int ms) {
if (cfg) CFG_OBJ(cfg)->tcpConnectionTimeout = ms;
}
void SFS3_ConfigData_setBlueBoxActive(SFS3_ConfigData* cfg, bool active) {
if (cfg) CFG_OBJ(cfg)->blueBox->isActive = active;
}
const char* SFS3_ConfigData_getHost(SFS3_ConfigData* cfg) {
if (!cfg) return nullptr;
return CFG_OBJ(cfg)->host.utf8_str();
}
int SFS3_ConfigData_getPort(SFS3_ConfigData* cfg) {
if (!cfg) return 0;
return CFG_OBJ(cfg)->port;
}
const char* SFS3_ConfigData_getZone(SFS3_ConfigData* cfg) {
if (!cfg) return nullptr;
return CFG_OBJ(cfg)->zone.utf8_str();
}
/* ── SFS3_Event ─────────────────────────────────────────────────────────── */
struct SFS3_Event {
::hx::ObjectPtr<com::smartfoxserver::v3::core::ApiEvent_obj> hxEvt;
};
/* ── Event callback bridge ──────────────────────────────────────────────── */
struct EventListenerEntry {
std::string eventType;
SFS3_EventHandler handler;
void* userData;
SFS3_SmartFox* sfsHandle;
::Dynamic hxListener;
};
static std::mutex g_listenerMutex;
static std::vector<EventListenerEntry*> g_listeners;
/*
* Pending event: holds a GC-rooted reference to the Haxe event object so it
* stays alive until the main thread processes it during SFS3_update().
*/
struct PendingEvent {
EventListenerEntry* entry;
hx::Object* hxEvtRoot;
PendingEvent() : entry(nullptr), hxEvtRoot(nullptr) {}
PendingEvent(EventListenerEntry* e, hx::Object* evt) : entry(e), hxEvtRoot(evt) {
if (hxEvtRoot) hx::GCAddRoot(&hxEvtRoot);
}
~PendingEvent() {
if (hxEvtRoot && g_sfs3_initialized) { hx::GCRemoveRoot(&hxEvtRoot); }
hxEvtRoot = nullptr;
}
PendingEvent(PendingEvent&& o) noexcept : entry(o.entry), hxEvtRoot(o.hxEvtRoot) {
o.entry = nullptr;
o.hxEvtRoot = nullptr;
}
PendingEvent& operator=(PendingEvent&& o) noexcept {
if (this != &o) {
if (hxEvtRoot && g_sfs3_initialized) hx::GCRemoveRoot(&hxEvtRoot);
entry = o.entry; hxEvtRoot = o.hxEvtRoot;
o.entry = nullptr; o.hxEvtRoot = nullptr;
}
return *this;
}
PendingEvent(const PendingEvent&) = delete;
PendingEvent& operator=(const PendingEvent&) = delete;
};
static std::mutex g_pendingMtx;
static std::vector<PendingEvent> g_pendingEvents;
/*
* hxcpp-compatible closure using the HX_BEGIN_LOCAL_FUNC macro family.
* Captures one pointer (EventListenerEntry*) and accepts one hxcpp arg.
* Instead of calling the user handler directly (on a background thread),
* it enqueues the event for deferred dispatch on the main thread.
*/
HX_BEGIN_LOCAL_FUNC_S1(::hx::LocalFunc, _hx_Closure_sfs3Event,
EventListenerEntry*, entry) HXARGC(1)
void _hx_run(::Dynamic hxEvt) {
std::lock_guard<std::mutex> lk(g_pendingMtx);
g_pendingEvents.emplace_back(entry, hxEvt.GetPtr());
}
HX_END_LOCAL_FUNC1((void))
/* ── SFS3_update — flushes pending events on the caller's (main) thread ── */
SFS3_NOINLINE void SFS3_update(double deltaSec) {
SFS3_HX_BEGIN
std::vector<PendingEvent> batch;
{ std::lock_guard<std::mutex> lk(g_pendingMtx); batch.swap(g_pendingEvents); }
for (auto& pe : batch) {
SFS3_Event evt;
evt.hxEvt = (com::smartfoxserver::v3::core::ApiEvent_obj*)pe.hxEvtRoot;
pe.entry->handler(pe.entry->sfsHandle, &evt, pe.entry->userData);
}
g_gcAccum += deltaSec;
if (g_gcAccum >= GC_INTERVAL_SEC) {
g_gcAccum = 0.0;
hx::InternalCollect(false, false);
}
SFS3_HX_END
}
SFS3_String SFS3_Event_getType(SFS3_Event* evt) {
if (!evt) return SFS3_String_create(nullptr);
return wrap_string(evt->hxEvt->getType());
}
bool SFS3_Event_getBool(SFS3_Event* evt, const char* key) {
if (!evt || !key) return false;
::Dynamic val = evt->hxEvt->getParam(::String(key));
if (val == null()) return false;
return (bool)val;
}
int SFS3_Event_getInt(SFS3_Event* evt, const char* key) {
if (!evt || !key) return 0;
::Dynamic val = evt->hxEvt->getParam(::String(key));
if (val == null()) return 0;
return (int)val;
}
SFS3_String SFS3_Event_getString(SFS3_Event* evt, const char* key) {
if (!evt || !key) return SFS3_String_create(nullptr);
::Dynamic val = evt->hxEvt->getParam(::String(key));
if (val == null()) return SFS3_String_create(nullptr);
return wrap_string((::String)val);
}
/* ── SFS3_User (thin wrapper) ───────────────────────────────────────────── */
struct SFS3_User {
::Dynamic hxUser;
};
SFS3_User* SFS3_Event_getUser(SFS3_Event* evt, const char* key) {
if (!evt || !key) return nullptr;
::Dynamic val = evt->hxEvt->getParam(::String(key));
if (val == null()) return nullptr;
auto u = new SFS3_User();
u->hxUser = val;
return u;
}
int SFS3_User_getId(SFS3_User* user) {
if (!user) return -1;
return (int)user->hxUser->__Field(HX_CSTRING("getId"), ::hx::paccDynamic)();
}
SFS3_String SFS3_User_getName(SFS3_User* user) {
if (!user) return SFS3_String_create(nullptr);
return wrap_string((::String)user->hxUser->__Field(HX_CSTRING("getName"), ::hx::paccDynamic)());
}
int SFS3_User_getPlayerId(SFS3_User* user) {
if (!user) return -1;
return (int)user->hxUser->__Field(HX_CSTRING("getPlayerId"), ::hx::paccDynamic)();
}
bool SFS3_User_isPlayer(SFS3_User* user) {
if (!user) return false;
return (bool)user->hxUser->__Field(HX_CSTRING("isPlayer"), ::hx::paccDynamic)();
}
bool SFS3_User_isSpectator(SFS3_User* user) {
if (!user) return false;
return (bool)user->hxUser->__Field(HX_CSTRING("isSpectator"), ::hx::paccDynamic)();
}
int SFS3_User_getPrivilegeId(SFS3_User* user) {
if (!user) return 0;
return (int)user->hxUser->__Field(HX_CSTRING("getPrivilegeId"), ::hx::paccDynamic)();
}
bool SFS3_User_isGuest(SFS3_User* user) {
if (!user) return false;
return (bool)user->hxUser->__Field(HX_CSTRING("isGuest"), ::hx::paccDynamic)();
}
bool SFS3_User_isStandardUser(SFS3_User* user) {
if (!user) return false;
return (bool)user->hxUser->__Field(HX_CSTRING("isStandardUser"), ::hx::paccDynamic)();
}
bool SFS3_User_isModerator(SFS3_User* user) {
if (!user) return false;
return (bool)user->hxUser->__Field(HX_CSTRING("isModerator"), ::hx::paccDynamic)();
}
bool SFS3_User_isAdmin(SFS3_User* user) {
if (!user) return false;
return (bool)user->hxUser->__Field(HX_CSTRING("isAdmin"), ::hx::paccDynamic)();
}
bool SFS3_User_isItMe(SFS3_User* user) {
if (!user) return false;
return (bool)user->hxUser->__Field(HX_CSTRING("getIsItMe"), ::hx::paccDynamic)();
}
static ::Dynamic user_getVar(SFS3_User* user, const char* name) {
if (!user || !name) return null();
::Dynamic v = user->hxUser->__Field(HX_CSTRING("getVariable"), ::hx::paccDynamic)(::String(name));
return v;
}
bool SFS3_User_containsVariable(SFS3_User* user, const char* name) {
if (!user || !name) return false;
return (bool)user->hxUser->__Field(HX_CSTRING("containsVariable"), ::hx::paccDynamic)(::String(name));
}
int SFS3_User_getVariable_int(SFS3_User* user, const char* name) {
::Dynamic v = user_getVar(user, name);
if (v == null()) return 0;
return (int)v->__Field(HX_CSTRING("getIntValue"), ::hx::paccDynamic)();
}
double SFS3_User_getVariable_double(SFS3_User* user, const char* name) {
::Dynamic v = user_getVar(user, name);
if (v == null()) return 0.0;
return (double)(Float)v->__Field(HX_CSTRING("getDoubleValue"), ::hx::paccDynamic)();
}
bool SFS3_User_getVariable_bool(SFS3_User* user, const char* name) {
::Dynamic v = user_getVar(user, name);
if (v == null()) return false;
return (bool)v->__Field(HX_CSTRING("getBoolValue"), ::hx::paccDynamic)();
}
SFS3_String SFS3_User_getVariable_string(SFS3_User* user, const char* name) {
::Dynamic v = user_getVar(user, name);
if (v == null()) return SFS3_String_create(nullptr);
::String s = (::String)v->__Field(HX_CSTRING("getStringValue"), ::hx::paccDynamic)();
return wrap_string(s);
}
/* ── SFS3_MMOItem (thin wrapper) ────────────────────────────────────────── */
struct SFS3_MMOItem {
::Dynamic hxItem;
};
static ::Dynamic mmoitem_getVar(SFS3_MMOItem* item, const char* name) {
if (!item || !name) return null();
::Dynamic v = item->hxItem->__Field(HX_CSTRING("getVariable"), ::hx::paccDynamic)(::String(name));
return v;
}
int SFS3_MMOItem_getId(SFS3_MMOItem* item) {
if (!item) return -1;
return (int)item->hxItem->__Field(HX_CSTRING("getId"), ::hx::paccDynamic)();
}
bool SFS3_MMOItem_containsVariable(SFS3_MMOItem* item, const char* name) {
if (!item || !name) return false;
return (bool)item->hxItem->__Field(HX_CSTRING("containsVariable"), ::hx::paccDynamic)(::String(name));
}
int SFS3_MMOItem_getVariable_int(SFS3_MMOItem* item, const char* name) {
::Dynamic v = mmoitem_getVar(item, name);
if (v == null()) return 0;
return (int)v->__Field(HX_CSTRING("getIntValue"), ::hx::paccDynamic)();
}
double SFS3_MMOItem_getVariable_double(SFS3_MMOItem* item, const char* name) {
::Dynamic v = mmoitem_getVar(item, name);
if (v == null()) return 0.0;
return (double)(Float)v->__Field(HX_CSTRING("getDoubleValue"), ::hx::paccDynamic)();
}
bool SFS3_MMOItem_getVariable_bool(SFS3_MMOItem* item, const char* name) {
::Dynamic v = mmoitem_getVar(item, name);
if (v == null()) return false;
return (bool)v->__Field(HX_CSTRING("getBoolValue"), ::hx::paccDynamic)();
}
SFS3_String SFS3_MMOItem_getVariable_string(SFS3_MMOItem* item, const char* name) {
::Dynamic v = mmoitem_getVar(item, name);
if (v == null()) return SFS3_String_create(nullptr);
::String s = (::String)v->__Field(HX_CSTRING("getStringValue"), ::hx::paccDynamic)();
return wrap_string(s);
}
/* ── Event list accessors ───────────────────────────────────────────────── */
static ::Dynamic evt_getArray(SFS3_Event* evt, const char* key) {
if (!evt || !key) return null();
::Dynamic val = evt->hxEvt->getParam(::String(key));
return val;
}
double SFS3_Event_getDouble(SFS3_Event* evt, const char* key) {
if (!evt || !key) return 0.0;
::Dynamic val = evt->hxEvt->getParam(::String(key));
if (val == null()) return 0.0;
return (double)(Float)val;
}
int SFS3_Event_getLagValue(SFS3_Event* evt) {
if (!evt) return 0;
::Dynamic val = evt->hxEvt->getParam(::String("lagValue"));
if (val == null()) return 0;
Float avg = (Float)val->__Field(HX_CSTRING("average"), ::hx::paccDynamic);
return (int)avg;
}
int SFS3_Event_getUserListCount(SFS3_Event* evt, const char* key) {
::Dynamic arr = evt_getArray(evt, key);
if (arr == null()) return 0;
return (int)arr->__Field(HX_CSTRING("length"), ::hx::paccDynamic);
}
SFS3_User* SFS3_Event_getUserAt(SFS3_Event* evt, const char* key, int index) {
::Dynamic arr = evt_getArray(evt, key);
if (arr == null()) return nullptr;
int len = (int)arr->__Field(HX_CSTRING("length"), ::hx::paccDynamic);
if (index < 0 || index >= len) return nullptr;
::Dynamic elem = arr->__GetItem(index);
if (elem == null()) return nullptr;
auto u = new SFS3_User();
u->hxUser = elem;
return u;
}
int SFS3_Event_getMMOItemCount(SFS3_Event* evt, const char* key) {
::Dynamic arr = evt_getArray(evt, key);
if (arr == null()) return 0;
return (int)arr->__Field(HX_CSTRING("length"), ::hx::paccDynamic);
}
SFS3_MMOItem* SFS3_Event_getMMOItemAt(SFS3_Event* evt, const char* key, int index) {
::Dynamic arr = evt_getArray(evt, key);
if (arr == null()) return nullptr;
int len = (int)arr->__Field(HX_CSTRING("length"), ::hx::paccDynamic);
if (index < 0 || index >= len) return nullptr;
::Dynamic elem = arr->__GetItem(index);
if (elem == null()) return nullptr;
auto item = new SFS3_MMOItem();
item->hxItem = elem;
return item;
}
int SFS3_Event_getStringListCount(SFS3_Event* evt, const char* key) {
::Dynamic arr = evt_getArray(evt, key);
if (arr == null()) return 0;
return (int)arr->__Field(HX_CSTRING("length"), ::hx::paccDynamic);
}
SFS3_String SFS3_Event_getStringListAt(SFS3_Event* evt, const char* key, int index) {
::Dynamic arr = evt_getArray(evt, key);
if (arr == null()) return SFS3_String_create(nullptr);
int len = (int)arr->__Field(HX_CSTRING("length"), ::hx::paccDynamic);
if (index < 0 || index >= len) return SFS3_String_create(nullptr);
::Dynamic elem = arr->__GetItem(index);
if (elem == null()) return SFS3_String_create(nullptr);
return wrap_string((::String)elem);
}
/* ── SFS3_Room (thin wrapper) ───────────────────────────────────────────── */
struct SFS3_Room {
::Dynamic hxRoom;
};
SFS3_Room* SFS3_Event_getRoom(SFS3_Event* evt, const char* key) {
if (!evt || !key) return nullptr;
::Dynamic val = evt->hxEvt->getParam(::String(key));
if (val == null()) return nullptr;
auto r = new SFS3_Room();
r->hxRoom = val;
return r;
}
int SFS3_Room_getId(SFS3_Room* room) {
if (!room) return -1;
return (int)room->hxRoom->__Field(HX_CSTRING("getId"), ::hx::paccDynamic)();
}
SFS3_String SFS3_Room_getName(SFS3_Room* room) {
if (!room) return SFS3_String_create(nullptr);
return wrap_string((::String)room->hxRoom->__Field(HX_CSTRING("getName"), ::hx::paccDynamic)());
}
SFS3_String SFS3_Room_getGroupId(SFS3_Room* room) {
if (!room) return SFS3_String_create(nullptr);
return wrap_string((::String)room->hxRoom->__Field(HX_CSTRING("getGroupId"), ::hx::paccDynamic)());
}
bool SFS3_Room_isJoined(SFS3_Room* room) {
if (!room) return false;
return (bool)room->hxRoom->__Field(HX_CSTRING("getJoined"), ::hx::paccDynamic)();
}
bool SFS3_Room_isGame(SFS3_Room* room) {
if (!room) return false;
return (bool)room->hxRoom->__Field(HX_CSTRING("getGame"), ::hx::paccDynamic)();
}
bool SFS3_Room_isHidden(SFS3_Room* room) {
if (!room) return false;
return (bool)room->hxRoom->__Field(HX_CSTRING("getHidden"), ::hx::paccDynamic)();
}
bool SFS3_Room_isPasswordProtected(SFS3_Room* room) {
if (!room) return false;
return (bool)room->hxRoom->__Field(HX_CSTRING("getPasswordProtected"), ::hx::paccDynamic)();
}
int SFS3_Room_getUserCount(SFS3_Room* room) {
if (!room) return 0;
return (int)room->hxRoom->__Field(HX_CSTRING("getUserCount"), ::hx::paccDynamic)();
}
int SFS3_Room_getMaxUsers(SFS3_Room* room) {
if (!room) return 0;
return (int)room->hxRoom->__Field(HX_CSTRING("getMaxUsers"), ::hx::paccDynamic)();
}
int SFS3_Room_getSpectatorCount(SFS3_Room* room) {
if (!room) return 0;
return (int)room->hxRoom->__Field(HX_CSTRING("getSpectatorCount"), ::hx::paccDynamic)();
}
int SFS3_Room_getMaxSpectators(SFS3_Room* room) {
if (!room) return 0;
return (int)room->hxRoom->__Field(HX_CSTRING("getMaxSpectators"), ::hx::paccDynamic)();
}
int SFS3_Room_getCapacity(SFS3_Room* room) {
if (!room) return 0;
return (int)room->hxRoom->__Field(HX_CSTRING("getCapacity"), ::hx::paccDynamic)();
}
int SFS3_Room_getUserListCount(SFS3_Room* room) {
if (!room) return 0;
SFS3_HX_BEGIN
::Dynamic arr = room->hxRoom->__Field(HX_CSTRING("getUserList"), ::hx::paccDynamic)();
int n = (arr == null()) ? 0 : (int)arr->__Field(HX_CSTRING("length"), ::hx::paccDynamic);
SFS3_HX_END
return n;
}
SFS3_User* SFS3_Room_getUserAt(SFS3_Room* room, int index) {
if (!room) return nullptr;
SFS3_HX_BEGIN
::Dynamic arr = room->hxRoom->__Field(HX_CSTRING("getUserList"), ::hx::paccDynamic)();
SFS3_HX_END
if (arr == null()) return nullptr;
int len = (int)arr->__Field(HX_CSTRING("length"), ::hx::paccDynamic);
if (index < 0 || index >= len) return nullptr;
auto u = new SFS3_User();
u->hxUser = arr->__GetItem(index);
return u;
}
/* ── SFS3_SFSObject wrapper ─────────────────────────────────────────────── */
struct SFS3_SFSObject {
::Dynamic hxObj;
};
SFS3_SFSObject* SFS3_Event_getSFSObject(SFS3_Event* evt, const char* key) {
if (!evt || !key) return nullptr;
::Dynamic val = evt->hxEvt->getParam(::String(key));
if (val == null()) return nullptr;
auto o = new SFS3_SFSObject();
o->hxObj = val;
return o;
}
SFS3_SFSObject* SFS3_SFSObject_create(void) {
auto o = new SFS3_SFSObject();
o->hxObj = com::smartfoxserver::v3::entities::data::SFSObject_obj::newInstance();
return o;
}
void SFS3_SFSObject_release(SFS3_SFSObject* obj) {
if (obj) {
obj->hxObj = null();
delete obj;
}
}
bool SFS3_SFSObject_containsKey(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return false;
return (bool)obj->hxObj->__Field(HX_CSTRING("containsKey"), ::hx::paccDynamic)(::String(key));
}
int SFS3_SFSObject_size(SFS3_SFSObject* obj) {
if (!obj) return 0;
return (int)obj->hxObj->__Field(HX_CSTRING("size"), ::hx::paccDynamic)();
}
bool SFS3_SFSObject_isNull(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return true;
return (bool)obj->hxObj->__Field(HX_CSTRING("isNull"), ::hx::paccDynamic)(::String(key));
}
void SFS3_SFSObject_putBool(SFS3_SFSObject* obj, const char* key, bool value) {
if (!obj || !key) return;
obj->hxObj->__Field(HX_CSTRING("putBool"), ::hx::paccDynamic)(::String(key), value);
}
void SFS3_SFSObject_putByte(SFS3_SFSObject* obj, const char* key, int value) {
if (!obj || !key) return;
obj->hxObj->__Field(HX_CSTRING("putByte"), ::hx::paccDynamic)(::String(key), value);
}
void SFS3_SFSObject_putShort(SFS3_SFSObject* obj, const char* key, int value) {
if (!obj || !key) return;
obj->hxObj->__Field(HX_CSTRING("putShort"), ::hx::paccDynamic)(::String(key), value);
}
void SFS3_SFSObject_putInt(SFS3_SFSObject* obj, const char* key, int value) {
if (!obj || !key) return;
obj->hxObj->__Field(HX_CSTRING("putInt"), ::hx::paccDynamic)(::String(key), value);
}
void SFS3_SFSObject_putLong(SFS3_SFSObject* obj, const char* key, long long value) {
if (!obj || !key) return;
obj->hxObj->__Field(HX_CSTRING("putLong"), ::hx::paccDynamic)(::String(key), (int)value);
}
void SFS3_SFSObject_putFloat(SFS3_SFSObject* obj, const char* key, float value) {
if (!obj || !key) return;
obj->hxObj->__Field(HX_CSTRING("putFloat"), ::hx::paccDynamic)(::String(key), (double)value);
}
void SFS3_SFSObject_putDouble(SFS3_SFSObject* obj, const char* key, double value) {
if (!obj || !key) return;
obj->hxObj->__Field(HX_CSTRING("putDouble"), ::hx::paccDynamic)(::String(key), value);
}
void SFS3_SFSObject_putString(SFS3_SFSObject* obj, const char* key, const char* value) {
if (!obj || !key || !value) return;
obj->hxObj->__Field(HX_CSTRING("putString"), ::hx::paccDynamic)(::String(key), ::String(value));
}
void SFS3_SFSObject_putSFSObject(SFS3_SFSObject* obj, const char* key, SFS3_SFSObject* value) {
if (!obj || !key || !value) return;
obj->hxObj->__Field(HX_CSTRING("putSFSObject"), ::hx::paccDynamic)(::String(key), value->hxObj);
}
void SFS3_SFSObject_putSFSArray(SFS3_SFSObject* obj, const char* key, SFS3_SFSArray* value) {
/* forward-declared; implemented after SFS3_SFSArray struct */
}
bool SFS3_SFSObject_getBool(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return false;
return (bool)obj->hxObj->__Field(HX_CSTRING("getBool"), ::hx::paccDynamic)(::String(key));
}
int SFS3_SFSObject_getByte(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return 0;
return (int)obj->hxObj->__Field(HX_CSTRING("getByte"), ::hx::paccDynamic)(::String(key));
}
int SFS3_SFSObject_getShort(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return 0;
return (int)obj->hxObj->__Field(HX_CSTRING("getShort"), ::hx::paccDynamic)(::String(key));
}
int SFS3_SFSObject_getInt(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return 0;
return (int)obj->hxObj->__Field(HX_CSTRING("getInt"), ::hx::paccDynamic)(::String(key));
}
long long SFS3_SFSObject_getLong(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return 0;
return (long long)(int)obj->hxObj->__Field(HX_CSTRING("getLong"), ::hx::paccDynamic)(::String(key));
}
float SFS3_SFSObject_getFloat(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return 0.0f;
return (float)(double)obj->hxObj->__Field(HX_CSTRING("getFloat"), ::hx::paccDynamic)(::String(key));
}
double SFS3_SFSObject_getDouble(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return 0.0;
return (double)obj->hxObj->__Field(HX_CSTRING("getDouble"), ::hx::paccDynamic)(::String(key));
}
SFS3_String SFS3_SFSObject_getString(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return SFS3_String_create(nullptr);
::Dynamic val = obj->hxObj->__Field(HX_CSTRING("getString"), ::hx::paccDynamic)(::String(key));
if (val == null()) return SFS3_String_create(nullptr);
return wrap_string((::String)val);
}
SFS3_SFSObject* SFS3_SFSObject_getSFSObject(SFS3_SFSObject* obj, const char* key) {
if (!obj || !key) return nullptr;
::Dynamic val = obj->hxObj->__Field(HX_CSTRING("getSFSObject"), ::hx::paccDynamic)(::String(key));
if (val == null()) return nullptr;
auto o = new SFS3_SFSObject();
o->hxObj = val;
return o;
}
SFS3_SFSArray* SFS3_SFSObject_getSFSArray(SFS3_SFSObject* obj, const char* key);
SFS3_String SFS3_SFSObject_toJson(SFS3_SFSObject* obj) {
if (!obj) return SFS3_String_create(nullptr);
::Dynamic val = obj->hxObj->__Field(HX_CSTRING("toJson"), ::hx::paccDynamic)();
if (val == null()) return SFS3_String_create(nullptr);
return wrap_string((::String)val);
}
SFS3_String SFS3_SFSObject_getDump(SFS3_SFSObject* obj) {
if (!obj) return SFS3_String_create(nullptr);
::Dynamic val = obj->hxObj->__Field(HX_CSTRING("getDump"), ::hx::paccDynamic)();
if (val == null()) return SFS3_String_create(nullptr);
return wrap_string((::String)val);
}
/* ── SFS3_SFSArray wrapper ──────────────────────────────────────────────── */
struct SFS3_SFSArray {
::Dynamic hxArr;
};
SFS3_SFSArray* SFS3_SFSArray_create(void) {
auto a = new SFS3_SFSArray();
a->hxArr = com::smartfoxserver::v3::entities::data::SFSArray_obj::newInstance();
return a;
}
void SFS3_SFSArray_release(SFS3_SFSArray* arr) {
if (arr) {
arr->hxArr = null();
delete arr;
}
}
int SFS3_SFSArray_size(SFS3_SFSArray* arr) {
if (!arr) return 0;
return (int)arr->hxArr->__Field(HX_CSTRING("size"), ::hx::paccDynamic)();
}
void SFS3_SFSArray_addBool(SFS3_SFSArray* arr, bool value) {
if (!arr) return;
arr->hxArr->__Field(HX_CSTRING("addBool"), ::hx::paccDynamic)(value);
}
void SFS3_SFSArray_addByte(SFS3_SFSArray* arr, int value) {
if (!arr) return;
arr->hxArr->__Field(HX_CSTRING("addByte"), ::hx::paccDynamic)(value);
}