Example #1
0
    public void OnMatchJoined(JoinMatchResponse matchJoin)
    {
        if (matchJoin.success)
        {
            Debug.Log("Join match succeeded");
            if (_lobby.matchCreated)
            {
                Debug.LogWarning("Match already set up, aborting...");
                return;
            }

            MatchInfo matchInfo = new MatchInfo(matchJoin);
            Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));
            _client = new NetworkClient();
            _client.RegisterHandler(MsgType.Connect, OnConnected);
            _client.RegisterHandler(MsgType.Disconnect, OnDisconnect);
            _client.RegisterHandler(MsgType.Error, OnError);
            _client.RegisterHandler(MsgType.AddPlayer, AddPlayerMessage);
            //_client.RegisterHandler(MsgType.Owner, OwnerMes);
            _client.RegisterHandler(100, MesFromServer);

            NetworkManager.singleton.StartClient(matchInfo);
            //_client.Connect(matchInfo);
        }
        else
        {
            Debug.LogError("Join match failed.");

        }
    }
Example #2
0
 //automatically called when starting a client
 public override void OnStartClient(NetworkClient mClient)
 {
     Debug.Log ("onstartclient called");
     base.OnStartClient(mClient);
     mClient.RegisterHandler((short)MyMessages.MyMessageTypes.CHAT_MESSAGE, OnClientChatMessage);
     mClient.RegisterHandler((short)MyMessages.MyMessageTypes.USER_INFO, OnClientUserInfo);
 }
Example #3
0
 // Create a client and connect to the server port
 public void SetupClient()
 {
     myClient = new NetworkClient();
     myClient.RegisterHandler(MsgType.Connect, OnConnected);
     myClient.RegisterHandler(MyMsgType.Info, OnInfo);
     myClient.Connect("10.250.235.162", 3000);
 }
        public static void OnStartClient(NetworkClient client)
        {
            client.RegisterHandler(VoiceChatMsgType.Packet, OnClientPacketReceived);
            client.RegisterHandler(VoiceChatMsgType.SpawnProxy, OnProxySpawned);

            var prefab = Resources.Load<GameObject>(ProxyPrefabPath);
            ClientScene.RegisterPrefab(prefab);
        }
    void setupLocalClient()
    {
        //registerPrefabs ();
        //Spawn ();

        myClient = ClientScene.ConnectLocalServer();
        myClient.RegisterHandler(MsgType.Connect, OnConnectedLocalPlayer);
        myClient.RegisterHandler (MsgType.Error, OnErrorLocalPlayer);
    }
    void setupClient()
    {
        //registerPrefabs ();
        //Spawn ();

        myClient = new NetworkClient();
        myClient.RegisterHandler(MsgType.Connect, OnConnectedRemotePlayer);
        myClient.RegisterHandler (MsgType.Error, OnErrorRemotePlayer);
        myClient.Connect(gameIP, gamePort);
    }
Example #7
0
        public static void RegisterClientPacketHandlers(NetworkClient client)
        {
            client.RegisterHandler((short)PacketType.SetPlayerID, PHSetPlayerID);
            client.RegisterHandler((short)PacketType.SendMapInfo, PHReceiveMap);
            client.RegisterHandler((short)PacketType.PlayerNotReady, PHPlayerNotReady);
            client.RegisterHandler((short)PacketType.BroadcastPlayerName, PHBroadcastPlayerName);
            client.RegisterHandler((short)PacketType.BroadcastPlayerTeam, PHBroadcastPlayerTeam);
            client.RegisterHandler((short)PacketType.PlayerPrepared, PHPlayerPrepared);

            Debug.Log("Client Packet Handlers registered");
        }
	public void Init(NetworkClient client)
	{
		myClient = client;
		NetworkServer.RegisterHandler(clientMsgType, OnServerReadyToBeginMessage);
		NetworkServer.RegisterHandler(serverMsgType, OnServerReadyToBeginMessage);
		
		if (myClient != null) {
			myClient.RegisterHandler (serverMsgType, OnServerReadyToBeginMessage);
			myClient.RegisterHandler (clientMsgType, OnServerReadyToBeginMessage);
		}
	}
 public void SetupLocalClient()
 {
     myClient = ClientScene.ConnectLocalServer ();
     myClient.RegisterHandler (MsgType.Connect, OnConnectedLocalClient);
     /*ClientScene.Ready(myClient.connection);*/
     ClientScene.AddPlayer (myClient.connection, 0);
 }
