Guest User

Untitled

a guest
Jan 5th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.85 KB | None | 0 0
  1. openAuth = {}
  2.  
  3. function openAuth.EnableTick()
  4. openAura.ShouldTick = true;
  5. end;
  6.  
  7. function openAuth.Initialize()
  8. openAura.config:Import("../gamemodes/openaura/mysql.cfg")
  9. openAura.config:Import("../gamemodes/openaura/owner.cfg")
  10. openAura.plugin:Call("OpenAuraCoreLoaded")
  11.  
  12. local useLocalMachineDate = openAura.config:Get('use_local_machine_date'):Get();
  13. local useLocalMachineTime = openAura.config:Get('use_local_machine_time'):Get();
  14. local defaultDate = openAura.option:GetKey('default_date');
  15. local defaultTime = openAura.option:GetKey('default_time');
  16. local defaultDays = openAura.option:GetKey('default_days');
  17. local username = openAura.config:Get('mysql_username'):Get();
  18. local password = openAura.config:Get('mysql_password'):Get();
  19. local database = openAura.config:Get('mysql_database'):Get();
  20. local dateInfo = os.date('*t');
  21. local host = openAura.config:Get('mysql_host'):Get();
  22. local success, value = pcall(tmysql.initialize, host, username, password, database, 3306, 6, 6);
  23. openAura.NoMySQL = !success;
  24.  
  25. if (useLocalMachineTime) then
  26. openAura.config:Get('minute_time'):Set(60);
  27. end;
  28.  
  29. openAura.config:SetInitialized(true);
  30. table.Merge(openAura.time, defaultTime);
  31. table.Merge(openAura.date, defaultDate);
  32. math.randomseed( os.time() );
  33.  
  34. if (useLocalMachineTime) then
  35. local realDay = dateInfo.wday - 1;
  36. if (realDay == 0) then
  37. realDay = #defaultDays;
  38. end;
  39. table.Merge( openAura.time, {
  40. minute = dateInfo.min,
  41. hour = dateInfo.hour,
  42. day = realDay
  43. } );
  44. openAura.NextDateTimeThink = SysTime() + (60 - dateInfo.sec);
  45. else
  46. table.Merge( openAura.time, openAura:RestoreSchemaData('time') );
  47. end;
  48.  
  49. if (useLocalMachineDate) then
  50. dateInfo.year = dateInfo.year + (defaultDate.year - dateInfo.year);
  51. table.Merge( openAura.time, {
  52. month = dateInfo.month,
  53. year = dateInfo.year,
  54. day = dateInfo.yday
  55. } );
  56. else
  57. table.Merge( openAura.date, openAura:RestoreSchemaData('date') );
  58. end;
  59.  
  60. AURA_CONVAR_LOG = openAura:CreateConVar('aura_log', 1);
  61.  
  62. for k, v in pairs(openAura.config.stored) do
  63. openAura.plugin:Call('OpenAuraConfigInitialized', k, v.value);
  64. end;
  65.  
  66. RunConsoleCommand('sv_usermessage_maxsize', '1024');
  67. openAura.plugin:Call('OpenAuraInitialized');
  68. openAura:LoadBans();
  69. end
  70.  
  71. if(!openAura)then
  72. openAura = GM;
  73.  
  74. AddCSLuaFile("cl_init.lua");
  75. DeriveGamemode("openaura");
  76. end;
  77.  
  78. function openAura:ManageThinkChecks()
  79. return;
  80. end;
  81.  
  82. function openAura:GetGameDescription()
  83. return '[OA-FINAL] '..self.schema:GetName();
  84. end
  85.  
  86. function openAura.option:GetColor(key)
  87. return key;
  88. end;
  89.  
  90. openAura.plugin:Call('OpenAuthInitialized', true);
  91.  
  92. function openAura:PlayerSpawn(player)
  93. if ( player:HasInitialized() ) then
  94. player:ShouldDropWeapon(false);
  95.  
  96. if (!player.lightSpawn) then
  97. self.player:SetWeaponRaised(player, false);
  98. self.player:SetRagdollState(player, RAGDOLL_RESET);
  99. self.player:SetAction(player, false);
  100. self.player:SetDrunk(player, false);
  101.  
  102. self.attributes:ClearBoosts(player);
  103. self.limb:ResetDamage(player);
  104.  
  105. self:PlayerSetModel(player);
  106. self:PlayerLoadout(player);
  107.  
  108. if ( player:FlashlightIsOn() ) then
  109. player:Flashlight(false);
  110. end;
  111.  
  112. player:SetForcedAnimation(false);
  113. player:SetCollisionGroup(COLLISION_GROUP_PLAYER);
  114. player:SetMaxHealth(100);
  115. player:SetMaxArmor(100);
  116. player:SetMaterial("");
  117. player:SetMoveType(MOVETYPE_WALK);
  118. player:Extinguish();
  119. player:UnSpectate();
  120. player:GodDisable();
  121. player:RunCommand("-duck");
  122. player:SetColor(255, 255, 255, 255);
  123.  
  124. player:SetCrouchedWalkSpeed( self.config:Get("crouched_speed"):Get() );
  125. player:SetWalkSpeed( self.config:Get("walk_speed"):Get() );
  126. player:SetJumpPower( self.config:Get("jump_power"):Get() );
  127. player:SetRunSpeed( self.config:Get("run_speed"):Get() );
  128.  
  129. if (player.firstSpawn) then
  130. local ammo = player:QueryCharacter("ammo");
  131.  
  132. for k, v in pairs(ammo) do
  133. if ( !string.find(k, "p_") and !string.find(k, "s_") ) then
  134. player:GiveAmmo(v, k); ammo[k] = nil;
  135. end;
  136. end;
  137. else
  138. player:UnLock();
  139. end;
  140. end;
  141.  
  142. if (player.lightSpawn and player.lightSpawnCallback) then
  143. player.lightSpawnCallback(player, true);
  144. player.lightSpawnCallback = nil;
  145. end;
  146.  
  147. self.plugin:Call("PostPlayerSpawn", player, player.lightSpawn, player.changeClass, player.firstSpawn);
  148. self.player:SetRecognises(player, player, RECOGNISE_TOTAL);
  149.  
  150. player.changeClass = false;
  151. player.lightSpawn = false;
  152. else
  153. player:KillSilent();
  154. end;
  155. end;
  156.  
  157. hook.OpenAuraCall = hook.Call;
  158. function hook.Call(name, gamemode, ...)
  159. local arguments = {...};
  160. local hookCall = hook.OpenAuraCall;
  161. if (!gamemode) then
  162. gamemode = openAura;
  163. end;
  164. if (name == 'EntityTakeDamage') then
  165. if ( openAura:DoEntityTakeDamageHook(gamemode, arguments) ) then
  166. return;
  167. end;
  168. end;
  169. if (name == 'PlayerDisconnected') then
  170. if ( !IsValid( arguments[1] ) ) then
  171. return;
  172. end;
  173. end;
  174. if (name == 'Lua_Preprocess') then
  175. if (arguments[1] == 'openAuth_loadDLC') then
  176. return arguments[3];
  177. end;
  178. end;
  179. if (name == 'PlayerSay') then
  180. arguments[2] = string.Replace(arguments[2], '~', "\"");
  181. end;
  182. local value = openAura.plugin:CallCachedHook( name, nil, unpack(arguments) );
  183. if (value == nil) then
  184. return hookCall( name, gamemode, unpack(arguments) );
  185. else
  186. return value;
  187. end;
  188. end;
  189.  
  190. function openAura:Think()
  191. self:CallTimerThink( CurTime() );
  192. end;
  193.  
  194. function openAura:SaveData()
  195. for k, v in ipairs( player.GetAll() ) do
  196. if ( v:HasInitialized() ) then v:SaveCharacter(); end;
  197. end;
  198. if ( !self.config:Get('use_local_machine_time'):Get() ) then
  199. self:SaveSchemaData( 'time', self.time:GetSaveData() );
  200. end;
  201. if ( !self.config:Get('use_local_machine_date'):Get() ) then
  202. self:SaveSchemaData( 'date', self.date:GetSaveData() );
  203. end;
  204. end;
  205.  
  206. function openAura:PlayerCanUseCharacter(player, character)
  207. if ( character.data['banned'] ) then
  208. return character.name..' is banned and cannot be used!';
  209. end;
  210. end;
  211.  
  212. function openAura:PlayerCanInteractCharacter(player, action, character)
  213. if ( self.quiz:GetEnabled() and !self.quiz:GetCompleted(player) ) then
  214. return false, 'You have not completed the quiz!';
  215. else
  216. return true;
  217. end;
  218. end;
  219.  
  220. function openAura:InitPostEntity()
  221. for k, v in ipairs( ents.GetAll() ) do
  222. if ( IsValid(v) and v:GetModel() ) then
  223. self.entity:SetMapEntity(v, true);
  224. self.entity:SetStartAngles( v, v:GetAngles() );
  225. self.entity:SetStartPosition( v, v:GetPos() );
  226. if ( self.entity:SetChairAnimations(v) ) then
  227. v:SetCollisionGroup(COLLISION_GROUP_WEAPON);
  228. local physicsObject = v:GetPhysicsObject();
  229. if ( IsValid(physicsObject) ) then
  230. physicsObject:EnableMotion(false);
  231. end;
  232. end;
  233. end;
  234. end;
  235. self.entity:RegisterSharedVars(GetWorldEntity(), self.GlobalSharedVars);
  236. openAura:SetSharedVar('noMySQL', self.NoMySQL);
  237. self.plugin:Call('OpenAuraInitPostEntity');
  238. openAuth.EnableTick();
  239. end;
  240.  
  241. function openAura:PlayerInitialSpawn(player)
  242. player.hasSpawned = true;
  243. player.characters = {};
  244. player.sharedVars = {};
  245. if ( IsValid(player) ) then
  246. player:KillSilent();
  247. end;
  248. if ( player:IsBot() ) then
  249. self.config:Send(player);
  250. end;
  251. if ( !player:IsKicked() ) then
  252. self.chatBox:Add(nil, nil, 'connect', player:SteamName()..' has connected to the server.');
  253. end;
  254. end;
  255.  
  256. function openAura:PlayerDeathThink(player)
  257. local action = self.player:GetAction(player);
  258. if ( !player:HasInitialized() or player:GetCharacterData('banned') ) then
  259. return true;
  260. end;
  261. if ( player:IsCharacterMenuReset() ) then
  262. return true;
  263. end;
  264. if (action == 'spawn') then
  265. return true;
  266. else
  267. player:Spawn();
  268. end;
  269. end;
  270.  
  271. function openAura.player:ConvertDataString(player, data)
  272. local success, value = pcall( Json.Decode, self:Unescape(data) );
  273. if (success) then
  274. return value;
  275. else
  276. return {};
  277. end;
  278. end;
Add Comment
Please, Sign In to add comment