Exemple #1
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;
    }
Exemple #2
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;
    }
Exemple #3
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);
    }
Exemple #4
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;
            }
        }