/// <summary> /// Create a room with the given roomId. /// </summary> /// <param name="roomId">The ID for the room.</param> public async Task CreateSpecificRoom(ColyseusClient client, string roomName, string roomId) { LSLog.LogImportant($"Creating Room {roomId}"); try { //Populate an options dictionary with custom options provided elsewhere as well as the critical option we need here, roomId Dictionary <string, object> options = new Dictionary <string, object> { ["roomId"] = roomId }; foreach (KeyValuePair <string, object> option in roomOptionsDictionary) { options.Add(option.Key, option.Value); } _room = await client.Create <ExampleRoomState>(roomName, options); } catch (Exception ex) { LSLog.LogError($"Failed to create room {roomId} : {ex.Message}"); return; } LSLog.LogImportant($"Created Room: {_room.Id}"); _lastRoomId = roomId; RegisterRoomHandlers(); }
public async void Start() { _colyseusClient = new ColyseusClient("localhost", "8080"); await _colyseusClient.ConnectToServer(); var room = _colyseusClient.JoinRoom("match"); room.Listen("players/:id", new ListenerPlayers(_players).OnChange); }
void Awake() { if (_instance != null && _instance != this) { Destroy(transform.root.gameObject); return; } _instance = this; DontDestroyOnLoad(transform.root.gameObject); }
public void Initialize() { if (onlineMode) { client = GetComponent <ColyseusClient>(); // Initialize takes a callback, which here is an anonymous delegate StartCoroutine(client.Initialize((msg) => { #if debug_server Debug.Log(msg); #endif })); } }
/// <summary> /// Set the client of the <see cref="ColyseusRoomManager" />. /// </summary> /// <param name="client"></param> public void SetClient(ColyseusClient client) { _client = client; }
// Start is called before the first frame update void Start() { colyseusClient = GetComponent <ColyseusClient>(); }
void Start() { client = ColyseusClient.instance; GetServerList(); client.AddListener(MsgId.Commond, OnCommandResp); client.AddListener(MsgId.Connect, OnConnectResp); client.AddListener(MsgId.DisConnect, OnDisConnectResp); client.AddListener(MsgId.CreateANetObject, OnCreateANetObjectResp); //client.AddListener(MsgId.CreateARoom, OnCreateARoomResp); client.AddListener(MsgId.DestroyANetObject, OnDestroyANetObjectResp); //client.AddListener(MsgId.GetRoomList, OnGetRoomListResp); //client.AddListener(MsgId.JoinARoom, OnJoinARoomResp); //client.AddListener(MsgId.LeaveARoom, OnLeaveARoomResp); client.AddListener(MsgId.StartGame, OnStartGameResp); client.AddListener(MsgId.UpdateRoomInfo, OnUpdateRoomInfo); #region btn event ConnectBtn.onClick.AddListener(() => { //test :192.168.71.140 client.ConnectToServer(ServerList[(int)serverType], "2567", (result, obj) => { if (result == ColyseusClient.ColyseusClientResult.Success) { Debug.Log("Connect server success!!!"); } else { Debug.Log("Connect server failed!!!"); } }); }); GetRoomBtn.onClick.AddListener(() => { client.GetAvailableRooms((result, obj) => { if (result == ColyseusClient.ColyseusClientResult.Success) { Debug.Log("Get rooms success!!!"); OnGetRoomListResp(obj); } else { Debug.Log("Get rooms failed!!!"); } }); //client.SendMsg(MsgId.GetRoomList, Target.Owner, null); }); CreateRoomBtn.onClick.AddListener(() => { client.CreateRoom("testRoom", "123456", (result, obj) => { if (result == ColyseusClient.ColyseusClientResult.Success) { Debug.Log("Create Room success!!!"); OnCreateARoomResp(obj); } else { Debug.Log("Create Room failed :" + obj); } }); }); JoinRoomBtn.onClick.AddListener(() => { client.JoinOrCreateRoom("123456", (result, obj) => { if (result == ColyseusClient.ColyseusClientResult.Success) { Debug.Log("Join a room success!!!"); } else { Debug.Log("Join a room failed! error code is :" + obj); } }); }); LeaveRoomBtn.onClick.AddListener(() => { client.LeaveRoom((result, obj) => { if (result == ColyseusClient.ColyseusClientResult.Success) { Debug.Log("Leave Room success!!!"); OnLeaveARoomResp(obj); } else { Debug.Log("Leave Room failed!!!"); } }); }); SendMsgBtn.onClick.AddListener(() => { SendCommond(); }); CreateBossBtn.onClick.AddListener(() => { CreateAEnemy(); }); ShootBossBtn.onClick.AddListener(() => { CommondInfo commond = new CommondInfo() { func = "damage", param = string.Format("{0},{1}", boss.enemyInfo.id, 0.1f) }; client.SendMsg(MsgId.Commond, Target.All, commond); }); StartGameBtn.onClick.AddListener(() => { client.SendMsg(MsgId.StartGame, Target.All, null); }); EndGameBtn.onClick.AddListener(() => { client.SendMsg(MsgId.EndGame, Target.Server, null); }); UploadScoresBtn.onClick.AddListener(() => { var ScoreInfo = new ScoreInfo(); ScoreInfo.scores = new ScoreItem[4]; ScoreInfo.scores[0] = new ScoreItem() { clientID = "11111", score = 12 }; ScoreInfo.scores[1] = new ScoreItem() { clientID = "22222", score = 12 }; ScoreInfo.scores[2] = new ScoreItem() { clientID = "33333", score = 12 }; ScoreInfo.scores[3] = new ScoreItem() { clientID = "44444", score = 12 }; client.SendMsg(MsgId.UploadScores, Target.Server, ScoreInfo); }); UploadDeviceinfoBtn.onClick.AddListener(() => { client.SendMsg(MsgId.UploadDeviceInfo, Target.Server, new AppInfo() { snCode = "0000-1111", macAddress = Utils.GetMacAddress(), startUpTimeStamp = 112312123 });; }); #endregion }
public void SetClient(ColyseusClient client) { _client = client; ColyseusRoom.Instance.OnOpenHandler(); }