Ejemplo n.º 1
0
    private void HandleSpawnRequest(InsightNetworkMessage netMsg)
    {
        RequestSpawn message = netMsg.ReadMessage <RequestSpawn>();

        if (SpawnThread(message))
        {
            //netMsg.Reply((short)MsgId.RequestSpawn, new RequestSpawn() {
            //    SceneName = message.SceneName,
            //    NetworkAddress = SpawnerNetworkAddress,
            //    UniqueID = Guid.NewGuid().ToString() });
        }
        else
        {
            netMsg.Reply((short)MsgId.Error, new ErrorMsg()
            {
                Text = "[ProcessSpawner] - Spawn failed"
            });
        }
    }
Ejemplo n.º 2
0
    //This is just an example. No actual authentication happens.
    //You would need to replace with your own logic. Perhaps with a DB connection.
    private void HandleLoginMsg(InsightNetworkMessage netMsg)
    {
        LoginMsg message = netMsg.ReadMessage <LoginMsg>();

        if (server.logNetworkMessages)
        {
            Debug.Log("[InsightServer] - Login Received: " + message.AccountName + " / " + message.AccountPassword);
        }

        registeredUsers.Add(new UserContainer()
        {
            username = message.AccountName, uniqueId = Guid.NewGuid().ToString(), connectionId = netMsg.connectionId
        });

        netMsg.Reply((short)MsgId.Status, new StatusMsg()
        {
            Text = "Login Sucessful!"
        });
    }
Ejemplo n.º 3
0
    //Instead of handling the msg here we will forward it to an available spawner.
    private void HandleSpawnRequestMsg(InsightNetworkMessage netMsg)
    {
        RequestSpawn message = netMsg.ReadMessage <RequestSpawn>();

        //Get all spawners that have atleast 1 slot free
        List <SpawnerContainer> freeSlotSpawners = new List <SpawnerContainer>();

        foreach (SpawnerContainer spawner in registeredSpawners)
        {
            if (spawner.CurrentThreads < spawner.MaxThreads)
            {
                freeSlotSpawners.Add(spawner);
            }
        }

        //sort by least busy spawner first
        freeSlotSpawners = freeSlotSpawners.OrderBy(x => x.CurrentThreads).ToList();
        server.SendToClient(freeSlotSpawners[0].connectionId, (short)MsgId.RequestSpawn, message, (callbackStatus, reader) =>
        {
            if (callbackStatus == CallbackStatus.Ok)
            {
                RequestSpawn callbackResponse = reader.ReadMessage <RequestSpawn>();
                if (server.logNetworkMessages)
                {
                    Debug.Log("[Spawn Callback] Game Created on Child Spawner: " + callbackResponse.UniqueID);
                }

                netMsg.Reply((short)MsgId.RequestSpawn, callbackResponse);
            }
            if (callbackStatus == CallbackStatus.Timeout)
            {
            }
            if (callbackStatus == CallbackStatus.Error)
            {
            }
        });
    }