Beispiel #1
0
    protected void HandleBytes(byte[] buffer)
    {
        InsightNetworkMessageDelegate msgDelegate;
        NetworkReader reader     = new NetworkReader(buffer);
        var           msgType    = reader.ReadInt16();
        var           callbackId = reader.ReadInt32();
        var           msg        = new InsightNetworkMessage(insightNetworkConnection, callbackId)
        {
            msgType = msgType, reader = reader
        };

        if (callbacks.ContainsKey(callbackId))
        {
            callbacks[callbackId].callback.Invoke(CallbackStatus.Ok, msg);
            callbacks.Remove(callbackId);
        }
        else if (messageHandlers.TryGetValue(msgType, out msgDelegate))
        {
            msgDelegate(msg);
        }
        else
        {
            //NOTE: this throws away the rest of the buffer. Need moar error codes
            Debug.LogError("Unknown message ID " + msgType);// + " connId:" + connectionId);
        }
    }
Beispiel #2
0
    private void HandleData(int connectionId, byte[] data)
    {
        NetworkReader            reader     = new NetworkReader(data);
        var                      msgType    = reader.ReadInt16();
        var                      callbackId = reader.ReadInt32();
        InsightNetworkConnection insightNetworkConnection;

        if (!connections.TryGetValue(connectionId, out insightNetworkConnection))
        {
            Debug.LogError("HandleData: Unknown connectionId: " + connectionId, this);
            return;
        }

        if (callbacks.ContainsKey(callbackId))
        {
            var msg = new InsightNetworkMessage(insightNetworkConnection, callbackId)
            {
                msgType = msgType, reader = reader
            };
            callbacks[callbackId].callback.Invoke(CallbackStatus.Ok, msg);
            callbacks.Remove(callbackId);

            CheckForFinishedCallback(callbackId);
        }
        else
        {
            insightNetworkConnection.TransportReceive(data);
        }
    }
Beispiel #3
0
    public void HandleChatMsg(InsightNetworkMessage netMsg)
    {
        Debug.Log("[InsightClient] - HandleChatMsg()");

        ChatMsg message = netMsg.ReadMessage <ChatMsg>();

        chatLog += message.Origin + ": " + message.Data + "\n";
    }
Beispiel #4
0
    private void HandleGetZonesMsg(InsightNetworkMessage netMsg)
    {
        //Request from Server for a list of all active Zones

        netMsg.conn.Send(GetZonesMsg.MsgId, new GetZonesMsg()
        {
            zonesList = ZoneList.ToArray()
        });
    }
Beispiel #5
0
    private void HandleChatMsg(InsightNetworkMessage netMsg)
    {
        if (server.logNetworkMessages)
        {
            Debug.Log("[InsightServer] - HandleChatMsg()");
        }

        ChatMsg message = netMsg.ReadMessage <ChatMsg>();

        server.SendToAll((short)MsgId.Chat, message); //Broadcast back to all other clients
    }
Beispiel #6
0
    private void HandleSpawnerStatusMsg(InsightNetworkMessage netMsg)
    {
        SpawnerStatus message = netMsg.ReadMessage <SpawnerStatus>();

        for (int i = 0; i < registeredSpawners.Count; i++)
        {
            if (registeredSpawners[i].connectionId == netMsg.connectionId)
            {
                SpawnerContainer instance = registeredSpawners[i];
                instance.CurrentThreads = message.CurrentThreads;
            }
        }
    }
Beispiel #7
0
    private void HandleUnregisterZoneMsg(InsightNetworkMessage netMsg)
    {
        print("HandleUnregisterZoneMsg");

        UnregisterZoneMsg message = netMsg.ReadMessage <UnregisterZoneMsg>();

        foreach (ZoneContainer zone in ZoneList)
        {
            if (zone.UniqueID.Equals(message.UniqueID))
            {
                ZoneList.Remove(zone);
            }
        }
    }
Beispiel #8
0
    private void HandleChangeServersMsg(InsightNetworkMessage netMsg)
    {
        ChangeServers message = netMsg.ReadMessage <ChangeServers>();

        if (client.logNetworkMessages)
        {
            Debug.Log("[InsightClient] - Connecting to GameServer: " + message.NetworkAddress + ":" + message.NetworkPort + "/" + message.SceneName);
        }

        networkManager.networkAddress = message.NetworkAddress;
        transport.port = message.NetworkPort;
        SceneManager.LoadScene(message.SceneName);
        networkManager.StartClient();
    }
Beispiel #9
0
    private void HandleRegisterSpawnerMsg(InsightNetworkMessage netMsg)
    {
        RegisterSpawnerMsg message = netMsg.ReadMessage <RegisterSpawnerMsg>();

        //Add the new child spawner to the list of spawners
        registeredSpawners.Add(new SpawnerContainer()
        {
            uniqueId = message.UniqueID, connectionId = netMsg.connectionId, MaxThreads = message.MaxThreads
        });

        if (server.logNetworkMessages)
        {
            Debug.Log("[MasterSpawner] - New Process Spawner Regsitered");
        }
    }
