Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -----------------------------------------------
- //
- // SAPHIRA CORE Version 1.0
- // Developed by Aryel 'DfKimera' Tupinambá
- //
- // File: server/sv.core.lua
- // Purpose: Core script. Manages and propagates events and hooks.
- // Version: 1.0
- // Last updated: 18-Oct-2009
- //
- // -----------------------------------------------
- // TO-DO: Relocate the config to its own place
- Config = {}
- Config.Hostname = "localhost"
- Config.Username = "saphira"
- Config.Password = ""
- Config.Database = "saphira"
- Saph = {}
- // Includes enums
- include("Saphira/gamemode/shared/saph.usermessages.lua")
- include("Saphira/gamemode/shared/saph.uicodes.lua")
- // Initializes global objects
- Saph.DB = nil
- Saph.Config = Config
- // Initializes cache tables
- Saph.Characters = {}
- Saph.Items = {}
- Saph.PlayerData = {}
- // ------------------------------
- // Function: Initialize
- // Called: When the server starts
- // Purpose: Initializes the database
- // ------------------------------
- function Saph:Initialize()
- Saph.DB = Database:New()
- Saph.DB:OpenConnection(Saph.Config)
- Saph:CacheData()
- end
- // ------------------------------
- // Function: CacheData
- // Purpose: Takes all current data from the database and caches locally for better speeds
- // ------------------------------
- function Saph:CacheData()
- local characters = Saph.DB:Get("characters", {'id','name','model','title'})
- for k,v in pairs(characters) do
- Saph.Characters[v['id']] = v
- end
- // TO-DO: Cache items, etc.
- end
- // ------------------------------
- // Function: PlayerSpawn
- // Called: When the player spawns for the first time
- // Purpose: Manages newly arrived players
- // ------------------------------
- function Saph:PlayerInitialSpawn(ply)
- Saph:RegisterPlayer(ply) //timer.Create( "Saphira.PlayerInitialSpawn", 1, 1, self.RegisterPlayer, ply )
- end
- // ------------------------------
- // Function: InitializePlayer
- // Purpose:
- // ------------------------------
- // TO-DO: Hook this event with cache transfer using the data exchanger.
- function Saph:InitializePlayer(ply)
- ply:Freeze()
- ply:ShowUI(Saph.UI.CharacterSelection)
- end
- // ------------------------------
- // Function: RegisterPlayer
- // Purpose: Registers the player in the database
- // ------------------------------
- function Saph:RegisterPlayer(ply)
- trace("Logging player: " .. ply:SteamID())
- playerData = Saph.DB:GetSingle("players", {'id'}, ply:SteamID(), "steamid")
- if(!playerData) then
- trace("Player is new, creating account...")
- playerData = {
- ip = ply:IPAddress(),
- steamid = ply:SteamID(),
- name = ply:Name()
- }
- SaphID = Saph.DB:Add("players", playerData)
- ply:SetNetworkedInt("SaphID", SaphID)
- // QUERY: Can networked ints be changed by the client?
- // If so, we'll have to add networked variables support on the data exchanger, and
- // make it integrate seamlessly with the Player object by adding a method to the metatable.
- trace("Account created! " .. ply:SteamID() .. " = " .. SaphID)
- Saph:InitializePlayer(ply)
- else
- SaphID = playerData.id
- ply:SetNetworkedInt("SaphID", SaphID)
- trace("Logged in! " .. ply:SteamID() .. " = " .. SaphID)
- Saph:InitializePlayer(ply)
- end
- end
- // ------------------------------
- // Function: CreateCharacter
- // Purpose: Creates a character
- // ------------------------------
- // TO-DO: Trigger the cache manager to update the clients cache. If the player just created a character, he's most likely going to use it.
- function Saph:CreateCharacter(ply, characterData)
- CharID = Saph.DB:Add("characters", characterData)
- table.insert( Saph.Characters, CharID, Character:New(CharID, characterData) )
- return CharID
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement