@xmobitea/gn-typescript-client 2.6.12 → 2.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/gearn.js.client.js +183 -57
  2. package/dist/gearn.js.client.min.js +1 -1
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +183 -57
  5. package/dist/runtime/GNNetwork.d.ts +1 -1
  6. package/dist/runtime/helper/GNSupport.d.ts +20 -0
  7. package/dist/runtime/{entity → helper}/OperationHelper.d.ts +1 -1
  8. package/dist/runtime/helper/StorageService.d.ts +18 -0
  9. package/dist/runtime/networking/NetworkingPeer.d.ts +1 -1
  10. package/dist/runtime/typescript/ServiceUpdate.d.ts +2 -0
  11. package/docs/COCOS_CREATOR_INTEGRATION.md +116 -0
  12. package/examples/cocos-creator/GearNExample.ts.txt +176 -0
  13. package/package.json +3 -2
  14. package/srcSwift/Package.swift +32 -0
  15. package/srcSwift/Sources/GearN/runtime/GNNetwork.swift +530 -0
  16. package/srcSwift/Sources/GearN/runtime/GNNetworkAuthenticateApi.swift +178 -0
  17. package/srcSwift/Sources/GearN/runtime/GNNetworkCharacterPlayerApi.swift +1162 -0
  18. package/srcSwift/Sources/GearN/runtime/GNNetworkCloudScriptApi.swift +154 -0
  19. package/srcSwift/Sources/GearN/runtime/GNNetworkContentApi.swift +208 -0
  20. package/srcSwift/Sources/GearN/runtime/GNNetworkDashboardApi.swift +240 -0
  21. package/srcSwift/Sources/GearN/runtime/GNNetworkGamePlayerApi.swift +1369 -0
  22. package/srcSwift/Sources/GearN/runtime/GNNetworkGroupApi.swift +1100 -0
  23. package/srcSwift/Sources/GearN/runtime/GNNetworkInventoryApi.swift +937 -0
  24. package/srcSwift/Sources/GearN/runtime/GNNetworkMasterPlayerApi.swift +2323 -0
  25. package/srcSwift/Sources/GearN/runtime/GNNetworkMultiplayerApi.swift +298 -0
  26. package/srcSwift/Sources/GearN/runtime/GNNetworkStoreInventoryApi.swift +397 -0
  27. package/srcSwift/Sources/GearN/runtime/common/Action0.swift +3 -0
  28. package/srcSwift/Sources/GearN/runtime/common/Action1.swift +3 -0
  29. package/srcSwift/Sources/GearN/runtime/common/Action2.swift +3 -0
  30. package/srcSwift/Sources/GearN/runtime/common/Action3.swift +3 -0
  31. package/srcSwift/Sources/GearN/runtime/common/Action4.swift +3 -0
  32. package/srcSwift/Sources/GearN/runtime/common/GNArray.swift +204 -0
  33. package/srcSwift/Sources/GearN/runtime/common/GNData.swift +108 -0
  34. package/srcSwift/Sources/GearN/runtime/common/GNHashtable.swift +200 -0
  35. package/srcSwift/Sources/GearN/runtime/config/GNServerSettings.swift +95 -0
  36. package/srcSwift/Sources/GearN/runtime/constant/Commands.swift +28 -0
  37. package/srcSwift/Sources/GearN/runtime/constant/EventCode.swift +10 -0
  38. package/srcSwift/Sources/GearN/runtime/constant/OperationCode.swift +252 -0
  39. package/srcSwift/Sources/GearN/runtime/constant/ReturnCode.swift +19 -0
  40. package/srcSwift/Sources/GearN/runtime/constant/enumType/ExecuteResponseStatus.swift +9 -0
  41. package/srcSwift/Sources/GearN/runtime/constant/enumType/FriendStatus.swift +8 -0
  42. package/srcSwift/Sources/GearN/runtime/constant/enumType/GoogleLoginType.swift +6 -0
  43. package/srcSwift/Sources/GearN/runtime/constant/enumType/GroupStatus.swift +8 -0
  44. package/srcSwift/Sources/GearN/runtime/constant/enumType/InvalidMemberType.swift +19 -0
  45. package/srcSwift/Sources/GearN/runtime/constant/enumType/ItemType.swift +6 -0
  46. package/srcSwift/Sources/GearN/runtime/constant/enumType/MatchmakingMemberStatus.swift +7 -0
  47. package/srcSwift/Sources/GearN/runtime/constant/enumType/MatchmakingTicketStatus.swift +9 -0
  48. package/srcSwift/Sources/GearN/runtime/constant/enumType/OwnerType.swift +10 -0
  49. package/srcSwift/Sources/GearN/runtime/constant/enumType/PermissionDataItem.swift +6 -0
  50. package/srcSwift/Sources/GearN/runtime/constant/enumType/PushPlatformType.swift +6 -0
  51. package/srcSwift/Sources/GearN/runtime/constant/enumType/RequestRole.swift +7 -0
  52. package/srcSwift/Sources/GearN/runtime/constant/enumType/RequestType.swift +16 -0
  53. package/srcSwift/Sources/GearN/runtime/constant/enumType/StoreItemType.swift +6 -0
  54. package/srcSwift/Sources/GearN/runtime/constant/enumType/StoreReceiveType.swift +9 -0
  55. package/srcSwift/Sources/GearN/runtime/constant/errorCode/ErrorCode.swift +58 -0
  56. package/srcSwift/Sources/GearN/runtime/constant/parameterCode/ParameterCode.swift +672 -0
  57. package/srcSwift/Sources/GearN/runtime/entity/DataMember.swift +196 -0
  58. package/srcSwift/Sources/GearN/runtime/entity/GNMetadata.swift +9 -0
  59. package/srcSwift/Sources/GearN/runtime/entity/InvalidMember.swift +11 -0
  60. package/srcSwift/Sources/GearN/runtime/entity/OperationEvent.swift +38 -0
  61. package/srcSwift/Sources/GearN/runtime/entity/OperationHelper.swift +28 -0
  62. package/srcSwift/Sources/GearN/runtime/entity/OperationRequest.swift +62 -0
  63. package/srcSwift/Sources/GearN/runtime/entity/OperationResponse.swift +98 -0
  64. package/srcSwift/Sources/GearN/runtime/entity/models/AuthenticateModels.swift +351 -0
  65. package/srcSwift/Sources/GearN/runtime/entity/models/AuthenticateRequestModels.swift +81 -0
  66. package/srcSwift/Sources/GearN/runtime/entity/models/AuthenticateResponseModels.swift +108 -0
  67. package/srcSwift/Sources/GearN/runtime/entity/models/CharacterPlayerModels.swift +1045 -0
  68. package/srcSwift/Sources/GearN/runtime/entity/models/CharacterPlayerRequestModels.swift +821 -0
  69. package/srcSwift/Sources/GearN/runtime/entity/models/CharacterPlayerResponseModels.swift +588 -0
  70. package/srcSwift/Sources/GearN/runtime/entity/models/CloudScriptModels.swift +187 -0
  71. package/srcSwift/Sources/GearN/runtime/entity/models/CloudScriptRequestModels.swift +84 -0
  72. package/srcSwift/Sources/GearN/runtime/entity/models/CloudScriptResponseModels.swift +59 -0
  73. package/srcSwift/Sources/GearN/runtime/entity/models/ContentModels.swift +195 -0
  74. package/srcSwift/Sources/GearN/runtime/entity/models/ContentRequestModels.swift +116 -0
  75. package/srcSwift/Sources/GearN/runtime/entity/models/ContentResponseModels.swift +81 -0
  76. package/srcSwift/Sources/GearN/runtime/entity/models/DashboardModels.swift +426 -0
  77. package/srcSwift/Sources/GearN/runtime/entity/models/DashboardRequestModels.swift +160 -0
  78. package/srcSwift/Sources/GearN/runtime/entity/models/DashboardResponseModels.swift +82 -0
  79. package/srcSwift/Sources/GearN/runtime/entity/models/GamePlayerModels.swift +1334 -0
  80. package/srcSwift/Sources/GearN/runtime/entity/models/GamePlayerRequestModels.swift +643 -0
  81. package/srcSwift/Sources/GearN/runtime/entity/models/GamePlayerResponseModels.swift +213 -0
  82. package/srcSwift/Sources/GearN/runtime/entity/models/GenericModels.swift +171 -0
  83. package/srcSwift/Sources/GearN/runtime/entity/models/GroupModels.swift +850 -0
  84. package/srcSwift/Sources/GearN/runtime/entity/models/GroupRequestModels.swift +485 -0
  85. package/srcSwift/Sources/GearN/runtime/entity/models/GroupResponseModels.swift +165 -0
  86. package/srcSwift/Sources/GearN/runtime/entity/models/InventoryModels.swift +679 -0
  87. package/srcSwift/Sources/GearN/runtime/entity/models/InventoryRequestModels.swift +413 -0
  88. package/srcSwift/Sources/GearN/runtime/entity/models/InventoryResponseModels.swift +141 -0
  89. package/srcSwift/Sources/GearN/runtime/entity/models/MasterPlayerModels.swift +378 -0
  90. package/srcSwift/Sources/GearN/runtime/entity/models/MasterPlayerRequestModels.swift +147 -0
  91. package/srcSwift/Sources/GearN/runtime/entity/models/MasterPlayerResponseModels.swift +318 -0
  92. package/srcSwift/Sources/GearN/runtime/entity/models/MultiplayerModels.swift +319 -0
  93. package/srcSwift/Sources/GearN/runtime/entity/models/MultiplayerRequestModels.swift +125 -0
  94. package/srcSwift/Sources/GearN/runtime/entity/models/MultiplayerResponseModels.swift +45 -0
  95. package/srcSwift/Sources/GearN/runtime/entity/models/StoreInventoryModels.swift +633 -0
  96. package/srcSwift/Sources/GearN/runtime/entity/models/StoreInventoryRequestModels.swift +173 -0
  97. package/srcSwift/Sources/GearN/runtime/entity/models/StoreInventoryResponseModels.swift +61 -0
  98. package/srcSwift/Sources/GearN/runtime/entity/request/CustomOperationRequest.swift +42 -0
  99. package/srcSwift/Sources/GearN/runtime/entity/response/CustomOperationResponse.swift +49 -0
  100. package/srcSwift/Sources/GearN/runtime/entity/response/GetAuthInfoResponse.swift +43 -0
  101. package/srcSwift/Sources/GearN/runtime/entity/response/HealthCheckResponse.swift +86 -0
  102. package/srcSwift/Sources/GearN/runtime/entity/response/UploadFileResponse.swift +15 -0
  103. package/srcSwift/Sources/GearN/runtime/helper/CodeHelper.swift +107 -0
  104. package/srcSwift/Sources/GearN/runtime/helper/ConverterService.swift +98 -0
  105. package/srcSwift/Sources/GearN/runtime/helper/EnumUtility.swift +34 -0
  106. package/srcSwift/Sources/GearN/runtime/helper/GNSupport.swift +41 -0
  107. package/srcSwift/Sources/GearN/runtime/helper/GNUtils.swift +66 -0
  108. package/srcSwift/Sources/GearN/runtime/helper/MessagePackConverterService.swift +21 -0
  109. package/srcSwift/Sources/GearN/runtime/helper/StorageService.swift +29 -0
  110. package/srcSwift/Sources/GearN/runtime/logger/GNDebug.swift +33 -0
  111. package/srcSwift/Sources/GearN/runtime/networking/AuthenticateStatus.swift +24 -0
  112. package/srcSwift/Sources/GearN/runtime/networking/IPeer.swift +8 -0
  113. package/srcSwift/Sources/GearN/runtime/networking/NetworkingPeer.swift +368 -0
  114. package/srcSwift/Sources/GearN/runtime/networking/OperationPending.swift +81 -0
  115. package/srcSwift/Sources/GearN/runtime/networking/PeerBase.swift +228 -0
  116. package/srcSwift/Sources/GearN/runtime/networking/handler/IServerEventHandler.swift +20 -0
  117. package/srcSwift/Sources/GearN/runtime/networking/http/HttpPeer.swift +226 -0
  118. package/srcSwift/Sources/GearN/runtime/networking/http/HttpTypes.swift +24 -0
  119. package/srcSwift/Sources/GearN/runtime/networking/http/NetworkingHttpPeerBase.swift +13 -0
  120. package/srcSwift/Sources/GearN/runtime/networking/http/NetworkingPeerUrlSession.swift +125 -0
  121. package/srcSwift/Sources/GearN/runtime/networking/request/NetRequest.swift +19 -0
  122. package/srcSwift/Sources/GearN/runtime/networking/response/NetResponse.swift +13 -0
  123. package/srcSwift/Sources/GearN/runtime/networking/socket/NetworkingPeerSocketIOClient.swift +244 -0
  124. package/srcSwift/Sources/GearN/runtime/networking/socket/NetworkingSocketPeerBase.swift +59 -0
  125. package/srcSwift/Sources/GearN/runtime/networking/socket/SocketPeer.swift +136 -0
  126. package/tsconfig-build.cocos.json +31 -0
  127. package/webpack.config.cocos.mjs +78 -0
