public override BaseMessage GetInnerMessage()
        {
            switch (Type)
            {
                case TCTypes.Info:
                    {
                        ServerInfoMessage msg = new ServerInfoMessage();
                        msg.UTFDeSerialize(this.Message);
                        return msg;
                    }
                case TCTypes.AbonentCommand:
                    {
                        AbonentsCommandMessage msg = new AbonentsCommandMessage();
                        msg.UTFDeSerialize(this.Message);
                        return msg;
                    }
                case TCTypes.Confirm:
                    {
                        ServerConfirmMessage msg = new ServerConfirmMessage();
                        msg.UTFDeSerialize(this.Message);
                        return msg;
                    }
                case TCTypes.PlayerCommand:
                    {
                        PlayerCommandMessage msg = new PlayerCommandMessage();
                        msg.UTFDeSerialize(this.Message);
                        return msg;
                    }

            }
            return null;
        }
 public TimedConfirmMessage(ServerConfirmMessage message)
 {
     this.msg = message;
     time = DateTime.Now;
 }
示例#3
0
        protected override void AfterRecieveCommand(AbonentsCommandMessage acMsg, Abonent ab)
        {
            switch (acMsg.Type)
            {
                case AbonentsCommandType.ExitRoom:
                    {
                        bool done = false;

                        RemoveAbonent(ab);
                            Program.Lobby.AddAbonent(ab);
                            if (ab.Gamer.Id == this.Owner.Id)
                            {
                                AfterRemoveOwner();
                            }
                            done = true;
                        if (acMsg.GetInnerMessage().NeedConfirm)
                        {
                            ServerConfirmMessage confirm = new ServerConfirmMessage() { Accept = done, RefMsgId = acMsg.MsgId };
                            var smsg = confirm.GetTC();
                            ab.SendMessage(smsg);
                        }
                        SendRoomStatusMessage();
                        Program.Lobby.SendRoomStatusMessage();
                        break;
                    }
                case AbonentsCommandType.Exit:
                    {
                        this.RemoveAbonent(ab);
                        ab.Gamer.Name = "Guest" + ab.Gamer.Id;
                        ab.Gamer.UserId = 0;
                        ab.Status = AbonentStatusEnum.Disconnected;
                        if (ab.Gamer.Id == this.Owner.Id)
                        {
                            AfterRemoveOwner();
                        }
                        SendRoomStatusMessage();
                        break;
                    }
                case AbonentsCommandType.StartRoom:
                    {
                        bool done = false;
                        if (acMsg.GetInnerMessage().NeedConfirm)
                        {
                            MultiPlayerGame game = new MultiPlayerGame(this.AbnsToList(),);
                            game.Start(AfterGameEnd);
                            ServerConfirmMessage confirm = new ServerConfirmMessage() { Accept = done, RefMsgId = acMsg.MsgId };
                            var smsg = confirm.GetTC();
                            ab.SendMessage(smsg);
                        }
                        break;
                    }
                case AbonentsCommandType.KickUser:
                    {
                        bool done = false;
                        KickUserMessage kickmsg = (KickUserMessage)acMsg.GetInnerMessage();
                        Abonent kickedab = this.AbnsToList().FirstOrDefault(a => a.Gamer.Id==kickmsg.UserId);
                        if (kickedab!=null)
                        {
                            this.RemoveAbonent(kickedab);
                                Program.Lobby.AddAbonent(kickedab);
                                done = true;
                        }
                        if (acMsg.GetInnerMessage().NeedConfirm)
                        {
                            ServerConfirmMessage confirm = new ServerConfirmMessage() { Accept = done, RefMsgId = acMsg.MsgId };
                            var smsg = confirm.GetTC();
                            ab.SendMessage(smsg);
                        }
                        SendRoomStatusMessage();
                        Program.Lobby.SendRoomStatusMessage();
                        break;
                    }

            }
        }
