Legacy:Session - Unreal Wiki

# Legacy:Session

### From Unreal Wiki, The Unreal Engine Documentation Site

UT2003 :: Object >> Session (Ladder1.46)

1. class Session extends Object within SessionMaster
2. transient;
4. //-----------------------------------------------------------
5. // Ladder.Session
6. // Sessions concept by El_Muerte[TDS]
7. // http://wiki.beyondunreal.com/wiki/Sessions
8. //
9. // Data container used by webadmin - tracked by SessionMaster
10. // Session "hashes" (10 digit number unique to each Session object)
11. // are generated by SessionMaster at server startup
12. //
13. // Session hashes are passed via form submittal, often taking advantage
14. // of the Webserver's ability to parse directly injected form labels
15. // (?VarName=VarValue)
16. //
17. // Session hashes are queried from the WebRequest object
18. // each connection - this allows easy access to unlimited amounts
19. // of related data across the entire class, without risking corruption
20. // across threads (such as would be the case with global variables)
21. //-----------------------------------------------------------
23. struct SessionData
24. {
25. var string Key;
26. var string Value;
27. };
29. struct SessionMap
30. {
31. var string MapName;
32. var int MapListOrder;
33. var bool bRequired;
34. };
36. struct SessionMutator
37. {
38. var string MutatorName;
39. var bool bRequired;
40. };
42. struct SessionServerActor
43. {
44. var string SAName;
45. var bool bRequired;
46. };
48. // contains the ProfileConfigSet that this session applies to
49. var private ProfileConfigSet PCS;
51. // contains the data for this session
52. var private array<SessionData> Data;
53. var private array<SessionMutator> Mutators;
54. var private array<SessionMap> Maps;
55. var private array<SessionServerActor> ServerActors;
57. // contains the unique identifier
58. var private string hash;
60. // Input functions
61. final function bool SetHash(string NewHash)
62. {
63. if (NewHash!="")
64. {
65. Hash = NewHash;
66. return true;
67. }
69. return false;
70. }
72. function bool SetPCS(ProfileConfigSet TempPCS)
73. {
74. if (TempPCS != None)
75. {
76. PCS = TempPCS;
77. return true;
78. }
80. return false;
81. }
83. function bool setValue(string Dataname, string value, bool bAddIfNotExists, optional out string oldValue)
84. {
85. local int i;
86. local SessionData KVP;
88. for (i = 0; i<data.length; i++)
89. {
90. if (data[i].key ~= Dataname)
91. {
92. oldValue = data[i].value;
93. data[i].value = value;
94. return true;
95. }
96. }
98. if (bAddIfNotExists)
99. {
100. KVP.Key = DataName;
101. KVP.Value = Value;
102. Data[Data.Length] = KVP;
103. return true;
104. }
105. return false;
106. }
108. function bool setMutator(string NewMutator, bool bAddIfNotExists, optional bool bRequired)
109. {
110. local int i;
111. local SessionMutator tmp;
113. for (i=0;i<Mutators.Length;i++)
114. {
115. if (Mutators[i].MutatorName ~= NewMutator)
116. {
117. Mutators[i].bRequired = bRequired;
118. return true;
119. }
120. }
122. if (bAddIfNotExists)
123. {
124. tmp.MutatorName = NewMutator;
125. tmp.bRequired = bRequired;
126. Mutators[Mutators.Length] = tmp;
127. return true;
128. }
130. return false;
131. }
133. function bool setMap(string NewMap, int NewOrder, bool bAddIfNotExists, optional bool bRequired)
134. {
135. local int i;
136. local SessionMap tmp;
138. for (i=0;i<Maps.Length;i++)
139. {
140. if (Maps[i].MapName ~= NewMap)
141. {
142. Maps[i].MapListOrder = NewOrder;
143. Maps[i].bRequired = bRequired;
144. return true;
145. }
146. }
148. if (bAddIfNotExists)
149. {
150. tmp.MapName = NewMap;
151. tmp.bRequired = bRequired;
152. tmp.MapListOrder = NewOrder;
153. Maps[Maps.Length] = tmp;
154. return true;
155. }
156. return false;
157. }
159. function bool SetServerActor(string NewActor, bool bAddIfNotExists, optional bool bRequired)
160. {
161. local int i;
162. local SessionServerActor tmp;
164. for (i=0;i<ServerActors.Length;i++)
165. {
166. if (ServerActors[i].SAName ~= NewActor)
167. {
168. ServerActors[i].bRequired = bRequired;
169. return true;
170. }
171. }
173. if (bAddIfNotExists)
174. {
175. tmp.SAName = NewActor;
176. tmp.bRequired = bRequired;
178. ServerActors[ServerActors.Length] = tmp;
179. return true;
180. }
182. return false;
183. }
185. // Output functions
186. final function string GetHash()
187. {
188. return Hash;
189. }
191. function ProfileConfigSet GetPCS()
192. {
193. if (PCS != None)
194. return PCS;
196. return None;
197. }
199. function int getIdValue(int idx, out string DataName, out string DataValue)
200. {
201. if (idx < 0 || idx >= Data.Length)
202. return -1;
204. DataName = Data[idx].Key;
205. DataValue = Data[idx].Value;
206. return idx;
207. }
209. function string getValue(string name, optional string sdefault)
210. {
211. local int i;
212. for (i = 0; i<data.length; i++)
213. if (data[i].key == name) return data[i].value;
215. return sdefault;
216. }
218. function string getMutator(int idx)
219. {
220. if (idx < 0 || idx >= Mutators.Length)
221. return "";
223. return Mutators[idx].MutatorName;
224. }
226. function string getMap(int idx)
227. {
228. if (idx < 0 || idx >= Maps.Length)
229. return "";
231. return Maps[idx].MapName;
232. }
234. function string getServerActor(int idx)
235. {
236. if (idx < 0 || idx >= ServerActors.Length)
237. return "";
239. return ServerActors[idx].SAName;
240. }
242. // Maintenance
243. final function ClearMutators()
244. {
245. Mutators.Length = 0;
246. }
248. final function ClearMaps()
249. {
250. Maps.Length = 0;
251. }
253. final function ClearData()
254. {
255. Data.Length = 0;
256. }
258. final function ClearServerActors()
259. {
260. ServerActors.Length = 0;
261. }
263. function bool delValue(string DataName)
264. {
265. local int i;
267. for (i=0;i<Data.Length;i++)
268. {
269. if (Data[i].Key ~= DataName)
270. {
271. Data.Remove(i,1);
272. return true;
273. }
274. }
276. return false;
277. }
279. function bool delMap(string MapName)
280. {
281. local int i;
283. for (i=0;i<Maps.Length;i++)
284. {
285. if (Maps[i].MapName ~= MapName)
286. {
287. Maps.Remove(i,1);
288. return true;
289. }
290. }
292. return false;
293. }
295. function bool delMutator(string Mutator)
296. {
297. local int i;
299. for (i=0;i<Mutators.Length;i++)
300. {
301. if (Mutators[i].MutatorName ~= Mutator)
302. {
303. Mutators.Remove(i,1);
304. return true;
305. }
306. }
308. return false;
309. }
311. function bool delServerActor(string ActorName)
312. {
313. local int i;
314. for (i=0;i<ServerActors.Length;i++)
315. {
316. if (ServerActors[i].SAName ~= ActorName)
317. {
318. ServerActors.Remove(i,1);
319. return true;
320. }
321. }
322. return false;
323. }
325. // Utility
326. final function ResetSession()
327. {
328. ClearMutators();
329. ClearMaps();
330. ClearData();
331. ClearServerActors();
333. PCS = None;
334. }
336. final function int GetMutatorLength()
337. {
338. return Mutators.Length;
339. }
341. final function int GetDataLength()
342. {
343. return Data.Length;
344. }
346. final function int GetMapLength()
347. {
348. return Maps.Length;
349. }
351. final function int GetSALength()
352. {
353. return ServerActors.Length;
354. }
356. final function int MapOrder(int idx)
357. {
358. if (idx < 0 || idx >= Maps.Length)
359. return -1;
361. return Maps[idx].MapListOrder;
362. }
364. final function bool HasData(string DataName)
365. {
366. local int i;
368. for (i=0;i<Data.Length;i++)
369. if (Data[i].key ~= DataName)
370. return true;
371. return false;
372. }
374. final function bool HasMutator(string MutatorName)
375. {
376. local int i;
378. for (i=0;i<Mutators.Length;i++)
379. if (Mutators[i].MutatorName ~= MutatorName)
380. return true;
381. return false;
382. }
384. final function bool HasMap(string MapName)
385. {
386. local int i;
387. for (i=0;i<Maps.Length;i++)
388. if (Maps[i].MapName ~= MapName)
389. return true;
390. return false;
391. }
393. final function bool HasServerActor(string ActorName)
394. {
395. local int i;
396. for (i=0;i<ServerActors.Length;i++)
397. if (ServerActors[i].SAName ~= ActorName)
398. return true;
399. return false;
400. }
402. final function bool MutRequired(string MutatorName)
403. {
404. local int i;
406. for (i=0;i<Mutators.Length;i++)
407. if ((Mutators[i].MutatorName ~= MutatorName) && (Mutators[i].bRequired))
408. return true;
409. return false;
410. }
412. final function bool MapRequired(string MapName)
413. {
414. local int i;
415. for (i=0;i<Maps.Length;i++)
416. if (Maps[i].MapName ~= MapName)
417. return Maps[i].bRequired;
418. return false;
419. }
421. final function bool SARequired(string ActorName)
422. {
423. local int i;
424. for (i=0;i<ServerActors.Length;i++)
425. if (ServerActors[i].SAName ~= ActorName)
426. return ServerActors[i].bRequired;
427. return false;
428. }

##### Views

- Legacy
- Discussion
- Current revision

##### Search