Example #10
0
	public void joinGame()
	{
		// Check if there is a room

		// Has the game Started?

		// If no, send the player to the Waiting For Players page

		// If yes, give error message.
		Debug.Log (string.Format ("join button clicked"));
		client = new NetworkClient();
		client.Connect ("192.168.1.103", 4444);
		client.RegisterHandler(MsgType.Connect, OnConnected);
		client.RegisterHandler(MsgType.Error, OnError);
		client.RegisterHandler (Message.GET_HAS_ROOM, OnGetRoom);
	}
Example #11
0
 public void SetupClient()
 {
     myClient = new NetworkClient();
     myClient.RegisterHandler(MsgType.Connect, OnConnected);
     myClient.Connect("192.16.7.21", 8888);
     isAtStartup = false;
 }
        public static void OnManagerStartClient(NetworkClient client, GameObject customPrefab = null)
        {
            client.RegisterHandler(VoiceChatMsgType.Packet, OnClientPacketReceived);
            client.RegisterHandler(VoiceChatMsgType.SpawnProxy, OnProxySpawned);

            if (customPrefab == null)
            {
                proxyPrefab = Resources.Load<GameObject>(ProxyPrefabPath);
            }
            else
            {
                proxyPrefab = customPrefab;
            }

            ClientScene.RegisterPrefab(proxyPrefab);
        }
 public void connect(string server, NetworkMessageDelegate onConnect)
 {
     client = new NetworkClient ();
     if(onConnect != null)
         client.RegisterHandler (MsgType.Connect, onConnect);
     client.Connect (server, PORT);
 }
Example #14
0
	//private SyncListString chatHistory = new SyncListString();

	public override void OnStartClient(NetworkClient mClient)
	{
		//chatHistory.Callback = OnStringChanged;
        base.OnStartClient(mClient);

        mClient.RegisterHandler((short)MyMessages.MyMessageTypes.CHAT_MESSAGE, OnClientChatMessage);
		//isAClient = true;
	}
Example #15
0
    public static void JoinP2PServer(string gn)
    {
        gameName = gn;

        myClient = instance.StartClient();
        myClient.RegisterHandler(MyMsgType.UpdateSeed, OnSeedReceived);

        MasterServer.RequestHostList(gameID);
    }
Example #16
0
 void Awake()
 {
     myClient = new NetworkClient ();
     ConnectionConfig config = new ConnectionConfig ();
     config.AddChannel (QosType.ReliableFragmented);
     myClient.Configure (config, 1);
     myClient.Connect (IP, 7777);
     myClient.RegisterHandler (MyMsgType.Info, OnInfoMessage);
 }
        // Create a client and connect to the server port
        public void SetupClient()
        {
            ClientScene.RegisterPrefab(Prefab);

            client = new NetworkClient();

            client.RegisterHandler(MsgType.Connect, OnConnected);
            client.Connect("127.0.0.1", 4444);
        }
Example #18
0
 void Start()
 {
     NetworkManager netManager = GameObject.FindObjectOfType<NetworkManager>();
     client = netManager.client;
     if (client.isConnected)
         client.RegisterHandler(CHAT_MSG, ClientReceiveChatMessage);
     if (isServer)
         NetworkServer.RegisterHandler(CHAT_MSG, ServerReceiveChatMessage);
 }
