Example #1
0
        public void IsValidShouldChangeTheAnnounceToNoneIfThereIsAnnounceAndValidCards()
        {
            validator.IsValid(action, context, playerCards);
            Announce announceResult = action.Announce;

            Assert.AreEqual(Announce.None, announceResult);
        }
        public JsonResult Save(string headLine, string content)
        {
            if (string.IsNullOrEmpty(headLine) || string.IsNullOrEmpty(content))
            {
                SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Save, MessageException.Null("The headLine or content is emptry."));
                return(Json(new { Success = false, Message = MessageException.PleaseFillOut }, JsonRequestBehavior.AllowGet));
            }

            using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
            {
                try
                {
                    Announce announce = new Announce {
                        HeadLine = headLine, Content = content
                    };
                    announce.CreateAction    = new iSabaya.UserAction(SessionContext.User);
                    announce.EffectivePeriod = iSabaya.TimeInterval.EffectiveNow;
                    SessionContext.Persist(announce);

                    tx.Commit();

                    SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Save, MessageException.Success());
                }
                catch (Exception ex)
                {
                    tx.Rollback();

                    SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Save, MessageException.Fail(ex.Message));
                    return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(new { Success = true, Message = "เพิ่มประกาศ เรียบร้อย" }, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        public async Task <IActionResult> Edit(Announce user)
        {
            db.Announces.Update(user);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public void CreateFacultative(string name)
        {
            Facultative newFac = new Facultative(name, this);

            facultatives.Add(newFac);
            Announce?.Invoke(newFac);
        }
Example #5
0
        public static void Send(Client client, int stat, uint value, bool announce)
        {
            PacketWriter writer = new PacketWriter();

            writer.PushBytes(new byte[] { 0xDF, 0xDF, });
            writer.PushShort(10);
            writer.PushShort(1);
            writer.PushShort(0);
            writer.PushInt(3086);
            writer.PushInt(client.Character.Id);
            writer.PushInt(0x2B333D6E);
            writer.PushIdentity(50000, client.Character.Id);
            writer.PushByte(1);
            writer.PushInt(1);
            writer.PushInt(stat);
            writer.PushUInt(value);

            byte[] packet = writer.Finish();
            client.SendCompressed(packet);

            /* announce to playfield? */
            if (announce)
            {
                Announce.PlayfieldOthers(client, packet);
            }
        }
Example #6
0
        /// <summary>
        /// Set own stat (no announce)
        /// </summary>
        /// <param name="client">Affected client</param>
        /// <param name="stat">Stat</param>
        /// <param name="value">Value</param>
        /// <param name="announce">Let others on same playfield know?</param>
        public static uint Set(Client client, int stat, uint value, bool announce)
        {
            PacketWriter packetWriter = new PacketWriter();

            uint oldValue = (uint)client.Character.Stats.StatValueByName(stat);

            client.Character.Stats.SetStatValueByName(stat, value);

            packetWriter.PushBytes(new byte[] { 0xDF, 0xDF, });
            packetWriter.PushShort(10);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(client.Character.Id);
            packetWriter.PushInt(0x2B333D6E);
            packetWriter.PushIdentity(50000, client.Character.Id);
            packetWriter.PushByte(1);
            packetWriter.PushInt(1);
            packetWriter.PushInt(stat);
            packetWriter.PushUInt(value);

            byte[] packet = packetWriter.Finish();
            client.SendCompressed(packet);

            /* announce to playfield? */
            if (announce)
            {
                Announce.Playfield(client.Character.PlayField, packet);
            }

            return(oldValue);
        }
Example #7
0
 private void LogAnnounce(Announce announce)
 {
     this.LogDevice(announce.Parameters.Device);
     this.LogIpAddresses(announce.Parameters.NetSettings.Interface);
     this.LogServices(announce.Parameters.Services);
     Console.Out.WriteLine();
 }
Example #8
0
    public async Task ShouldBroadcastMessageToGroup(
        [Frozen] Mock <IConnectedClientStore> connectedClients,
        ConnectedClient sender,
        Announce announce,
        CancellationToken ct,
        AnnounceHandler sut)
    {
        var connections = Fixture.CreateMany <IConnection>().ToList();
        var clients     = connections
                          .Select(connection => CreateSingleGroupClient(connection))
                          .ToList();

        connectedClients
        .Setup(x => x.FindInGroups(It.Is <IEnumerable <string> >(
                                       groups => groups.Count() == 1 &&
                                       groups.Contains(sender.Group))))
        .Returns(clients);

        await sut.HandleAsync(sender, announce, ct);

        foreach (var connection in connections)
        {
            Mock.Get(connection).Verify(x => x.SendAsync(
                                            It.Is <Announce>(m => m.Message.Contains(announce.Message)),
                                            ct));
        }
    }
Example #9
0
        /* Called from CharacterAction class in case of 'stand' (0x57)
         * Sends Stand packet back to client
         * In case of logout CancelLogOut (above) stops it.
         */

        public void StandCancelLogout()
        {
            PacketWriter standUp = new PacketWriter();

            // start packet header
            standUp.PushByte(0xDF);
            standUp.PushByte(0xDF);
            standUp.PushShort(10);
            standUp.PushShort(1);
            standUp.PushShort(0);
            standUp.PushInt(3086);                          // Sender (server ID)
            standUp.PushInt(this.Character.Id);             // Receiver
            standUp.PushInt(0x5E477770);                    // CharacterAction packet ID
            standUp.PushIdentity(50000, this.Character.Id); // affected identity
            standUp.PushByte(0);
            // end packet header

            standUp.PushByte(0);
            standUp.PushShort(0);
            standUp.PushByte(0x57); // stand packet flag
            standUp.PushInt(0);
            standUp.PushInt(0);
            standUp.PushInt(0);
            standUp.PushInt(0);
            standUp.PushInt(0);
            standUp.PushShort(0);
            byte[] standUpPacket = standUp.Finish();
            Announce.Playfield(this.Character.PlayField, standUpPacket);
            //            SendCompressed(standUpPacket);

            if (LogoutTimer.Enabled)
            {
                this.CancelLogOut();
            } // If logout timer is running, CancelLogOut method stops it.
        }
Example #10
0
        public static void SendStat(Client client, int statnum, int value, Boolean announce)
        {
            PacketWriter packetWriter = new PacketWriter();

            packetWriter.PushBytes(new byte[] { 0xDF, 0xDF, });
            packetWriter.PushShort(10);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(client.Character.Id);
            packetWriter.PushInt(0x2B333D6E);
            packetWriter.PushIdentity(50000, client.Character.Id);
            packetWriter.PushByte(1);
            packetWriter.PushInt(1);
            packetWriter.PushInt(statnum);
            packetWriter.PushInt(value);

            byte[] reply = packetWriter.Finish();
            client.SendCompressed(reply);

            /* announce to playfield? */
            if (announce)
            {
                Announce.Playfield(client.Character.PlayField, reply);
            }
        }
Example #11
0
        public static void DespawnPacket(int targetId)
        {
            PacketWriter packetWriter = new PacketWriter();

            packetWriter.PushByte(0xDF);
            packetWriter.PushByte(0xDF);
            packetWriter.PushShort(10);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0x1d);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(0);
            packetWriter.PushInt(0x36510078);
            packetWriter.PushIdentity(50000, targetId);
            packetWriter.PushByte(1);
            byte[] packet = packetWriter.Finish();

            Dynel dyn = FindDynel.FindDynelById(50000, targetId);

            if (dyn != null)
            {
                NonPlayerCharacterClass npc = dyn as NonPlayerCharacterClass;
                if (npc != null)
                {
                    npc.RemoveFromCache();
                }
                Announce.PlayfieldOthers(dyn.PlayField, packet);
            }
        }
Example #12
0
        public void SyncNextAnnouncement_WithSyncingAndEmptyAnnoucements_EndsSync()
        {
            Mock <IMessageReader> reader         = new Mock <IMessageReader>();
            Mock <IMessageWriter> messageWritter = new Mock <IMessageWriter>();

            ECKeyPair kp = new KeyPairGenerator().Generate();
            Peer      p  = new Peer(new TcpClient(), reader.Object, messageWritter.Object, 1234, kp, 0);

            var(_, handshake) = NetworkTestHelpers.CreateKeyPairAndHandshake(1235);
            p.AuthentifyWith(handshake); // set "other peer as authentified"

            var annoucement = new Announce {
                Height = 10, Id = ByteString.CopyFromUtf8("FakeHash")
            };

            p.StashAnnouncement(annoucement);

            // trigger sync
            p.SyncNextAnnouncement();

            // end sync
            var movedToNext = p.SyncNextAnnouncement();

            // Check that sync ended
            Assert.False(movedToNext);

            Assert.Null(p.SyncedAnnouncement);
            Assert.False(p.AnyStashed);
        }
Example #13
0
        /// <summary>
        /// This method is used to update the height of the current peer.
        /// </summary>
        /// <param name="a"></param>
        public void OnAnnouncementMessage(Announce a)
        {
            if (a?.Id == null)
            {
                _logger?.Error($"[{this}] announcement or its id is null.");
                return;
            }

            try
            {
                if (a.Height <= KnownHeight)
                {
                    // todo just log for now, but this is probably a protocol error.
                    _logger?.Warn($"[{this}] current know heigth: {KnownHeight} announcement height {a.Height}.");
                }

                KnownHeight = a.Height;

                _logger?.Trace($"[{this}] received announcement, height increased: {KnownHeight}.");
            }
            catch (Exception e)
            {
                _logger?.Error(e, $"[{this}] error processing announcement.");
            }
        }
Example #14
0
        public async Task <IActionResult> Edit(int id, [Bind("AnnounceId,Title,Description,AddingDate,ExpiringDate,CategoryId,UserId")] Announce announce)
        {
            if (id != announce.AnnounceId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(announce);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AnnounceExists(announce.AnnounceId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryName", announce.CategoryId);
            ViewData["UserId"]     = new SelectList(_context.User, "UserId", "Email", announce.UserId);
            return(View(announce));
        }
        public JsonResult Update(long id, string headLine, string content)
        {
            Announce announce = Announce.Get(SessionContext, id);

            if (announce == null)
            {
                SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Update, MessageException.Null("The static method Get return null, ID : " + id));
                return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
            }

            using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
            {
                try
                {
                    announce.HeadLine        = headLine;
                    announce.Content         = content;
                    announce.UpdateAction    = new iSabaya.UserAction(SessionContext.User);
                    announce.EffectivePeriod = iSabaya.TimeInterval.EffectiveNow;
                    announce.Persist(SessionContext);
                    tx.Commit();

                    SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Update, MessageException.Success(id.ToString()));
                }
                catch (Exception ex)
                {
                    tx.Rollback();

                    SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Update, MessageException.Fail(ex.Message));
                    return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(new { Success = true, Message = "แก้ไขประกาศ เรียบร้อย" }, JsonRequestBehavior.AllowGet));
        }
        public MyResult <object> AddAnnounce(AnnounceDto model)
        {
            MyResult result = new MyResult();

            if (string.IsNullOrEmpty(model.Title))
            {
                return(result.SetStatus(ErrorCode.InvalidData, "公告标题不能为空"));
            }
            if (string.IsNullOrEmpty(model.Content))
            {
                return(result.SetStatus(ErrorCode.InvalidData, "公告内容不能为空"));
            }
            if (string.IsNullOrEmpty(model.Type.ToString()) || model.Type < 0)
            {
                return(result.SetStatus(ErrorCode.InvalidData, "公告类型非法"));
            }
            Announce announce = new Announce
            {
                Title   = model.Title,
                Content = model.Content,
                Types   = model.Type
            };

            base.Add(announce, true);
            result.Data = true;
            return(result);
        }
        public JsonResult Delete(long id)
        {
            Announce announce = Announce.Get(SessionContext, id);

            if (announce == null)
            {
                SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Delete, MessageException.Null("The static method Get return null, ID : " + id));
                return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
            }

            using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction())
            {
                try
                {
                    announce.Delete(SessionContext);

                    tx.Commit();

                    SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Delete, MessageException.Success(id.ToString()));
                }
                catch (Exception ex)
                {
                    tx.Rollback();

                    SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Delete, MessageException.Fail(ex.Message));
                    return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new { Success = true, Message = "ลบประกาศ เรียบร้อย" }, JsonRequestBehavior.AllowGet));
        }
