コード例 #1
0
ファイル: Client.cs プロジェクト: TiernanMcCarthy/GameJam2020
    private void onData(int ConnectionId, int channelId, int recHostId, nMsg msg)
    {
        switch (msg.OP) //Server Recieves much data than the client
        {
        case NetOP.None:
            Debug.Log("Incorrect initialisation");
            break;

        case NetOP.Position:
            n_Position Decode = (n_Position)msg;
            //Player.NetworkInstance.ObjectID = (int)Decode.Position.x;
            //Player.ID = (int)Decode.Position.x;
            //checkMoving.PlayerID = Player.ID;
            //Test.transform.position = ((n_Position)msg).Position+OffsetDistance;
            break;

        case NetOP.SyncSceneObjects:
            Debug.Log("SceneObjects");
            UpdatedObjectContainer temp = (UpdatedObjectContainer)msg;
            checkMoving.SyncObjects(temp.SceneObjects);
            break;

        case NetOP.NewPlayer:
            nPlayerNew PlayerType = (nPlayerNew)msg;
            //  spawn.Spawn(true, PlayerType.ID);
            break;

        case NetOP.Action:
            nAction ActionToggle = (nAction)msg;
            crystalize.crystalize();
            break;
        }
    }
コード例 #2
0
ファイル: Server.cs プロジェクト: TiernanMcCarthy/GameJam2020
    public void UpdateMessagePump()
    {
        if (!Started) //Don't do this stuff if you don't need to
        {
            return;
        }

        int recHostId;                         //Host ID
        int connectionId;                      //User ID
        int channelId;                         //Which lane is this occuring through

        byte[] recBuffer = new byte[ByteSize]; //recieving buffer
        int    dataSize;
        //byte error;
        //Decode incoming data
        NetworkEventType type = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, ByteSize, out dataSize, out error);

        switch (type)
        {
        case NetworkEventType.Nothing:
            break;

        case NetworkEventType.ConnectEvent:
            Debug.Log(string.Format("User {0} has connected from host {1}", connectionId, recHostId));
            ClientID = connectionId;
            Clients.Add(ClientID);
            rechost = recHostId;

            //player.Spawn(true,connectionId);
            n_Position SendID = new n_Position();
            SendID.Position = new SerialVector3(connectionId, 0, 0);
            SendClient(rechost, connectionId, SendID);

            nPlayerNew playerNew = new nPlayerNew();
            playerNew.ID = connectionId;

            SendClients(playerNew);
            //nPlayerNew playerNew = new nPlayerNew();



            //Connect = true;
            // Connection.text = "Client Connected";
            // ConnectionConfig cc = new ConnectionConfig();
            //ReliableChannel = cc.AddChannel(QosType.UnreliableSequenced);
            break;

        case NetworkEventType.DisconnectEvent:
            Debug.Log(string.Format("User {0} has disconnected", connectionId));
            // Connection.text = "Client Disconnected";
            // Connect = false;
            break;

        case NetworkEventType.DataEvent:
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    ms        = new MemoryStream(recBuffer);     //designate memory from ram to load this into msg
            nMsg            msg       = (nMsg)formatter.Deserialize(ms); //Decode this data and deserialise it into something recognisable

            onData(connectionId, channelId, recHostId, msg);
            break;

        default:
        case NetworkEventType.BroadcastEvent:
            Debug.Log("Unexpected network event type");
            break;
        }
    }