コード例 #1
0
        async Task ExecuteLoadItemsCommand()
        {
            IsBusy = true;

            try
            {
                await Task.Delay(TimeSpan.FromSeconds(2));

                VoteOptions.Add(new VoteOption
                {
                    VoteId = Item.Id
                });
                BindingContext = this;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #2
0
        public static byte[] BuildVoteMessage(int proposal_id, VoteOptions option, Wallet wallet)
        {
            string hrpFrom;

            byte[] addrDec;
            Bech32.Bech32Engine.Decode(wallet.Address, out hrpFrom, out addrDec);

            Vote vt = new Vote
            {
                Voter      = ByteString.CopyFrom(addrDec),
                Option     = (long)option,
                ProposalId = proposal_id
            };
            var aminoMessage = AminoBuilder.buildAminoMessage(vt.ToByteArray(), AminoBuilder.AminoType.Vote);
            StdSignBytesConverter signatureBytesConverter = new StdSignBytesConverter(vt, wallet);

            byte[] messageBytesForSign   = signatureBytesConverter.GetCanonicalBytesForSignature();
            var    signatureBytes        = wallet.Sign(messageBytesForSign);
            var    signatureBytesMessage = AminoBuilder.buildAminoSignature(signatureBytes, wallet);
            var    stdMsg = AminoBuilder.buildStandardTransaction(aminoMessage, signatureBytesMessage, "");

            return(stdMsg);
        }
コード例 #3
0
        public override void SendVotes(BasePlayer player)
        {
            const int VotesPerMsg = 20;

            KeyValuePair <string, VoteOption>[] options;
            var skip = 0;

            do
            {
                options = VoteOptions.Skip(skip).Take(VotesPerMsg).ToArray();
                skip   += options.Length;

                var msg = new MsgPacker((int)GameMessage.ServerVoteOptionListAdd, false);
                msg.AddInt(options.Length);

                for (var i = 0; i < options.Length; i++)
                {
                    msg.AddString(options[i].Value.Description);
                }

                Server.SendMsg(msg, MsgFlags.Vital, player.ClientId);
            } while (options.Length >= VotesPerMsg);
        }
コード例 #4
0
        public override bool AddVote(string description, string command)
        {
            if (string.IsNullOrEmpty(description) || description.Length > VoteOption.MaxDescription)
            {
                Console.Print(OutputLevel.Standard, "votes", $"skipped invalid option '{description}'");
                return(false);
            }

            if (string.IsNullOrEmpty(command) || command.Length > VoteOption.MaxCommand || !Console.IsLineValid(command))
            {
                Console.Print(OutputLevel.Standard, "votes", $"skipped invalid command '{command}'");
                return(false);
            }

            if (ContainsVote(description))
            {
                Console.Print(OutputLevel.Standard, "votes", $"option '{description}' already exists");
                return(false);
            }

            var voteOption = new VoteOption()
            {
                Description = description,
                Command     = command
            };

            VoteOptions.Add(voteOption.Description, voteOption);
            Console.Print(OutputLevel.Standard, "votes", $"added option '{voteOption.Description}' '{voteOption.Command}'");

            Server.SendPackMsg(new GameMsg_SvVoteOptionAdd
            {
                Description = description
            }, MsgFlags.Vital, -1);

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Votes with the specified value.
        /// </summary>
        /// <param name="value">The value to vote with.</param>
        /// <param name="callback">The callback delegate to invoke on the server response.</param>
        public void Vote(VoteOptions value, Action<JObject> callback)
        {
            Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "TurntableBot Public Vote. Thread ID: {0}. Value: {1}.", Thread.CurrentThread.ManagedThreadId, value.ToString()));

            Random random = new Random();

            string vh = SHA1Hex(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", this.RoomId, value.ToString().ToLower(), this.CurrentSongId));
            string th = SHA1Hex(random.NextDouble().ToString());
            string ph = SHA1Hex(random.NextDouble().ToString());

            JObject json = new JObject(
                new JProperty("api", "room.vote"),
                new JProperty("roomid", this.RoomId),
                new JProperty("val", value.ToString().ToLower()),
                new JProperty("vh", vh),
                new JProperty("th", th),
                new JProperty("ph", ph));

            this.Send(json, callback);
        }
コード例 #6
0
 /// <summary>
 /// Votes with the specified value.
 /// </summary>
 /// <param name="value">The value to vote with.</param>
 public void Vote(VoteOptions value)
 {
     this.Vote(value, null);
 }
コード例 #7
0
ファイル: Character.cs プロジェクト: justin-ou/Stay-Alive
	public void Init(int index, Transform parent, VoteOptions selfVoteOption){
		_characterIndex = index;
		_parentTransform = parent;
		_selfVoteOption = selfVoteOption;
	}
コード例 #8
0
        public override void CallVote(GameMsg_ClCallVote message, BasePlayer player)
        {
            if (message.Force && !Server.IsAuthed(player.ClientId))
            {
                return;
            }

            if (Config["SvSpamprotection"] && PlayersVoteInfo[player.ClientId].LastVoteTry + Server.TickSpeed * 3 > Server.Tick)
            {
                return;
            }

            PlayersVoteInfo[player.ClientId].LastVoteTry = Server.Tick;

            if (ActiveVote != null)
            {
                GameContext.SendChat(-1, ChatMode.All, player.ClientId, "Wait for the current vote to end");
                return;
            }

            if (player.Team == Team.Spectators)
            {
                GameContext.SendChat(-1, ChatMode.All, player.ClientId, "Wait for the current vote to end");
                return;
            }

            // TODO
            //var timeRemaning = 60 - (Server.Tick - PlayerLastVoteCall[player.ClientId]) / Server.TickSpeed;
            //if (Config["SvSpamprotection"] && timeRemaning > 0)
            //{
            //    GameContext.SendChat(-1, ChatMode.All, player.ClientId,
            //        $"Wait '{timeRemaning}' seconds for start new vote");
            //    return;
            //}

            PlayersVoteInfo[player.ClientId].LastVoteCall = Server.Tick;
            var    reason = string.IsNullOrEmpty(message.Reason) ? "No reason given" : message.Reason;
            string description;
            string command;
            Vote   voteType;

            if (message.VoteType == "option")
            {
                if (!VoteOptions.TryGetValue(message.Value, out var voteOption))
                {
                    return;
                }

                voteType    = Vote.StartOption;
                description = voteOption.Description;
                command     = voteOption.Command;
            }
            else if (message.VoteType == "kick")
            {
                voteType    = Vote.StartKick;
                description = string.Empty;
                command     = string.Empty;
            }
            else if (message.VoteType == "spectate")
            {
                voteType    = Vote.StartSpectator;
                description = string.Empty;
                command     = string.Empty;
            }
            else
            {
                return; // unknown type
            }

            if (message.Force)
            {
            }
            else
            {
                PlayersVoteInfo[player.ClientId].Vote         = 1;
                PlayersVoteInfo[player.ClientId].LastVoteCall = Server.Tick;

                StartVote(new ActiveVote
                {
                    CallerId    = player.ClientId,
                    Description = description,
                    Type        = voteType,
                    Reason      = reason,
                    CloseTick   = Server.Tick + Server.TickSpeed * 25,
                    Command     = command
                });
            }
        }
コード例 #9
0
 public override bool ContainsVote(string description)
 {
     return(VoteOptions.ContainsKey(description));
 }