Example #18
0
        private void AnnounceBlock(IBlock block)
        {
            if (block?.Header == null)
            {
                _logger?.Error("Block or block header is null.");
                return;
            }

            if (_peers == null || !_peers.Any())
            {
                return;
            }

            try
            {
                Announce anc = new Announce
                {
                    Height = (int)block.Header.Index,
                    Id     = ByteString.CopyFrom(block.GetHashBytes())
                };

                BroadcastMessage(AElfProtocolMsgType.Announcement, anc.ToByteArray());
            }
            catch (Exception e)
            {
                _logger?.Error(e, "Error while announcing block.");
            }
        }
Example #19
0
        // GET: Login
        public ActionResult Index()
        {
            Tab = TabIndex;
            ViewBag.LoginActionName = FullUrl("Login/Authentication");
            ViewBag.StatusLogin     =
                @"<option value='ระบุสถานะผู้ใช้'>ระบุสถานะผู้ใช้</option>
                            <option value='1'>ส่วนราชการ</option>
                            <option value='1'>รัฐวิสาหกิจ</option>
                            <option value='1'>หน่วยงานอื่นของรัฐ</option>
                            <option value='1'>จังหวัด</option>
                            <option value='1'>กลุ่มจังหวัด</option>";
            //<option value='2'>เจ้าหน้าที่จัดทำงบประมาณ</option>
            //<option value='3'>เจ้าหน้าที่ประเมินผล</option>
            //<option value='4'>เจ้าหน้าที่ดูแลระบบ</option>";

            ViewBag.StatusLoginTxt =
                new List <string>()
            {
                "ส่วนราชการ",
                "รัฐวิสาหกิจ",
                "หน่วยงานอื่นของรัฐ",
                "จังหวัด",
                "กลุ่มจังหวัด",
                "เจ้าหน้าที่จัดทำงบประมาณ",
                "เจ้าหน้าที่ประเมินผล",
                "เจ้าหน้าที่ดูแลระบบ"
            };

            ViewBag.Notices = Announce.GetAll(SessionContext);

            return(View());
        }
Example #20
0
        public async Task <Announce> InsertAnnounceAsync(Announce entity)
        {
            var result = await Context.Set <Announce>().AddAsync(entity);

            await Context.SaveChangesAsync();

            return(result.Entity);
        }
Example #21
0
        public ActionResult Index()
        {
            Tab = "0";
            ViewBag.LoginActionName = FullUrl("Login/Authentication");
            ViewBag.Notices         = Announce.GetAll(SessionContext);

            return(View());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Announce announce = db.Announces.Find(id);

            db.Announces.Remove(announce);
            db.SaveChanges();
            return(RedirectToAction("Announcements"));
        }
Example #23
0
        public void AnnounceMessage(string message)
        {
            AssertSerializable <Announce>();

            var sut = new Announce(message);

            Assert.Equal(message, sut.Message);
        }
Example #24
0
 public void PlayAnnounce(Announce annnouce, byte variant, params string[] var)
 {
     if ((type & GameMgrType.SERVER) == 0)
     {
         return;
     }
     Announcer.Instance.PlayAnnounce(annnouce, variant, var);
     s.SendPacketBroadCast(PacketBuilder.BuildPlayAnnouncePacket(annnouce, variant, var));
 }
Example #25
0
    public void PlayAnnounce(Announce a, int variant, params string[] values)
    {
        Format announce = m_announce[a];

        m_text.text  = FormatAnnounce(announce.text[variant], values);
        m_text.color = announce.color;
        m_anim.Rewind();
        m_anim.Play();
    }
