Beispiel #1
0
    // Start
    void Start()
    {
        NetworkTransport.Init();

        reliableChannel   = config.AddChannel(QosType.Reliable);
        unreliableChannel = config.AddChannel(QosType.Unreliable);

        var hostTopology = new HostTopology(config, maxConnections);

        hostId = NetworkTransport.AddHost(hostTopology, port);

        receiveBuffer = new byte[bufferSize];

        onConnect += (connectionId) => {
            Debug.Log("Player " + connectionId + " connected.");

            var player = new NetworkTarget(connectionId);
            NetworkPlayers.Add(player);

            // Send connected message
            player.Send(ServerMessage.Connected);
        };

        onDisconnect += (connectionId) => {
            Debug.Log("Player " + connectionId + " disconnected.");
            NetworkPlayers.Remove(NetworkPlayers.Find(connectionId));
        };

        isStarted = true;
    }
Beispiel #2
0
    // Start
    void Start()
    {
        Console.instance.Log("Connecting to server...");

        NetworkTransport.Init();
        RPCManager.instance.Register(this);

        reliableChannel   = config.AddChannel(QosType.Reliable);
        unreliableChannel = config.AddChannel(QosType.Unreliable);
        receiveBuffer     = new byte[bufferSize];

        var hostTopology = new HostTopology(config, maxConnections);

        hostId       = NetworkTransport.AddHost(hostTopology, 0);
        connectionId = NetworkTransport.Connect(hostId, address, port, 0, out error);

        server = new NetworkTarget(connectionId);
        NetworkPlayers.Add(server);

        if ((NetworkError)error != NetworkError.Ok)
        {
            Console.instance.Log("Connection failed: " + (NetworkError)error);
        }

        onConnect += () => {
            isConnected = true;
            Console.instance.Log("Connected to server.");
        };

        isStarted = true;
    }
 private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
     }
 }
Beispiel #4
0
 // Manage the singleton instance
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Beispiel #5
0
    // Only called by Unity on server
    public void uLink_OnPlayerConnected(uLink.NetworkPlayer player)
    {
        // Explictly add players to the Character group ID, so that they can
        // still see what happens even if they don't have a character currently
        // spawned.
        if (!player.isServer)
        {
            uLink.Network.AddPlayerToGroup(player, Relay.CharacterSpawnGroupID);
        }

        NetworkPlayers.Add(player);
    }
    private void Start()
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("it");
        if (GameObject.FindGameObjectsWithTag("NetworkManager").Length > 1)
        {
            Destroy(gameObject);
            return;
        }

        messageHandler     = GetComponent <MessageHandler>();
        networkPlayer      = GetComponent <NetworkPlayers>();
        networkMap         = GetComponent <NetworkMapManager>();
        networkFps         = GetComponent <NetworkFPSManager>();
        networkEntity      = GetComponent <NetworkEntityManager>();
        networkLeaderboard = GetComponent <NetworkLeaderboard>();
        DontDestroyOnLoad(this);
        CreateServer();
    }
Beispiel #7
0
    // HandleMessage
    public void HandleMessage(byte[] buffer, int connectionId)
    {
        var reader = new NetworkReader(buffer);

        // Message type
        MessageType msgType = reader.ReadByte();

        NetworkCall call;
        bool        exists = functions.TryGetValue(msgType, out call);

        if (!exists)
        {
            Debug.LogError("Unknown message type: " + msgType);
            return;
        }

        var methodParams = call.method.GetParameters();
        var invokeParams = new object[methodParams.Length];

        for (var i = 0; i < methodParams.Length; i++)
        {
            var param     = methodParams[i];
            var paramType = param.ParameterType;

            if (paramType == typeof(NetworkTarget))
            {
                invokeParams[i] = NetworkPlayers.Find(connectionId);
                continue;
            }

            invokeParams[i] = Serialization.Read(reader, paramType);
        }

        // Call the method
        call.method.Invoke(call.obj, invokeParams);
    }
Beispiel #8
0
        /// <summary>
        /// Display messages and peform any actions
        /// </summary>
        /// <param name="composite"></param>
        public void ProcessMessage(CompositeType composite)
        {
            IRequest request = Newtonsoft.Json.JsonConvert.DeserializeObject <RPCRequest>(composite.Message);

            this.InComingRequests.Add(request);
            this.LastMessage = composite.Message;

            switch (request.Method)
            {
            case "NewPeer":
                NewPeerRequest newPeer = Newtonsoft.Json.JsonConvert.DeserializeObject <NewPeerRequest>(request.Params.ToString());
                NetworkPlayers.Add(newPeer.Player);

                break;

            case "NewTable":     //Peer has announced a new table

                BitPoker.Models.Contracts.Table newTable = Newtonsoft.Json.JsonConvert.DeserializeObject <BitPoker.Models.Contracts.Table>(request.Params.ToString());
                TableViewModel newTableViewModel         = new TableViewModel(newTable);
                //this.Tables.Add(newTableViewModel);

                break;

            case "GetTables":     //Give me your tables

                using (BitPoker.Repository.ITableRepository tableRepo = new BitPoker.Repository.LiteDB.TableRepository("data.db"))
                {
                    IEnumerable <BitPoker.Models.Contracts.Table> tables = tableRepo.All();

                    //now send
                    IResponse response = new RPCResponse()
                    {
                        Id     = request.Id,
                        Result = tables
                    };

                    this.SentRequests.Add(request);
                    Backend.SendResponse(response);

                    break;
                }

            case "GetTablesResponse":     //Add resultant tables
                GetTablesResponse tableResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <GetTablesResponse>(request.Params.ToString());

                foreach (BitPoker.Models.Contracts.Table table in tableResponse.Tables)
                {
                    //TableViewModel tableViewModel = new TableViewModel(table);
                    this.Tables.Add(table);
                }

                break;

            case "ActionMessage":
                ActionMessage actionMessage = Newtonsoft.Json.JsonConvert.DeserializeObject <ActionMessage>(request.Params.ToString());

                //actionMessage.HandId;

                break;
            }
        }
Beispiel #9
0
 void Start()
 {
     INSTANCE = this;
 }
Beispiel #10
0
 // Only called by Unity on server
 public void uLink_OnPlayerDisconnected(uLink.NetworkPlayer player)
 {
     uLink.Network.RemoveRPCs(player);
     uLink.Network.DestroyPlayerObjects(player);
     NetworkPlayers.Remove(player);
 }
Beispiel #11
0
 // Update is called once per frame
 void Update()
 {
     syncToHost["input"] = NetworkPlayers.GetInput();
 }