Esempio n. 1
0
 public int GetConnectionId()
 {
     /*if(!Networking.isServer)
      * {
      *
      * }*/
     return(LobbyConnector.ConvertPlayerToConnection(this));
 }
Esempio n. 2
0
    public void OpenNewLobby()
    {
        // Setup the networker
        LobbyInfo thisLobby = new LobbyInfo();

        thisLobby.connectedClients = 1;
        thisLobby.maxClients       = 1000;
        thisLobby.port             = 8081;
        thisLobby.name             = "MMO Duel Simulation";

        LobbyConnector.HostLobby(thisLobby);
    }
Esempio n. 3
0
    private void OnGUI()
    {
        if (isConnecting)
        {
            if (GUILayout.Button("Cancel Connection"))
            {
                this.isConnected  = false;
                this.isConnecting = false;

                LobbyConnector.CancelConnection();
            }
        }
        else if (isConnected)
        {
            if (GUILayout.Button("Disconnect"))
            {
                LobbyConnector.Disconnect();
            }
        }
        else
        {
            if (GUILayout.Button("Start Host"))
            {
                this.isConnecting = true;

                LobbyInfo thisLobby = new LobbyInfo();
                thisLobby.ip       = "localhost";
                thisLobby.port     = 8080;
                thisLobby.isServer = false;
                LobbyConnector.HostLobby(thisLobby);
            }

            if (GUILayout.Button("Start Dedicated Server"))
            {
                this.isConnecting = true;

                LobbyInfo thisLobby = new LobbyInfo();
                thisLobby.ip       = "localhost";
                thisLobby.port     = 8080;
                thisLobby.isServer = true;
                LobbyConnector.HostLobby(thisLobby);
            }

            if (GUILayout.Button("Connect To Host"))
            {
                this.isConnecting = true;

                LobbyConnector.ConnectToLobby(textFieldString);
            }
            textFieldString = GUI.TextField(new Rect(0, 100, 100, 20), textFieldString);
        }
    }
Esempio n. 4
0
    // Use this for initialization
    void Start()
    {
        print("Setting ttrget fps");
        if (UnityEngine.SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Null)
        {
            QualitySettings.vSyncCount  = 0;
            Application.targetFrameRate = 30;
        }
        NetworkingConfig cfg = new NetworkingConfig();

        cfg.isServer         = false;
        cfg.isMatchmaker     = false;
        cfg.simulatedLatency = 100;

        LobbyConnector.Init(cfg);

        NetworkEvents.onLobbyJoined     += OnLobbyJoined;
        NetworkEvents.onDisconnect      += OnLobbyDisconnected;
        NetworkEvents.onPlayerConnected += OnPlayerConnected;
    }
Esempio n. 5
0
 public void ConnectToHost()
 {
     LobbyConnector.ConnectToLobby("localhost:8081");
 }
Esempio n. 6
0
    public static void ProcessRecieve()
    {
        while (true)
        {
            int              recHostId;
            int              connectionId;
            int              channelId;
            byte[]           recBuffer  = new byte[1024];
            int              bufferSize = 1024;
            int              dataSize;
            byte             error;
            NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
            //if (recData != NetworkEventType.Nothing) Debug.Log("Recieve : " + recData);
            switch (recData)
            {
            case NetworkEventType.Nothing: return;

            case NetworkEventType.ConnectEvent:
            {
                if (LobbyConnector.connectionId == connectionId)
                {
                    //my connect request was approved
                    Debug.Log("On connect socces!!!");
                    LobbyConnector.OnConnectSuccess();
                }
                else
                {
                    // another user connected
                    Debug.Log("On Player Joined");
                    LobbyConnector.OnPlayerJoined(connectionId);
                }
                break;
            };

            case NetworkEventType.DataEvent:
            {
                //DispersePacket(new MemoryStream(recBuffer));3
                if (LobbyConnector.isServer)
                {
                    foreach (int connection in LobbyConnector.connectedClients)
                    {
                        if (connection != connectionId)
                        {
                            SocketSender.SendPacket(new System.IO.MemoryStream(recBuffer, 0, recBuffer.Length, false, true), connection);
                        }
                    }
                    LitePacket.executingClient   = LobbyConnector.connectionToPlayer[connectionId];
                    Networking.localPacketPlayer = Networking.GetPlayer(LitePacket.executingClient);
                }
                LiteNetworkingGenerated.PacketReader.ReadPacket(new System.IO.MemoryStream(recBuffer, 0, recBuffer.Length, false, true));
                break;
            };

            case NetworkEventType.DisconnectEvent:
            {
                if (LobbyConnector.connectionId == connectionId)
                {
                    // cant connect to server
                }
                else
                {
                    // someone disconnected
                    LobbyConnector.OnPlayerDisconnect(connectionId);
                }
                break;
            }

            case NetworkEventType.BroadcastEvent:

                break;
            }
        }
    }