Example #26
0
        public void Get_Test()
        {
            //Arrange
            //Act
            var announce = Announce.Get(context, 1L);

            //Assert
            Assert.IsNotNull(announce);
        }
Example #27
0
        public void StashAnnouncement(Announce announce)
        {
            if (announce?.Id == null)
            {
                throw new ArgumentNullException($"{nameof(announce)} or its ID is null.");
            }

            _announcements.Add(announce);
        }
Example #28
0
 public PlayerAction(
     PlayerActionType type,
     Card card,
     Announce announce)
 {
     this.Type = type;
     this.Card = card;
     this.Announce = announce;
 }
Example #29
0
 public PlayerAction(
     PlayerActionType type,
     Card card,
     Announce announce)
 {
     this.Type     = type;
     this.Card     = card;
     this.Announce = announce;
 }
Example #30
0
        public void GetAll_Test()
        {
            // Arrange

            // Act
            var announces = Announce.GetAll(context);

            // Assert
            Assert.IsNotNull(announces);
        }
 public ActionResult Edit([Bind(Include = "AnnouncementID,Announcement,Date_Time")] Announce announce)
 {
     if (ModelState.IsValid)
     {
         db.Entry(announce).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Announcements"));
     }
     return(View(announce));
 }
        private Card GetAnnounce(PlayerTurnContext context, Announce announce, ICollection<Card> cards)
        {
            foreach (var card in possibleCardsToPlay)
            {
                if (this.cardValidator.IsCardInAnnounce(context, card, cards, announce))
                {
                    return card;
                }
            }

            return null;
        }
        public void Start()
        {
            IPlayer firstToPlay;
            IPlayer secondToPlay;
            IList<Card> firstToPlayCards;
            IList<Card> secondToPlayCards;
            if (this.whoWillPlayFirst == PlayerPosition.FirstPlayer)
            {
                firstToPlay = this.firstPlayer;
                firstToPlayCards = this.firstPlayerCards;
                secondToPlay = this.secondPlayer;
                secondToPlayCards = this.secondPlayerCards;
            }
            else
            {
                firstToPlay = this.secondPlayer;
                firstToPlayCards = this.secondPlayerCards;
                secondToPlay = this.firstPlayer;
                secondToPlayCards = this.firstPlayerCards;
            }

            var context = new PlayerTurnContext(this.deck.GetTrumpCard, this.state, deck.CardsLeft);

            PlayerAction firstPlayerAction = null;
            do
            {
                firstPlayerAction = this.FirstPlayerTurn(firstToPlay, context);

                if (!this.actionValidater.isValid(firstPlayerAction, context, firstToPlayCards))
                {
                    //TODO: something more graceful?
                    throw new InternalGameExceptions("Invalid turn");
                }

            } while (firstPlayerAction.Type == PlayerActionType.PlayCard);

            context.FirstPlayedCard = firstPlayerAction.Card;

            PlayerAction secondPlayerAction = secondToPlay.GetTurn(
                context,
                this.actionValidater);
            if (!this.actionValidater.isValid(secondPlayerAction, context, secondToPlayCards))
            {
                //TODO: something more graceful?
                throw new InternalGameExceptions("Invalid turn");
            }

            context.SecondPlayedCard = secondPlayerAction.Card;

            if (firstToPlay == this.firstPlayer)
            {
                this.firstPlayerCard = secondPlayerAction.Card;
                this.firstPlayerAnnounce = secondPlayerAction.Announce;
                this.secondPlayerCard = firstPlayerAction.Card;
                this.secondPlayerAnnounce = firstPlayerAction.Announce;
            }
            else
            {

            }

            firstToPlay.EndTurn(context);
            secondToPlay.EndTurn(context);

            ICardWinner cardWinner = new CardWinner();
            if (firstToPlay == this.firstPlayer)
            {
                this.winner = cardWinner.Winner(firstPlayerAction.Card, secondPlayerAction.Card, this.deck.GetTrumpCard.Suit);
            }
            else
            {
                this.winner = cardWinner.Winner(secondPlayerAction.Card, firstPlayerAction.Card, this.deck.GetTrumpCard.Suit);
            }
        }