예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            switch (PubFunction.curParameter.istry)
            {
            case 0:
                this.spFoot.Style.Add("display", "");
                break;

            case 1:
                this.spFoot.Style.Add("display", "none");
                break;

            case 2:
                this.spFoot.Style.Add("display", "none");
                break;
            }
            OnlineMessage bllProposal = new OnlineMessage();
            int           count       = bllProposal.GetRecordCount("IsReply=0 and MessageType=0");

            this.spMessageCount.InnerHtml = count.ToString();
            if (count == 0)
            {
                this.divMessage.Visible = false;
            }
        }
예제 #2
0
    public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data)
    {
        ConsoleScreen.Log("OnRealTimeMessageReceived");
        OnlineMessage message = deserializeMessage(data);

        if (!playerOneDecided)
        {
            ConsoleScreen.Log("OnRealTimeMessageReceived - decide p1");
            GlobalGameManager.amIPlayerOne = PlayGamesPlatform.Instance.RealTime.GetSelf().ParticipantId.Equals(message.participantIdPlayerOne);
            CurrentState = GlobalGameManager.amIPlayerOne ? State.MY_TURN : State.WAIT;
        }
        else
        {
            ReceiveShoot(message.unitIndex, message.force);
        }
        //switch (CurrentState)
        //{
        //    case State.WAIT:

        //        break;
        //    case State.MY_TURN:
        //        Debug.Log("OnRealTimeMessageReceived - mensaje en mi turno? WTF!!");
        //        break;
        //    default:
        //        Debug.Log("OnRealTimeMessageReceived - WTF!!");
        //        break;
        //}
    }
예제 #3
0
        protected override async Task BroadCastAction(CancellationToken token)
        {
            try
            {
                foreach (var interval in _intervals)
                {
                    await Task.Delay(TimeSpan.FromSeconds(interval), token);

                    var message = new OnlineMessage(SuperDriveCore.LocalDevice);
                    var bytes   = message.ToPacket().ToBytes();
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }
                    Env.Logger.Log("+++Broadcast out" + message, nameof(LanDiscoverer));
                    SendUdp(bytes, _broadcastEndpoint);
                }
            }
            catch (Exception e)
            {
                Env.Logger.Log("Broadcast exception", stackTrace: e.StackTrace);
            }
            //直接运行可能死锁。
#pragma warning disable 4014
            // ReSharper disable once MethodSupportsCancellation
            Task.Run(() => StopBroadcasting());
#pragma warning restore 4014
        }
예제 #4
0
    internal void SendShoot(int unitIndex, Vector3 outPower)
    {
        OnlineMessage message = new OnlineMessage();

        message.unitIndex = unitIndex;
        message.force     = outPower;
        PlayGamesPlatform.Instance.RealTime.SendMessageToAll(true, serializeMessage(message));
        CurrentState = State.WAIT;
    }
예제 #5
0
 private byte[] serializeMessage(OnlineMessage message)
 {
     byte[] bytes;
     using (MemoryStream stream = new MemoryStream())
     {
         formatter.Serialize(stream, message);
         bytes = stream.ToArray();
     }
     return(bytes);
 }
        private void BroadcastTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var idx = broadCastCount >= intervals.Length ? intervals.Length - 1 : broadCastCount;

            if (broadCastCount++ > MAX_BROADCAST_TIME) //有限次数广播。如果是无限次数的,当broadcastCount>设定值,idx = intervals.Length-1
            {
                broadcastTimer.Stop();
            }
            else
            {
                var message = new OnlineMessage(localInfo);
                var bytes   = message.ToPacket().ToBytes();
                udp.Send(null, bytes, udp.broadcastEndpoint);


                var interval = intervals[idx];
                broadcastTimer.Interval = interval;
                broadcastTimer.Start();
            }
        }
예제 #7
0
    /**
     * Realiza lógica de decidir quién es el jugador 1.
     */
    private void DecideWhoIsPlayerOne()
    {
        bool iDecide = doIDecideWhoIsPlayerOne();

        ConsoleScreen.Log("i decide");
        if (iDecide)
        {
            GlobalGameManager.amIPlayerOne = UnityEngine.Random.value <= 0.5;
            Debug.LogFormat("DecideWhoIsPlayerOne - decide p1 - %s", GlobalGameManager.amIPlayerOne);
            if (GlobalGameManager.amIPlayerOne)
            {
                ConsoleScreen.Log("i am");
                OnlineMessage message = new OnlineMessage();
                message.participantIdPlayerOne = PlayGamesPlatform.Instance.RealTime.GetSelf().ParticipantId;
                PlayGamesPlatform.Instance.RealTime.SendMessageToAll(true, serializeMessage(message));
                playerOneDecided = true;
                CurrentState     = State.MY_TURN;
            }
        }
    }
예제 #8
0
    public static OnlineMessage DecodeMessage(byte[] update)
    {
        SimpleJSON.JSONClass jsonObj = (SimpleJSON.JSONClass)SimpleJSON.JSONClass.Parse(System.Text.Encoding.UTF8.GetString(update, 0, update.Length));

        OnlineMessage msg = new OnlineMessage();
        msg.sender = jsonObj["sender"].Value;
        msg.type = jsonObj["type"].Value;
        if(msg.type == "move")
        {
            msg.gridBoxIndex = jsonObj["gridBoxIndex"].AsInt;
            msg.piece = jsonObj["piece"].Value;
        }
        if(msg.type == "online_event")
        {
            int i = jsonObj["gE"].AsInt;
            EOnlineGameEvent e = (EOnlineGameEvent)jsonObj["gE"].AsInt;
            EOnlineGameEvent eb = EOnlineGameEvent.ONL_EVT_START_MATCH+i;
            bool hasEP = jsonObj["hasEP"].AsBool;
            object obj = hasEP? (object)jsonObj["gEP"].AsObject: null;
            msg.onlineEvent = new OnlineGameEvent(e, obj);
        }
        return msg;
    }
예제 #9
0
        /// <summary>
        /// 像目标设备发送一个udp数据包。对方收到后,回复一个数据包,发送者收到这个数据包之后更新device的最新在线时间。
        /// </summary>
        public void Ping()
        {
            var m = new OnlineMessage(AppModel.Instance.LocalDevice);

            SendUdpMessage(m);
        }
예제 #10
0
        /// <summary>
        /// 像目标设备发送一个udp数据包。对方收到后,回复一个数据包,发送者收到这个数据包之后更新device的最新在线时间。
        /// </summary>
        public void Ping()
        {
            var m = new OnlineMessage(SuperDriveCore.LocalDevice);

            SendUdpMessage(m);
        }