Always snap to grid

Legacy:Session

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
UT2003 :: Object >> Session (Ladder1.46)
  1. class Session extends Object within SessionMaster
  2. 	transient;
  3.  
  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. //-----------------------------------------------------------
  22.  
  23. struct SessionData
  24. {
  25.     var string Key;
  26.     var string Value;
  27. };
  28.  
  29. struct SessionMap
  30. {
  31. 	var string MapName;
  32. 	var int MapListOrder;
  33. 	var bool bRequired;
  34. };
  35.  
  36. struct SessionMutator
  37. {
  38. 	var string MutatorName;
  39. 	var bool bRequired;
  40. };
  41.  
  42. struct SessionServerActor
  43. {
  44. 	var string 	SAName;
  45. 	var bool	bRequired;
  46. };
  47.  
  48. // contains the ProfileConfigSet that this session applies to
  49. var private ProfileConfigSet PCS;
  50.  
  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;
  56.  
  57. // contains the unique identifier
  58. var private string hash;
  59.  
  60. // Input functions
  61. final function bool SetHash(string NewHash)
  62. {
  63. 	if (NewHash!="")
  64. 	{
  65. 		Hash = NewHash;
  66. 		return true;
  67. 	}
  68.  
  69. 	return false;
  70. }
  71.  
  72. function bool SetPCS(ProfileConfigSet TempPCS)
  73. {
  74. 	if (TempPCS != None)
  75. 	{
  76. 		PCS = TempPCS;
  77. 		return true;
  78. 	}
  79.  
  80. 	return false;
  81. }
  82.  
  83. function bool setValue(string Dataname, string value, bool bAddIfNotExists, optional out string oldValue)
  84. {
  85. 	local int i;
  86. 	local SessionData KVP;
  87.  
  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. 	}
  97.  
  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. }
  107.  
  108. function bool setMutator(string NewMutator, bool bAddIfNotExists, optional bool bRequired)
  109. {
  110. 	local int i;
  111. 	local SessionMutator tmp;
  112.  
  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. 	}
  121.  
  122. 	if (bAddIfNotExists)
  123. 	{
  124. 		tmp.MutatorName = NewMutator;
  125. 		tmp.bRequired = bRequired;
  126. 		Mutators[Mutators.Length] = tmp;
  127. 		return true;
  128. 	}
  129.  
  130. 	return false;
  131. }
  132.  
  133. function bool setMap(string NewMap, int NewOrder, bool bAddIfNotExists, optional bool bRequired)
  134. {
  135. 	local int i;
  136. 	local SessionMap tmp;
  137.  
  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. 	}
  147.  
  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. }
  158.  
  159. function bool SetServerActor(string NewActor, bool bAddIfNotExists, optional bool bRequired)
  160. {
  161. 	local int i;
  162. 	local SessionServerActor tmp;
  163.  
  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. 	}
  172.  
  173. 	if (bAddIfNotExists)
  174. 	{
  175. 		tmp.SAName = NewActor;
  176. 		tmp.bRequired = bRequired;
  177.  
  178. 		ServerActors[ServerActors.Length] = tmp;
  179. 		return true;
  180. 	}
  181.  
  182. 	return false;
  183. }
  184.  
  185. // Output functions
  186. final function string GetHash()
  187. {
  188. 	return Hash;
  189. }
  190.  
  191. function ProfileConfigSet GetPCS()
  192. {
  193. 	if (PCS != None)
  194. 		return PCS;
  195.  
  196. 	return None;
  197. }
  198.  
  199. function int getIdValue(int idx, out string DataName, out string DataValue)
  200. {
  201. 	if (idx < 0 || idx >= Data.Length)
  202. 		return -1;
  203.  
  204. 	DataName = Data[idx].Key;
  205. 	DataValue = Data[idx].Value;
  206. 	return idx;
  207. }
  208.  
  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;
  214.  
  215. 	return sdefault;
  216. }
  217.  
  218. function string getMutator(int idx)
  219. {
  220. 	if (idx < 0 || idx >= Mutators.Length)
  221. 		return "";
  222.  
  223. 	return Mutators[idx].MutatorName;
  224. }
  225.  
  226. function string getMap(int idx)
  227. {
  228. 	if (idx < 0 || idx >= Maps.Length)
  229. 		return "";
  230.  
  231. 	return Maps[idx].MapName;
  232. }
  233.  
  234. function string getServerActor(int idx)
  235. {
  236. 	if (idx < 0 || idx >= ServerActors.Length)
  237. 		return "";
  238.  
  239. 	return ServerActors[idx].SAName;
  240. }
  241.  
  242. // Maintenance
  243. final function ClearMutators()
  244. {
  245. 	Mutators.Length = 0;
  246. }
  247.  
  248. final function ClearMaps()
  249. {
  250. 	Maps.Length = 0;
  251. }
  252.  
  253. final function ClearData()
  254. {
  255. 	Data.Length = 0;
  256. }
  257.  
  258. final function ClearServerActors()
  259. {
  260. 	ServerActors.Length = 0;
  261. }
  262.  
  263. function bool delValue(string DataName)
  264. {
  265. 	local int i;
  266.  
  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. 	}
  275.  
  276. 	return false;
  277. }
  278.  
  279. function bool delMap(string MapName)
  280. {
  281. 	local int i;
  282.  
  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. 	}
  291.  
  292. 	return false;
  293. }
  294.  
  295. function bool delMutator(string Mutator)
  296. {
  297. 	local int i;
  298.  
  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. 	}
  307.  
  308. 	return false;
  309. }
  310.  
  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. }
  324.  
  325. // Utility
  326. final function ResetSession()
  327. {
  328. 	ClearMutators();
  329. 	ClearMaps();
  330. 	ClearData();
  331. 	ClearServerActors();
  332.  
  333. 	PCS = None;
  334. }
  335.  
  336. final function int GetMutatorLength()
  337. {
  338. 	return Mutators.Length;
  339. }
  340.  
  341. final function int GetDataLength()
  342. {
  343. 	return Data.Length;
  344. }
  345.  
  346. final function int GetMapLength()
  347. {
  348. 	return Maps.Length;
  349. }
  350.  
  351. final function int GetSALength()
  352. {
  353. 	return ServerActors.Length;
  354. }
  355.  
  356. final function int MapOrder(int idx)
  357. {
  358. 	if (idx < 0 || idx >= Maps.Length)
  359. 		return -1;
  360.  
  361. 	return Maps[idx].MapListOrder;
  362. }
  363.  
  364. final function bool HasData(string DataName)
  365. {
  366. 	local int i;
  367.  
  368. 	for (i=0;i<Data.Length;i++)
  369. 		if (Data[i].key ~= DataName)
  370. 			return true;
  371. 	return false;
  372. }
  373.  
  374. final function bool HasMutator(string MutatorName)
  375. {
  376. 	local int i;
  377.  
  378. 	for (i=0;i<Mutators.Length;i++)
  379. 		if (Mutators[i].MutatorName ~= MutatorName)
  380. 			return true;
  381. 	return false;
  382. }
  383.  
  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. }
  392.  
  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. }
  401.  
  402. final function bool MutRequired(string MutatorName)
  403. {
  404. 	local int i;
  405.  
  406. 	for (i=0;i<Mutators.Length;i++)
  407. 		if ((Mutators[i].MutatorName ~= MutatorName) && (Mutators[i].bRequired))
  408. 			return true;
  409. 	return false;
  410. }
  411.  
  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. }
  420.  
  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. }