Always snap to grid

Legacy:SessionMaster

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
UT2003 :: Object >> SessionMaster (Ladder1.46)
  1. //-----------------------------------------------------------
  2. // Ladder.SessionMaster
  3. // Sessions concept by El_Muerte[TDS]
  4. // http://wiki.beyondunreal.com/wiki/Sessions
  5. //
  6. // Controls and tracks all Session objects for use by webadmin
  7. //-----------------------------------------------------------
  8. class SessionMaster extends Object transient;
  9.  
  10. var array<Session> Sessions;
  11.  
  12. // get a session by it's hash
  13. function Session getSession(string hash, optional bool bCreateNew)
  14. {
  15. 	local int i;
  16.  
  17. 	for (i = 0; i < sessions.length; i++) if (Sessions[i].GetHash() == hash) return Sessions[i];
  18. 	if (bCreateNew) return createSession();
  19. 	return none;
  20. }
  21.  
  22. // destroy an existing session
  23. function bool destroySession(Session session)
  24. {
  25. 	local int i;
  26. 	local string Hash;
  27.  
  28.   	Hash = Session.GetHash();
  29. 	for (i = 0; i < sessions.length; i++)
  30. 		if (Sessions[i].GetHash() == Hash)
  31. 		{
  32.  
  33. 			Sessions.Remove(i, 1);
  34. 			return true;
  35. 		}
  36.  
  37. 	return false;
  38. }
  39.  
  40. // create a new session
  41. private function Session createSession()
  42. {
  43. 	local Session TempS;
  44.  
  45. 	TempS = new class'Session';
  46. 	if (TempS.SetHash(CreateSessionHash())) Sessions[Sessions.Length] = TempS;
  47.  
  48. 	return TempS;
  49. }
  50.  
  51. // create a unique session hash
  52. function string createSessionHash()
  53. {
  54. 	local int i;
  55. 	local string temphash;
  56.  
  57. 	do {
  58. 		temphash = Right("00000"$string(Rand(65536)), 5)$Right("00000"$string(Rand(65536)), 5);
  59. 		for (i = 0; i < sessions.length; i++)
  60. 			if (Sessions[i].GetHash() == temphash) break;
  61. 	} until (i == sessions.length);
  62.   return temphash;
  63. }