Example #19
0
		// CONSTRUCTOR
		public Client(NetworkingInfo netinfo)
		{
			networkingInfo = netinfo;
			if(networkingInfo.port == -1) networkingInfo.port = NetworkingInfo.defaultPort;
			if(networkingInfo.address == "") networkingInfo.address = NetworkingInfo.defaultAddress;
			// TODO: Add some kind of DNS pre check for IP?

			connectedPlayers = new List<Player>();

			config = new ConnectionConfig();
			Channels.priority = config.AddChannel(QosType.AllCostDelivery);
			Channels.reliable = config.AddChannel(QosType.ReliableSequenced);
			Channels.unreliable = config.AddChannel(QosType.UnreliableSequenced);
			Channels.fragmented = config.AddChannel(QosType.ReliableFragmented);
			Channels.update = config.AddChannel(QosType.StateUpdate);
			hostconfig = new HostTopology(config, maxConcurrentConnectedUsers);

			if(networkingInfo.isServer)
			{
				myClient = ClientScene.ConnectLocalServer();
				myClient.Configure(hostconfig);

				myClient.RegisterHandler(MsgType.Connect, OnConnected);
				myClient.RegisterHandler(MsgType.Disconnect, ConnectionFailed);
				registerAllCallbacks(myClient, cbClientHandler);
			}
			else
			{
				myClient = new NetworkClient();
				myClient.Configure(hostconfig);

				myClient.RegisterHandler(MsgType.Connect, OnConnected);
				myClient.RegisterHandler(MsgType.Error, ConnectionError);
				myClient.RegisterHandler(MsgType.Disconnect, ConnectionFailed);
				registerAllCallbacks(myClient, cbClientHandler);

				common.printConsole (tag, "Setup complete", true);

				myClient.Connect(networkingInfo.address, networkingInfo.port);
				common.printConsole (tag, "Connecting to " + networkingInfo.address + ":" + networkingInfo.port, true);
			}
		}
	public void Initialize (NetworkClient network_client, string playFabId)
	{
		_network = network_client;
		PlayFabId = playFabId;
		//Register for Messages
		_network.RegisterHandler(ChatServerMessageTypes.ChannelMessage, OnChannelMessage);
		_network.RegisterHandler(ChatServerMessageTypes.JoinChannelResponse, OnJoinChannelResponse);
		_network.RegisterHandler(ChatServerMessageTypes.CreateChannelResponse, OnCreateChannelResponse);

		Debug.Log ("send create channel");
		_network.Send(ChatServerMessageTypes.CreateChannel, new CreateChannelMessage()
			{
				ChannelId = "General",
				MemberId = PlayFabId,
				MemberName = PlayerUsername,
				IsInviteOnly = false
			});

		chat_diplay_name_text.text = PlayerUsername;
	}
    // Create a client and connect to the server port
    public void SetupClient()
    {
        Debug.Log ("SetupClient.");
        foreach (GameObject prefab in prefabs) {
            if (prefab != null)
                ClientScene.RegisterPrefab (prefab);
        }

        myClient = new NetworkClient ();

        myClient.RegisterHandler (MsgType.Connect, OnConnected);
        myClient.Connect (base.networkAddress, base.networkPort);
    }
    void Start()
    {
        //on client, this isn't required but is nice for testing.
        Application.runInBackground = true;

        var globals = FindObjectOfType<GlobalAssets>();

        _networkStateEntityProtoType = globals.NetworkEntityStatePrototype.GetComponent<NetworkIdentity>();

        ClientScene.RegisterSpawnHandler(_networkStateEntityProtoType.assetId, OnSpawnEntity, OnDespawnEntity);

        _client = new NetworkClient();
        _client.Connect("localhost", 7777);
        _client.RegisterHandler(MsgType.Connect, OnClientConnected);

    }
Example #23
0
 public void OnMatchJoined(JoinMatchResponse matchJoin)
 {
     if (matchJoin.success)
     {
         Debug.Log("Join match succeeded");
         if (matchCreated)
         {
             Debug.LogWarning("Match already set up, aborting...");
             return;
         }
         Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));
         NetworkClient myClient = new NetworkClient();
         myClient.RegisterHandler(MsgType.Connect, OnConnected);
         myClient.Connect(new MatchInfo(matchJoin));
     }
     else
     {
         Debug.LogError("Join match failed");
     }
 }
Example #24
0
    void Start()
    {
        manager = GetComponent<NetworkManager>();
        manager.StartMatchMaker();
        matcher = manager.matchMaker;

        matcher.ListMatches(0, ListSize, "", (matches) => {
            if (matches.success) {
                if (matches.matches.Count > 0 && !OnlyHost) {
                    matcher.JoinMatch(matches.matches[0].networkId, "", (join) => {
                        if (join.success) {
                            Utility.SetAccessTokenForNetwork(join.networkId, new NetworkAccessToken(join.accessTokenString));
                            NetworkClient client = new NetworkClient();
                            client.RegisterHandler(MsgType.Connect, (connected) => {
                                Debug.Log("Connected");
                            });
                            client.Connect(new MatchInfo(join));
                            manager.StartClient();
                        } else {
                            Debug.LogError("Could not join match");
                        }
                    });
                } else {
                    matcher.CreateMatch(URandom.value.ToString(), PlayerCountPerRoom, Advertise, "", (created) => {
                        if (created.success) {
                            Debug.Log("Create match succeeded");
                            Utility.SetAccessTokenForNetwork(created.networkId, new NetworkAccessToken(created.accessTokenString));
                            NetworkServer.Listen(new MatchInfo(created), 9000);
                            manager.StartHost();
                            isHost = true;
                        } else {
                            Debug.LogError("Could not create match");
                        }
                    });
                }
            } else {
                Debug.LogError("Could not recieve list of matchces");
            }
        });
    }
 public void connectToLocal(NetworkMessageDelegate onConnect)
 {
     client = ClientScene.ConnectLocalServer ();
     client.RegisterHandler (MsgType.Connect, onConnect);
 }