@@ -0,0 +1,204 @@
1
+ import Foundation
2
+
3
+ public class GNArrayBuilder {
4
+ private var array: [Any] = []
5
+
6
+ public init() {}
7
+
8
+ public func add(_ value: Any) -> GNArrayBuilder {
9
+ self.array.append(value)
10
+ return self
11
+ }
12
+
13
+ public func addAll(_ array: [Any]) -> GNArrayBuilder {
14
+ self.array.append(contentsOf: array)
15
+ return self
16
+ }
17
+
18
+ public func build() -> GNArray {
19
+ let answer = GNArray()
20
+ for v in self.array {
21
+ answer.add(v)
22
+ }
23
+ return answer
24
+ }
25
+ }
26
+
27
+ public class GNArray: GNData, IGNData, CustomStringConvertible {
28
+ private var array: [Any] = []
29
+
30
+ public override init() {
31
+ super.init()
32
+ }
33
+
34
+ public static func builder() -> GNArrayBuilder {
35
+ return GNArrayBuilder()
36
+ }
37
+
38
+ public func clear() {
39
+ self.array.removeAll()
40
+ }
41
+
42
+ public func remove(key: String) -> Bool {
43
+ return false // Not applicable
44
+ }
45
+
46
+ public func remove(index: Int) -> Bool {
47
+ if index >= 0 && index < self.array.count {
48
+ self.array.remove(at: index)
49
+ return true
50
+ }
51
+ return false
52
+ }
53
+
54
+ public func count() -> Int {
55
+ return self.array.count
56
+ }
57
+
58
+ public func add(_ value: Any?) {
59
+ if let v = value {
60
+ self.array.append(GNData.createUseDataFromOriginData(value: v)!)
61
+ }
62
+ }
63
+
64
+ // Getters by key - Not applicable
65
+ public func getObject(key: String) -> Any? { return nil }
66
+ public func getBoolean(key: String) -> Bool? { return nil }
67
+ public func getString(key: String) -> String? { return nil }
68
+ public func getNumber(key: String) -> Double? { return nil }
69
+ public func getByte(key: String) -> UInt8? { return nil }
70
+ public func getSByte(key: String) -> Int8? { return nil }
71
+ public func getShort(key: String) -> Int16? { return nil }
72
+ public func getInt(key: String) -> Int? { return nil }
73
+ public func getLong(key: String) -> Int64? { return nil }
74
+ public func getFloat(key: String) -> Float? { return nil }
75
+ public func getDouble(key: String) -> Double? { return nil }
76
+ public func getGNHashtable(key: String) -> GNHashtable? { return nil }
77
+ public func getGNArray(key: String) -> GNArray? { return nil }
78
+
79
+ // Getters by Index
80
+ public func getObject(index: Int) -> Any? { return self.get(index) }
81
+
82
+ public func getBoolean(index: Int) -> Bool? { return self.get(index) as? Bool }
83
+
84
+ public func getString(index: Int) -> String? { return self.get(index) as? String }
85
+
86
+ public func getNumber(index: Int) -> Double? { return self.getDouble(index: index) }
87
+
88
+ public func getByte(index: Int) -> UInt8? {
89
+ if let v = self.get(index) as? UInt8 { return v }
90
+ if let v = self.get(index) as? NSNumber { return v.uint8Value }
91
+ return nil
92
+ }
93
+
94
+ public func getSByte(index: Int) -> Int8? {
95
+ if let v = self.get(index) as? Int8 { return v }
96
+ if let v = self.get(index) as? NSNumber { return v.int8Value }
97
+ return nil
98
+ }
99
+
100
+ public func getShort(index: Int) -> Int16? {
101
+ if let v = self.get(index) as? Int16 { return v }
102
+ if let v = self.get(index) as? NSNumber { return v.int16Value }
103
+ return nil
104
+ }
105
+
106
+ public func getInt(index: Int) -> Int? {
107
+ if let v = self.get(index) as? Int { return v }
108
+ if let v = self.get(index) as? NSNumber { return v.intValue }
109
+ return nil
110
+ }
111
+
112
+ public func getLong(index: Int) -> Int64? {
113
+ if let v = self.get(index) as? Int64 { return v }
114
+ if let v = self.get(index) as? NSNumber { return v.int64Value }
115
+ return nil
116
+ }
117
+
118
+ public func getFloat(index: Int) -> Float? {
119
+ if let v = self.get(index) as? Float { return v }
120
+ if let v = self.get(index) as? NSNumber { return v.floatValue }
121
+ return nil
122
+ }
123
+
124
+ public func getDouble(index: Int) -> Double? {
125
+ if let v = self.get(index) as? Double { return v }
126
+ if let v = self.get(index) as? NSNumber { return v.doubleValue }
127
+ return nil
128
+ }
129
+
130
+ public func getGNHashtable(index: Int) -> GNHashtable? { return self.get(index) as? GNHashtable }
131
+
132
+ public func getGNArray(index: Int) -> GNArray? { return self.get(index) as? GNArray }
133
+
134
+ private func get(_ index: Int) -> Any? {
135
+ if index >= 0 && index < self.array.count {
136
+ return self.array[index]
137
+ }
138
+ return nil
139
+ }
140
+
141
+ public func toArray<T>() -> [T] {
142
+ var result: [T] = []
143
+ for item in self.array {
144
+ if let converted = item as? T {
145
+ result.append(converted)
146
+ } else if let num = item as? NSNumber {
147
+ // Try to convert NSNumber to T if T is a number type
148
+ // Swift generics constraints don't easily allow checking "is Int"
149
+ // But we can check via type casting
150
+ if T.self == Int.self { result.append(num.intValue as! T) }
151
+ else if T.self == Double.self { result.append(num.doubleValue as! T) }
152
+ else if T.self == Float.self { result.append(num.floatValue as! T) }
153
+ else if T.self == Int64.self { result.append(num.int64Value as! T) }
154
+ else if T.self == UInt8.self { result.append(num.uint8Value as! T) }
155
+ else if T.self == String.self { result.append(num.stringValue as! T) }
156
+ // Add more as needed
157
+ }
158
+ }
159
+ return result
160
+ }
161
+
162
+ public func toData() -> [Any] {
163
+ return self.array.map { GNData.createDataFromUseData(value: $0)! }
164
+ }
165
+
166
+ public func toString() -> String {
167
+ var parts: [String] = []
168
+ for v in self.array {
169
+ parts.append(stringify(v))
170
+ }
171
+ return "[" + parts.joined(separator: ",") + "]"
172
+ }
173
+
174
+ public var description: String {
175
+ return self.toString()
176
+ }
177
+
178
+ private func stringify(_ value: Any) -> String {
179
+ if value is NSNull { return "null" }
180
+ if let str = value as? String { return "\"\(str)\"" }
181
+ if let bool = value as? Bool { return bool ? "true" : "false" }
182
+ if let ignStr = value as? IGNData { return ignStr.toString() }
183
+ if let num = value as? NSNumber { return "\(num)" }
184
+ return "\(value)"
185
+ }
186
+ }
187
+
188
+ extension GNArray: Codable {
189
+ public convenience init(from decoder: Decoder) throws {
190
+ self.init()
191
+ var container = try decoder.unkeyedContainer()
192
+ while !container.isAtEnd {
193
+ let value = try container.decode(AnyCodable.self)
194
+ self.add(value.value)
195
+ }
196
+ }
197
+
198
+ public func encode(to encoder: Encoder) throws {
199
+ var container = encoder.unkeyedContainer()
200
+ for value in self.toData() {
201
+ try container.encode(AnyCodable(value))
202
+ }
203
+ }
204
+ }
@@ -0,0 +1,108 @@
1
+ import Foundation
2
+
3
+ public protocol IGNData {
4
+ func clear()
5
+ func remove(key: String) -> Bool
6
+ func remove(index: Int) -> Bool
7
+ func count() -> Int
8
+
9
+ // Getters by Key
10
+ func getObject(key: String) -> Any?
11
+ func getBoolean(key: String) -> Bool?
12
+ func getString(key: String) -> String?
13
+ func getNumber(key: String) -> Double?
14
+
15
+ func getByte(key: String) -> UInt8?
16
+ func getSByte(key: String) -> Int8?
17
+ func getShort(key: String) -> Int16?
18
+ func getInt(key: String) -> Int?
19
+ func getLong(key: String) -> Int64?
20
+ func getFloat(key: String) -> Float?
21
+ func getDouble(key: String) -> Double?
22
+
23
+ func getGNHashtable(key: String) -> GNHashtable?
24
+ func getGNArray(key: String) -> GNArray?
25
+
26
+ // Getters by Index
27
+ func getObject(index: Int) -> Any?
28
+ func getBoolean(index: Int) -> Bool?
29
+ func getString(index: Int) -> String?
30
+ func getNumber(index: Int) -> Double?
31
+
32
+ func getByte(index: Int) -> UInt8?
33
+ func getSByte(index: Int) -> Int8?
34
+ func getShort(index: Int) -> Int16?
35
+ func getInt(index: Int) -> Int?
36
+ func getLong(index: Int) -> Int64?
37
+ func getFloat(index: Int) -> Float?
38
+ func getDouble(index: Int) -> Double?
39
+
40
+ func getGNHashtable(index: Int) -> GNHashtable?
41
+ func getGNArray(index: Int) -> GNArray?
42
+
43
+ func toString() -> String
44
+ }
45
+
46
+ public class GNData {
47
+ // Shared static helpers
48
+
49
+ public static func createGNHashtableFromObject(value: [String: Any]) -> GNHashtable {
50
+ let answer = GNHashtable()
51
+ for (k, v) in value {
52
+ answer.put(k, v)
53
+ }
54
+ return answer
55
+ }
56
+
57
+ public static func createGNArrayFromArray(value: [Any]) -> GNArray {
58
+ let answer = GNArray()
59
+ for v in value {
60
+ answer.add(v)
61
+ }
62
+ return answer
63
+ }
64
+
65
+ public static func createUseDataFromOriginData(value: Any?) -> Any? {
66
+ guard let value = value else { return nil }
67
+
68
+ if let str = value as? String { return str }
69
+ if let bool = value as? Bool { return bool }
70
+
71
+ // Number types
72
+ if let num = value as? NSNumber { return num }
73
+ if let i = value as? Int { return i }
74
+ if let d = value as? Double { return d }
75
+ if let f = value as? Float { return f }
76
+ if let i8 = value as? Int8 { return i8 }
77
+ if let u8 = value as? UInt8 { return u8 }
78
+ if let i16 = value as? Int16 { return i16 }
79
+ if let i64 = value as? Int64 { return i64 }
80
+
81
+ if let arr = value as? GNArray { return arr }
82
+ if let ht = value as? GNHashtable { return ht }
83
+
84
+ if let dict = value as? [String: Any] {
85
+ return createGNHashtableFromObject(value: dict)
86
+ }
87
+
88
+ if let arr = value as? [Any] {
89
+ return createGNArrayFromArray(value: arr)
90
+ }
91
+
92
+ return value // Return raw if undetermined? Or nil? Unity returns value.
93
+ }
94
+
95
+ public static func createDataFromUseData(value: Any?) -> Any? {
96
+ guard let value = value else { return nil }
97
+
98
+ if let arr = value as? GNArray {
99
+ return arr.toData()
100
+ }
101
+
102
+ if let ht = value as? GNHashtable {
103
+ return ht.toData()
104
+ }
105
+
106
+ return value
107
+ }
108
+ }
@@ -0,0 +1,200 @@
1
+ import Foundation
2
+
3
+ public class GNHashtableBuilder {
4
+ private var dict: [String: Any] = [:]
5
+
6
+ public init() {}
7
+
8
+ public func add(_ key: String, _ value: Any) -> GNHashtableBuilder {
9
+ self.dict[key] = value
10
+ return self
11
+ }
12
+
13
+ public func addAll(_ dict: [String: Any]) -> GNHashtableBuilder {
14
+ for (k, v) in dict {
15
+ self.dict[k] = v
16
+ }
17
+ return self
18
+ }
19
+
20
+ public func build() -> GNHashtable {
21
+ let answer = GNHashtable()
22
+ for (k, v) in self.dict {
23
+ answer.put(k, v)
24
+ }
25
+ return answer
26
+ }
27
+ }
28
+
29
+ public class GNHashtable: GNData, IGNData, CustomStringConvertible {
30
+ private var dict: [String: Any] = [:]
31
+
32
+ public override init() {
33
+ super.init()
34
+ }
35
+
36
+ public static func builder() -> GNHashtableBuilder {
37
+ return GNHashtableBuilder()
38
+ }
39
+
40
+ public func clear() {
41
+ self.dict.removeAll()
42
+ }
43
+
44
+ public func remove(key: String) -> Bool {
45
+ return self.dict.removeValue(forKey: key) != nil
46
+ }
47
+
48
+ public func remove(index: Int) -> Bool {
49
+ return false // Not applicable for Hashtable
50
+ }
51
+
52
+ public func count() -> Int {
53
+ return self.dict.count
54
+ }
55
+
56
+ public func put(_ key: String, _ value: Any?) {
57
+ if let v = value {
58
+ self.dict[key] = GNData.createUseDataFromOriginData(value: v)
59
+ } else {
60
+ self.dict.removeValue(forKey: key)
61
+ }
62
+ }
63
+
64
+ public func containsKey(_ key: String) -> Bool {
65
+ return self.dict.keys.contains(key)
66
+ }
67
+
68
+ public func keys() -> [String] {
69
+ return Array(self.dict.keys)
70
+ }
71
+
72
+ public func values() -> [Any] {
73
+ return Array(self.dict.values)
74
+ }
75
+
76
+ // Getters
77
+ public func getObject(key: String) -> Any? { return self.dict[key] }
78
+ public func getObject(index: Int) -> Any? { return nil }
79
+
80
+ public func getBoolean(key: String) -> Bool? { return self.get(key) as? Bool }
81
+ public func getBoolean(index: Int) -> Bool? { return nil }
82
+
83
+ public func getString(key: String) -> String? { return self.get(key) as? String }
84
+ public func getString(index: Int) -> String? { return nil }
85
+
86
+ public func getNumber(key: String) -> Double? { return self.getDouble(key: key) } // Mapping Number to Double generally
87
+ public func getNumber(index: Int) -> Double? { return nil }
88
+
89
+ // Typed Getters (Key)
90
+ public func getByte(key: String) -> UInt8? {
91
+ if let v = self.get(key) as? UInt8 { return v }
92
+ if let v = self.get(key) as? NSNumber { return v.uint8Value }
93
+ return nil
94
+ }
95
+
96
+ public func getSByte(key: String) -> Int8? {
97
+ if let v = self.get(key) as? Int8 { return v }
98
+ if let v = self.get(key) as? NSNumber { return v.int8Value }
99
+ return nil
100
+ }
101
+
102
+ public func getShort(key: String) -> Int16? {
103
+ if let v = self.get(key) as? Int16 { return v }
104
+ if let v = self.get(key) as? NSNumber { return v.int16Value }
105
+ return nil
106
+ }
107
+
108
+ public func getInt(key: String) -> Int? {
109
+ if let v = self.get(key) as? Int { return v }
110
+ if let v = self.get(key) as? NSNumber { return v.intValue }
111
+ return nil
112
+ }
113
+
114
+ public func getLong(key: String) -> Int64? {
115
+ if let v = self.get(key) as? Int64 { return v }
116
+ if let v = self.get(key) as? NSNumber { return v.int64Value }
117
+ return nil
118
+ }
119
+
120
+ public func getFloat(key: String) -> Float? {
121
+ if let v = self.get(key) as? Float { return v }
122
+ if let v = self.get(key) as? NSNumber { return v.floatValue }
123
+ return nil
124
+ }
125
+
126
+ public func getDouble(key: String) -> Double? {
127
+ if let v = self.get(key) as? Double { return v }
128
+ if let v = self.get(key) as? NSNumber { return v.doubleValue }
129
+ return nil
130
+ }
131
+
132
+ // Typed Getters (Index) - Not supported for Hashtable
133
+ public func getByte(index: Int) -> UInt8? { return nil }
134
+ public func getSByte(index: Int) -> Int8? { return nil }
135
+ public func getShort(index: Int) -> Int16? { return nil }
136
+ public func getInt(index: Int) -> Int? { return nil }
137
+ public func getLong(index: Int) -> Int64? { return nil }
138
+ public func getFloat(index: Int) -> Float? { return nil }
139
+ public func getDouble(index: Int) -> Double? { return nil }
140
+
141
+ public func getGNHashtable(key: String) -> GNHashtable? { return self.get(key) as? GNHashtable }
142
+ public func getGNHashtable(index: Int) -> GNHashtable? { return nil }
143
+
144
+ public func getGNArray(key: String) -> GNArray? { return self.get(key) as? GNArray }
145
+ public func getGNArray(index: Int) -> GNArray? { return nil }
146
+
147
+ private func get(_ key: String) -> Any? {
148
+ return self.dict[key]
149
+ }
150
+
151
+ public func toData() -> [String: Any] {
152
+ var answer: [String: Any] = [:]
153
+ for (k, v) in self.dict {
154
+ answer[k] = GNData.createDataFromUseData(value: v)
155
+ }
156
+ return answer
157
+ }
158
+
159
+ public func toString() -> String {
160
+ var parts: [String] = []
161
+ for (k, v) in self.dict {
162
+ let keyStr = "\"\(k)\""
163
+ let valStr = stringify(v)
164
+ parts.append("\(keyStr):\(valStr)")
165
+ }
166
+ return "{" + parts.joined(separator: ",") + "}"
167
+ }
168
+
169
+ public var description: String {
170
+ return self.toString()
171
+ }
172
+
173
+ private func stringify(_ value: Any) -> String {
174
+ if value is NSNull { return "null" }
175
+ if let str = value as? String { return "\"\(str)\"" }
176
+ if let bool = value as? Bool { return bool ? "true" : "false" }
177
+ if let ignStr = value as? IGNData { return ignStr.toString() }
178
+ if let num = value as? NSNumber { return "\(num)" } // Covers all numbers
179
+ // Add more types if needed
180
+ return "\(value)"
181
+ }
182
+ }
183
+
184
+ extension GNHashtable: Codable {
185
+ public convenience init(from decoder: Decoder) throws {
186
+ self.init()
187
+ let container = try decoder.container(keyedBy: AnyCodingKey.self)
188
+ for key in container.allKeys {
189
+ let value = try container.decode(AnyCodable.self, forKey: key)
190
+ self.put(key.stringValue, value.value)
191
+ }
192
+ }
193
+
194
+ public func encode(to encoder: Encoder) throws {
195
+ var container = encoder.container(keyedBy: AnyCodingKey.self)
196
+ for (key, value) in self.toData() {
197
+ try container.encode(AnyCodable(value), forKey: AnyCodingKey(stringValue: key)!)
198
+ }
199
+ }
200
+ }
@@ -0,0 +1,95 @@
1
+ import Foundation
2
+
3
+ public enum MessageType: Int {
4
+ case Json = 1
5
+ case MsgPack = 2
6
+ }
7
+
8
+ public class GNServerSettings {
9
+ private var serverAddress: String = "127.0.0.1"
10
+ private var serverPort: Int = 2202
11
+ private var serverSocketPort: Int = 2901
12
+ private var useSsl: Bool = false
13
+ private var useSocket: Bool = true
14
+ private var useHttp: Bool = true
15
+
16
+ private var defaultTimeoutInSeconds: Int = 20
17
+ private var messageType: MessageType = .MsgPack
18
+ private var sendRate: Int = 20
19
+ private var reconnectDelay: Int = 5000 // ms
20
+ private var pingInterval: Float = 20000 // ms
21
+ private var pingTimeout: Float = 20000 // ms
22
+
23
+ private var adminSecretKey: String?
24
+ private var serverSecretKey: String?
25
+ private var clientSecretKey: String?
26
+
27
+ private var logType: LogType = .All
28
+
29
+ public init() {}
30
+
31
+ // Getters and Setters
32
+
33
+ public func getServerAddress() -> String { return self.serverAddress }
34
+ public func setServerAddress(_ serverAddress: String) { self.serverAddress = serverAddress }
35
+
36
+ public func getServerPort() -> Int { return self.serverPort }
37
+ public func setServerPort(_ serverPort: Int) { self.serverPort = serverPort }
38
+
39
+ public func getServerSocketPort() -> Int { return self.serverSocketPort }
40
+ public func setServerSocketPort(_ serverSocketPort: Int) { self.serverSocketPort = serverSocketPort }
41
+
42
+ public func isUseSsl() -> Bool { return self.useSsl }
43
+ public func setUseSsl(_ useSsl: Bool) { self.useSsl = useSsl }
44
+
45
+ public func isUseSocket() -> Bool { return self.useSocket }
46
+ public func setUseSocket(_ useSocket: Bool) { self.useSocket = useSocket }
47
+
48
+ public func isUseHttp() -> Bool { return self.useHttp }
49
+ public func setUseHttp(_ useHttp: Bool) { self.useHttp = useHttp }
50
+
51
+ public func getDefaultTimeoutInSeconds() -> Int { return self.defaultTimeoutInSeconds }
52
+ public func setDefaultTimeoutInSeconds(_ defaultTimeoutInSeconds: Int) { self.defaultTimeoutInSeconds = defaultTimeoutInSeconds }
53
+
54
+ public func getMessageType() -> MessageType { return self.messageType }
55
+ public func setMessageType(_ messageType: MessageType) { self.messageType = messageType }
56
+
57
+ public func getSendRate() -> Int { return self.sendRate }
58
+ public func setSendRate(_ sendRate: Int) { self.sendRate = sendRate }
59
+
60
+ public func getReconnectDelay() -> Int { return self.reconnectDelay }
61
+ public func setReconnectDelay(_ reconnectDelay: Int) { self.reconnectDelay = reconnectDelay }
62
+
63
+ public func getPingInterval() -> Float { return self.pingInterval }
64
+ public func setPingInterval(_ pingInterval: Float) { self.pingInterval = pingInterval }
65
+
66
+ public func getPingTimeout() -> Float { return self.pingTimeout }
67
+ public func setPingTimeout(_ pingTimeout: Float) { self.pingTimeout = pingTimeout }
68
+
69
+ public func getAdminSecretKey() -> String? { return self.adminSecretKey }
70
+ public func setAdminSecretKey(_ adminSecretKey: String?) { self.adminSecretKey = adminSecretKey }
71
+
72
+ public func getServerSecretKey() -> String? { return self.serverSecretKey }
73
+ public func setServerSecretKey(_ serverSecretKey: String?) { self.serverSecretKey = serverSecretKey }
74
+
75
+ public func getClientSecretKey() -> String? { return self.clientSecretKey }
76
+ public func setClientSecretKey(_ clientSecretKey: String?) { self.clientSecretKey = clientSecretKey }
77
+
78
+ public func getLogType() -> LogType { return self.logType }
79
+ public func setLogType(_ logType: LogType) { self.logType = logType }
80
+
81
+ public func getSocketUrl() -> String {
82
+ let proto = self.useSsl ? "https" : "http"
83
+ return self.serverPort < 0 ? "\(proto)://\(self.serverAddress)" : "\(proto)://\(self.serverAddress):\(self.serverSocketPort)"
84
+ }
85
+
86
+ public func getHttpUrl() -> String {
87
+ let proto = self.useSsl ? "https" : "http"
88
+ return self.serverPort < 0 ? "\(proto)://\(self.serverAddress)" : "\(proto)://\(self.serverAddress):\(self.serverPort)"
89
+ }
90
+
91
+ private var gameId: String = ""
92
+ public func getGameId() -> String { return self.gameId }
93
+ public func setGameId(_ gameId: String) { self.gameId = gameId }
94
+ }
95
+
@@ -0,0 +1,28 @@
1
+ import Foundation
2
+
3
+ public struct Commands {
4
+ public static let USER_AGENT: String = "User-Agent"
5
+
6
+ public static let CONTENT_TYPE: String = "Content-Type"
7
+ public static let ACCEPT: String = "Accept"
8
+ public static let CONTENT_LENGTH: String = "Content-Length"
9
+ public static let APPLICATION_JSON: String = "application/json"
10
+ public static let APPLICATION_MSGPACK: String = "application/msgpack"
11
+
12
+ public static let RequestAuthTokenCmd: String = "Auth-Token"
13
+ public static let RequestSecretCmd: String = "Secret-Key"
14
+ public static let RequestGameIdCmd: String = "Game-Id"
15
+
16
+ public static let RequestCmd_MsgPack: String = "rMsgPack"
17
+ public static let ResponseCmd_MsgPack: String = "rMsgPack"
18
+ public static let EventCmd_MsgPack: String = "eMsgPack"
19
+
20
+ public static let RequestCmd_Json: String = "rJson"
21
+ public static let ResponseCmd_Json: String = "rJson"
22
+ public static let EventCmd_Json: String = "eJson"
23
+
24
+ public static let Data: String = "data"
25
+ public static let File: String = "file"
26
+
27
+ public static let BaseUrl: String = "X-BaseUrl"
28
+ }
@@ -0,0 +1,10 @@
1
+ import Foundation
2
+
3
+ public struct EventCode {
4
+ public static let OnGamePlayerFriendUpdate: String = "onGamePlayerFriendUpdate"
5
+ public static let OnCharacterPlayerFriendUpdate: String = "onCharacterPlayerFriendUpdate"
6
+ public static let OnGamePlayerGroupUpdate: String = "onGamePlayerGroupUpdate"
7
+ public static let OnGroupMemberUpdate: String = "onGroupMemberUpdate"
8
+ public static let OnGroupMessageUpdate: String = "onGroupMessageUpdate"
9
+ public static let OnCharacterPlayerGroupUpdate: String = "onCharacterPlayerGroupUpdate"
10
+ }