public void Initialize(string id) { LNSClientParameters clientParameters = new LNSClientParameters(id, System.Environment.UserName); LNSConnectSettings settings = new LNSConnectSettings(); settings.gameKey = "com.hybriona.multiplayertest"; settings.gameVersion = Application.version; if (connectToLocalServer) { settings.serverIp = "127.0.0.1"; } else { settings.serverIp = "45.55.33.88"; } settings.serverPort = 10002; settings.serverSecurityKey = serverKey; //settings.serverIp = "192.168.0.100"; connector = new LNSConnector(clientParameters, settings, this); if (writer == null) { writer = new LNSWriter(); } writer.Reset(); connector.onPlayerConnected = OnPlayerConnected; connector.onPlayerDisconnected = OnPlayerDisconnected; connector.onMasterClientUpdated += (LNSClient client) => { Debug.Log("Masterclient changed to " + client.id); }; }
public LNSConnector(LNSClientParameters clientParameters, LNSConnectSettings settings, ILNSDataReceiver dataReceiver) { this.clientParameters = clientParameters; this.settings = settings; this.dataReceiver = dataReceiver; this.threadDispatcher = LNSMainThreadDispatcher.GetInstance(); localClient = new LNSClient(); clientDataWriter = new NetDataWriter(); writer = new NetDataWriter(); this.settings.Validate(); EventBasedNetListener listener = new EventBasedNetListener(); client = new NetManager(listener); SetClientId(this.clientParameters.id); //Write Client Data clientDataWriter.Put(this.settings.serverSecurityKey); clientDataWriter.Put(this.clientParameters.id); clientDataWriter.Put(this.clientParameters.displayName); clientDataWriter.Put(this.settings.gameKey); clientDataWriter.Put(this.settings.gameVersion); clientDataWriter.Put(this.settings.platform); //List to receiveEvent listener.PeerConnectedEvent += Listener_PeerConnectedEvent; listener.PeerDisconnectedEvent += Listener_PeerDisconnectedEvent; listener.NetworkReceiveEvent += Listener_NetworkReceiveEvent; listener.NetworkErrorEvent += Listener_NetworkErrorEvent; listener.NetworkReceiveUnconnectedEvent += Listener_NetworkReceiveUnconnectedEvent; }
public FakeClient(string ip, int port, string id) { LNSClientParameters clientParameters = new LNSClientParameters(id, null); LNSConnectSettings connectSettings = new LNSConnectSettings(); connectSettings.serverIp = ip; connectSettings.serverPort = port; connectSettings.serverSecurityKey = "iamatestserver"; connectSettings.gameKey = "hybriona.ccutest"; writer = new LNSWriter(); connector = new LNSConnector(clientParameters, connectSettings, this); connector.onConnected += () => { connector.JoinRoomOrCreateIfNotExist("test", 10000); }; connector.Connect(); }
public void StartProcess(string id) { clonePrefab.SetActive(false); writer = new LNSWriter(); player.GetComponent <SphereGizmos>().radius = searchExtends; if (name == "Client") { id = "Client"; player.localPosition = Vector3.zero; } StartCoroutine(RandomMovement()); player.localPosition = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)) * mapSize * .5f; LNSClientParameters clientParameters = new LNSClientParameters(id, gameObject.name); LNSConnectSettings connectSettings = new LNSConnectSettings(); if (useLive) { connectSettings.serverIp = liveip; } else { connectSettings.serverIp = ip; } connectSettings.serverPort = port; connectSettings.serverSecurityKey = "demokey"; connectSettings.gameKey = "hybriona.quadtreetest"; if (!useLive) { connectSettings.serverSecurityKey = "demokey"; } connector = new LNSConnector(clientParameters, connectSettings, this); connector.onConnected = () => { LNSCreateRoomParameters roomParameters = new LNSCreateRoomParameters(); roomParameters.maxPlayers = 100; roomParameters.isQuadTreeAllowed = true; //roomParameters.idleLife = 60 * 24; roomParameters.EnableQuadTreeCellOptimization(Vector2.zero, new Vector2(2000, 2000)); connector.CreateRoom("default", roomParameters); }; connector.onFailedToConnect = (CONNECTION_FAILURE_CODE code) => { Debug.LogError(name + " - " + code); }; connector.onDisconnectedFromRoom = () => { Debug.LogError(name + " - onDisconnectedFromRoom"); }; connector.onDisconnected = () => { Debug.LogError(name + " - onDisconnectedFromServer"); }; connector.onRoomCreateFailed = (ROOM_FAILURE_CODE code) => { Debug.LogError(name + " - " + code); if (code == ROOM_FAILURE_CODE.ROOM_ALREADY_EXIST) { connector.JoinRoom("default"); } }; connector.onRoomJoined = () => { Debug.Log(name + " on room joined"); }; connector.onRoomJoinFailed = (ROOM_FAILURE_CODE code) => { Debug.LogError(name + " - " + code); }; connector.Connect(); }