Example #26
0
        void Start()
        {
            NetworkManager netManager = FindObjectOfType<NetworkManager>();

            if (netManager == null) return;

            Debug.Log("found netManager");

            client = netManager.client;
            if (client.isConnected)
                client.RegisterHandler(CHAT_MSG, ClientReceiveChatMessage);
            if (isServer)
                NetworkServer.RegisterHandler(CHAT_MSG, ServerReceiveChatMessage);
        }
        public override void OnStartClient(NetworkClient client)
        {
            if (this.lobbySlots.Length == 0)
            this.lobbySlots = new NetworkLobbyPlayer[this.maxPlayers];

              if ((UnityEngine.Object) this.m_LobbyPlayerPrefab == (UnityEngine.Object) null || (UnityEngine.Object) this.m_LobbyPlayerPrefab.gameObject == (UnityEngine.Object) null)
              {
            if (LogFilter.logError)
              Debug.LogError((object) "NetworkLobbyManager no LobbyPlayer prefab is registered. Please add a LobbyPlayer prefab.");
              }
              else
            ClientScene.RegisterPrefab(this.m_LobbyPlayerPrefab.gameObject);

              if ((UnityEngine.Object) this.m_GamePlayerPrefab == (UnityEngine.Object) null)
              {
            if (LogFilter.logError)
              Debug.LogError((object) "NetworkLobbyManager no GamePlayer prefab is registered. Please add a GamePlayer prefab.");
              }
              else
            ClientScene.RegisterPrefab(this.m_GamePlayerPrefab);

              client.RegisterHandler((short) 43, new NetworkMessageDelegate(this.OnClientReadyToBegin));
              client.RegisterHandler((short) 45, new NetworkMessageDelegate(this.OnClientAddPlayerFailedMessage));
              this.OnLobbyStartClient(client);
        }
Example #28
0
 public void SetupLocalClient()
 {
     myClient = ClientScene.ConnectLocalServer();
     myClient.RegisterHandler(MsgType.Connect, OnConnected);
     isAtStartup = false;
 }
 internal void RegisterClientMessages(NetworkClient client)
 {
   client.RegisterHandler((short) 32, new NetworkMessageDelegate(this.OnClientConnectInternal));
   client.RegisterHandler((short) 33, new NetworkMessageDelegate(this.OnClientDisconnectInternal));
   client.RegisterHandler((short) 36, new NetworkMessageDelegate(this.OnClientNotReadyMessageInternal));
   client.RegisterHandler((short) 34, new NetworkMessageDelegate(this.OnClientErrorInternal));
   client.RegisterHandler((short) 39, new NetworkMessageDelegate(this.OnClientSceneInternal));
   if ((UnityEngine.Object) this.m_PlayerPrefab != (UnityEngine.Object) null)
     ClientScene.RegisterPrefab(this.m_PlayerPrefab);
   using (List<GameObject>.Enumerator enumerator = this.m_SpawnPrefabs.GetEnumerator())
   {
     while (enumerator.MoveNext())
     {
       GameObject current = enumerator.Current;
       if ((UnityEngine.Object) current != (UnityEngine.Object) null)
         ClientScene.RegisterPrefab(current);
     }
   }
 }
        // This provided NetManager accounts for a client, server, or host. Register handlers for a client here using the NetworkClient field
        internal void RegisterClientMessages(NetworkClient client)
        {
            client.RegisterHandler((short) 32, new NetworkMessageDelegate(this.OnClientConnectInternal));
              client.RegisterHandler((short) 33, new NetworkMessageDelegate(this.OnClientDisconnectInternal));
              client.RegisterHandler((short) 36, new NetworkMessageDelegate(this.OnClientNotReadyMessageInternal));
              client.RegisterHandler((short) 34, new NetworkMessageDelegate(this.OnClientErrorInternal));
              client.RegisterHandler((short) 39, new NetworkMessageDelegate(this.OnClientSceneInternal));

              // handle the registering of the clients prefab also so it doesnt need to be done manually from separate client code
              if ((UnityEngine.Object) this.m_PlayerPrefab != (UnityEngine.Object) null)
            ClientScene.RegisterPrefab(this.m_PlayerPrefab);

              // Also register any prefabs added in the inspector so they are included in the game for the client, no manual client code also needed
              using (List<GameObject>.Enumerator enumerator = this.m_SpawnPrefabs.GetEnumerator())
              {
            while (enumerator.MoveNext())
            {
              GameObject current = enumerator.Current;
              if ((UnityEngine.Object) current != (UnityEngine.Object) null)
            ClientScene.RegisterPrefab(current);
            }
              }
        }