示例#4
0
        protected override void AfterRecieveCommand(AbonentsCommandMessage acMsg, Abonent ab)
        {
            switch (acMsg.Type)
            {
                case AbonentsCommandType.Authorization:
                    {
                        bool done = false;
                        AuthorizationMessage amsg = (AuthorizationMessage)acMsg.GetInnerMessage();
                        //реализация логики авторизации пока пусть будет типа авторизован
                        ab.Status = AbonentStatusEnum.Authorized;
                        ab.Gamer.Id = usrid;
                        ab.Gamer.UserId = usrid;
                        usrid++;
                        ab.Gamer.Name = amsg.Login;
                        done = true;
                        if (amsg.NeedConfirm)
                        {
                            ServerConfirmMessage confirm = new ServerConfirmMessage() { Accept = done, RefMsgId = acMsg.MsgId };
                            var smsg = confirm.GetTC();
                            ab.SendMessage(smsg);
                        }
                        SendRoomStatusMessage();

                        break;
                    }
                case AbonentsCommandType.UnAuthorization:
                    {
                        bool done = false; ;

                        ab.Gamer.Name = "Guest" + ab.Gamer.Id;
                        ab.Gamer.UserId = 0;
                        ab.Status = AbonentStatusEnum.Guest;
                        done = true;
                        if (acMsg.GetInnerMessage().NeedConfirm)
                        {
                            ServerConfirmMessage confirm = new ServerConfirmMessage() { Accept = done, RefMsgId = acMsg.MsgId };
                            var smsg = confirm.GetTC();
                            ab.SendMessage(smsg);
                        }
                        SendRoomStatusMessage();
                        break;
                    }
                case AbonentsCommandType.Exit:
                    {
                        RemoveAbonent(ab);
                        ab.Gamer.Name = "Guest" + ab.Gamer.Id;
                        ab.Gamer.UserId = 0;
                        ab.Status = AbonentStatusEnum.Disconnected;
                        SendRoomStatusMessage();
                        break;
                    }
                case AbonentsCommandType.CreateRoom:
                    {
                        bool done = false;
                        CreateRoomMessage crmsg = (CreateRoomMessage)acMsg.GetInnerMessage();
                        GameRoom room = new GameRoom(roomnumber, crmsg.Name, crmsg.Password, ab.Gamer, crmsg.Capability);
                        Program.Rooms.Add(room);
                        RemoveAbonent(ab);
                        room.AddAbonent(ab);
                            done = true;
                        if (acMsg.GetInnerMessage().NeedConfirm)
                        {
                            ServerConfirmMessage confirm = new ServerConfirmMessage() { Accept = done, RefMsgId = acMsg.MsgId };
                            var smsg = confirm.GetTC();
                            ab.SendMessage(smsg);
                        }
                        ab.CurrentRoom.SendRoomStatusMessage();
                        SendRoomStatusMessage();
                        var roomsmsg = new ServerInfoRoomsMessage() { Rooms = Program.GetRoomsInfo() };
                        Program.Lobby.SendMessage(roomsmsg.GetTC());
                        break;
                    }
                case AbonentsCommandType.JoinRoom:
                    {
                        bool done = false;
                        JoinRoomMessage jrmsg = (JoinRoomMessage)acMsg.GetInnerMessage();
                        if (jrmsg.RoomId > 0)
                        {
                            GameRoom room = (GameRoom)Program.Rooms.FirstOrDefault(r => r.Id == jrmsg.RoomId);
                            if (room != null)
                            {
                                this.RemoveAbonent(ab);
                                    room.AddAbonent(ab, jrmsg.Password);
                                    done = true;
                            }
                        }
                        if (acMsg.GetInnerMessage().NeedConfirm)
                        {
                            ServerConfirmMessage confirm = new ServerConfirmMessage() { Accept = done, RefMsgId = acMsg.MsgId };
                            var smsg = confirm.GetTC();
                            ab.SendMessage(smsg);
                        }
                        SendRoomStatusMessage();
                        break;
                    }
                case AbonentsCommandType.RequestRoomInfo:
                    {
                        ServerInfoRoomsMessage riMessage = new ServerInfoRoomsMessage() { Rooms = Program.GetRoomsInfo() };
                        var smsg = riMessage.GetTC();
                        ab.SendMessage(smsg);
                        break;
                    }

            }
        }