--[[
    SocietixM Preloaded Map Model - Server Script
    This script runs on the server when the map is loaded
]]

local SocietixMPlugin = script.Parent:FindFirstChild("SocietixMPlugin")
if not SocietixMPlugin then
    warn("[SocietixM] SocietixMPlugin not found in map model")
    return
end

local Server = require(SocietixMPlugin.Server)
local Network = require(SocietixMPlugin.Network)
local Core = require(SocietixMPlugin.Core)

-- Initialize the server
local server = Server.new()
server:Initialize()

-- Create default server configuration
local defaultConfig = {
    Name = "SocietixM Custom Server",
    Description = "A custom server created with SocietixM Map Model",
    RobloxGameId = tostring(game.PlaceId),
    MaxPlayers = 20,
    IsPrivate = true,
    AllowFriends = true,
    AllowSpectators = false,
    Region = "US-East",
    EnableMods = true,
    Password = "",
    MapName = game.Workspace.Name or "Custom Map",
    GameMode = "Free Play"
}

-- Create the server
local success = server:Create(defaultConfig)
if success then
    print("[SocietixM] Server created successfully with map model")
    
    -- Auto-start the server
    server:Start()
    
    -- Set up server events
    game:BindToClose(function()
        server:Shutdown()
    end)
    
    -- Update server info periodically
    spawn(function()
        while server.IsRunning do
            wait(30) -- Update every 30 seconds
            server:RegisterServer()
        end
    end)
else
    warn("[SocietixM] Failed to create server with map model")
end