Beispiel #10
0
    private void HandleRegisterZoneMsg(InsightNetworkMessage netMsg)
    {
        print("HandleRegisterZoneMsg");

        RegisterZoneMsg message = netMsg.ReadMessage <RegisterZoneMsg>();

        ZoneList.Add(new ZoneContainer()
        {
            UniqueID       = message.UniqueID,
            ScenePath      = message.ScenePath,
            NetworkAddress = message.NetworkAddress,
            NetworkPort    = message.NetworkPort,
            MaxPlayers     = message.MaxPlayers,
            CurentPlayers  = message.CurentPlayers
        });
    }
Beispiel #11
0
    private void HandleRegisterGameMsg(InsightNetworkMessage netMsg)
    {
        RegisterGameMsg message = netMsg.ReadMessage <RegisterGameMsg>();

        if (server.logNetworkMessages)
        {
            Debug.Log("Received GameRegistration request");
        }

        registeredGameServers.Add(new GameContainer()
        {
            connectionId   = netMsg.connectionId,
            UniqueId       = message.UniqueID,
            SceneName      = message.SceneName,
            NetworkAddress = message.NetworkAddress,
            NetworkPort    = message.NetworkPort
        });
    }
Beispiel #12
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!"
        });
    }
Beispiel #13
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"
            });
        }
    }
Beispiel #14
0
    private void HandleChatMessage(InsightNetworkMessage netMsg)
    {
        InsightChatMessage message = netMsg.ReadMessage <InsightChatMessage>();

        switch (message.ChannelType)
        {
        //Send message from Origin to Target
        case (short)ChatChannelType.Private:
            Debug.Log("Type: " + message.ChannelType + " Origin: " + message.Origin + " Target: " + message.Target + " Message: " + message.Message);
            //NetworkConnection conn = insightServer.FindConnectionByPlayer(message.Target);
            //conn.Send(InsightChatMessage.MsgId, message);
            break;

        //Send message to all players on same Zone
        case (short)ChatChannelType.Public:
            Debug.Log("Type: " + message.ChannelType + " Origin: " + message.Origin + " Message: " + message.Message);
            //How to find what zone an player is in?
            break;

        //Send to all players on all zones (admin only later)
        case (short)ChatChannelType.Global:
            Debug.Log("Type: " + message.ChannelType + " Origin: " + message.Origin + " Message: " + message.Message);
            //How to find all players logged into all zones.
            break;

        case (short)ChatChannelType.Party:
            Debug.Log("Type: " + message.ChannelType + " Origin: " + message.Origin + " Message: " + message.Message);
            break;

        case (short)ChatChannelType.Guild:
            Debug.Log("Type: " + message.ChannelType + " Origin: " + message.Origin + " Message: " + message.Message);
            break;

        default:
            Debug.LogError("Received unexpected ChatChannelType");
            break;
        }
    }
Beispiel #15
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)
            {
            }
        });
    }
    // handle this message
    // note: original HLAPI HandleBytes function handled >1 message in a while loop, but this wasn't necessary
    //       anymore because NetworkServer/NetworkClient.Update both use while loops to handle >1 data events per
    //       frame already.
    //       -> in other words, we always receive 1 message per Receive call, never two.
    //       -> can be tested easily with a 1000ms send delay and then logging amount received in while loops here
    //          and in NetworkServer/Client Update. HandleBytes already takes exactly one.
    protected void HandleBytes(byte[] buffer)
    {
        // unpack message
        ushort msgType;

        byte[] content;
        if (Protocol.UnpackMessage(buffer, out msgType, out content))
        {
            if (logNetworkMessages)
            {
                Debug.Log("ConnectionRecv con:" + connectionId + " msgType:" + msgType + " content:" + BitConverter.ToString(content));
            }

            InsightNetworkMessageDelegate msgDelegate;
            if (m_MessageHandlers.TryGetValue((short)msgType, out msgDelegate))
            {
                // create message here instead of caching it. so we can add it to queue more easily.
                InsightNetworkMessage msg = new InsightNetworkMessage();
                msg.msgType = (short)msgType;
                msg.reader  = new NetworkReader(content);
                msg.conn    = this;

                msgDelegate(msg);
                lastMessageTime = Time.time;
            }
            else
            {
                //NOTE: this throws away the rest of the buffer. Need moar error codes
                Debug.LogError("Unknown message ID " + msgType + " connId:" + connectionId);
            }
        }
        else
        {
            Debug.LogError("HandleBytes UnpackMessage failed for: " + BitConverter.ToString(buffer));
        }
    }
Beispiel #17
0
    private void HandleZoneServerSpawnRequest(InsightNetworkMessage netMsg)
    {
        ZoneServerSpawnRequest message = netMsg.ReadMessage <ZoneServerSpawnRequest>();

        print("HandleZoneServerSpawnRequest - " + message.SceneName);
    }
Beispiel #18
0
 private void HandleClientToMasterTestMsg(InsightNetworkMessage netMsg)
 {
 }