Esempio n. 1
0
    public void CreateRoom()
    {
        createButton.interactable = false;
        MessageInstanceCreate message = new MessageInstanceCreate();

        message.name       = roomName.text;
        message.maxClients = (uint)System.Int32.Parse(maxCount.text);
        GalaxyApi.send.SendMessageToServer((byte)CommandType.roomCreate, message, GalaxyCoreCommon.GalaxyDeliveryType.reliable);
    }
        /// <summary>
        /// Создать новую комнату
        /// </summary>
        /// <param name="data">данные от пользователя</param>
        /// <param name="clientConnection">Подключение пользователя</param>
        internal void CreateRoom(byte[] data, ClientConnection clientConnection)
        {
            MessageInstanceCreate message = MessageInstanceCreate.Deserialize <MessageInstanceCreate>(data);
            Room room = new Room();         // создаем новый экземпляр комнаты

            room.name       = message.name; // задаем имя комнаты
            room.id         = GetNewID();   // задаем уникальный id комнаты, это id серверный, для сохранения в базу следует создать отдельную переменную
            room.maxClients = (int)message.maxClients;
            instances.TryAdd(room, null);   // Добавляем инстанс в список
            if (Server.debugLog)
            {
                Console.WriteLine("Клиент ID:" + Server.clientManager.GetClientByConnection(clientConnection).id + " Создал комнату ID:" + room.id);
            }
            room.AddClient(clientConnection); // добавляем клиента в созданный инстанс,
        }