Exemplo n.º 1
0
    public CreateRoomAck CreateRoom(CreateRoom msg)
    {
        CreateRoomAck rsp = new CreateRoomAck();

        if (client == null)
        {
            Logger.Warn("Not connected to matchvs server");
            rsp.Status = 400;
            return(rsp);
        }
        msg.SvcName = svcName;
        msg.PodName = podName;

        var reply = SendMsg(ByteUtils.ObjectToByteString(msg), (UInt32)GSDirectoryCmdID.GscreateRoomCmd);

        if (reply == null)
        {
            rsp.Status = 500;
        }
        else
        {
            rsp = new CreateRoomAck();
            ByteUtils.ByteStringToObject(rsp, reply.Message);
        }
        return(rsp);
    }
Exemplo n.º 2
0
        public static void HandleCreateRoom(Packet packet)
        {
            CmdCreateRoom cmd = new CmdCreateRoom(packet);

            if (packet.Sender.Character?.Token != cmd.Token)
            {
                packet.SendBackError(12);
                return;
            }

            Character character = packet.Sender.Character;

            // User can only create room in lobby
            if (character?.Status?.GetState() != typeof(Lobby))
            {
                packet.SendBackError(11);
                return;
            }

            Lobby userLobby = character.Status.GetObject <Lobby>();

            Room createdRoom;

            userLobby.RoomManager.Create(
                packet.Sender,
                cmd.RoomName, 4, cmd.NumTurns, cmd.IsLocked, cmd.Password, out createdRoom);

            if (createdRoom == null)
            {
                packet.SendBackError(14);
                return;
            }

            createdRoom.Join(packet.Sender);

            // Send acks
            var ack1 = new CreateRoomAck()
            {
                Room = createdRoom
            };
            var ack2 = new RoomCreatedAck()
            {
                Room = createdRoom
            };

            // Broadcast to everyone in lobby that room has been created
            createdRoom.Parent.Broadcast(ack2.CreatePacket());

            // Give client room details
            packet.SendBack(ack1.CreatePacket());
        }