Exemplo n.º 1
0
 public override BaseMessage GetInnerMessage()
 {
     switch (Type)
     {
         case SIMessageType.Abonents:
             {
                 ServerInfoAbonentsMessage msg = new ServerInfoAbonentsMessage();
                 msg.UTFDeSerialize(this.Message);
                 return msg;
             }
         case SIMessageType.Rooms:
             {
                 ServerInfoRoomsMessage msg = new ServerInfoRoomsMessage();
                 msg.UTFDeSerialize(this.Message);
                 return msg;
             }
         case SIMessageType.Error:
             {
                 ServerInfoErrorMessage msg = new ServerInfoErrorMessage();
                 msg.UTFDeSerialize(this.Message);
                 return msg;
             }
     }
     return null;
 }
Exemplo n.º 2
0
        protected override void AfterRemoveOwner()
        {
            foreach (var remab in AbnsToList())
            {
                this.RemoveAbonent(remab);
                Program.Lobby.AddAbonent(remab);
            }
            Program.Rooms.Remove(this);
            Program.Lobby.SendRoomStatusMessage();

            var roomsmsg = new ServerInfoRoomsMessage() { Rooms = Program.GetRoomsInfo() };
            Program.Lobby.SendMessage(roomsmsg.GetTC());
        }
Exemplo n.º 3
0
 private void AfterRoomsInfoRecived(ServerInfoRoomsMessage rmsmsg)
 {
     var oldRooms = Rooms.ToList();
     var newRooms = new List<GameRoomInfo>();
     foreach (var rm in rmsmsg.Rooms)
         if (oldRooms.Contains(rm))
             oldRooms.Remove(rm);
         else
             newRooms.Add(rm);
     foreach (var rm in oldRooms)
         Rooms.Remove(rm);
     foreach (var rm in newRooms)
         Rooms.Add(rm);
 }
Exemplo n.º 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;
                    }

            }
        }
Exemplo n.º 5
0
        public bool AddAbonent(Abonent ab)
        {
            try
            {
                if (ab.Status != AbonentStatusEnum.Authorized && Id != 0)
                    return false;
                if (CanAddAbonent)
                {
                    AddToAbList(ab);
                    ab.CurrentRoom = this;
                    capacity++;
                    if (this.Id==0)
                    {
                        var roomsmsg = new ServerInfoRoomsMessage() { Rooms = Program.GetRoomsInfo() };
                        ab.SendMessage(roomsmsg.GetTC());
                    }
                    ab.Sender.BeginReceive(new AsyncCallback(AfterRecieve), ab);
                    return true;
                }
                else
                    return false;
            }
            catch (Exception ex)
            {

                return false;
            }
        }