Send() публичный Метод

public Send ( ServerMessage msg ) : void
msg ServerMessage
Результат void
Пример #1
0
        public async Task DisconnectAsync(IProgress <string> prog)
        {
            if (m_user == null)
            {
                return;
            }

            m_disconnectEvent = new AutoResetEvent(false);

            prog.Report("Saving");
            m_user.SaveEvent += OnGameSaved;
            m_user.Send(new SaveRequestMessage());

            await Task.Run(() => m_disconnectEvent.WaitOne());

            m_user.SaveEvent -= OnGameSaved;
            prog.Report("Logging Out");
            m_user.SendLogOut();

            await Task.Run(() => m_disconnectEvent.WaitOne());

            m_disconnectEvent.Dispose();
            m_disconnectEvent = null;
        }
Пример #2
0
        public void SendProceedTurn()
        {
            turnTrace.TraceVerbose("SendProceedTurn");

            if (m_world.IsOurTurn == false)
            {
                turnTrace.TraceWarning("SendProceedTurn when not our turn");
                return;
            }

            if (m_proceedTurnSent)
            {
                turnTrace.TraceWarning("SendProceedTurn when proceed turn already sent");
                return;
            }

            var list = new List <KeyValuePair <ObjectID, GameAction> >();

            IEnumerable <LivingObject> livings;

            if (m_world.CurrentLivingID == ObjectID.AnyObjectID)
            {
                // livings which the user can control (ie. server not doing high priority action)
                livings = m_world.Controllables.Where(l => l.UserActionPossible());
            }
            else
            {
                var living = m_world.GetObject <LivingObject>(m_world.CurrentLivingID);
                if (living.UserActionPossible() == false)
                {
                    throw new NotImplementedException();
                }
                livings = new LivingObject[] { living };
            }

            var focusedObject = this.FocusedObject;

            foreach (var living in livings)
            {
                GameAction action;

                if (m_actionMap.TryGetValue(living, out action) == false)
                {
                    // skip AI if we're directly controlling the living
                    if (focusedObject != living)
                    {
                        action = living.DecideAction();
                    }
                    else
                    {
                        action = living.CurrentAction;
                    }
                }

                Debug.Assert(action == null || action.GUID.IsNull == false);

                if (action != living.CurrentAction)
                {
                    turnTrace.TraceVerbose("{0}: selecting new action {1}", living, action);
                    list.Add(new KeyValuePair <ObjectID, GameAction>(living.ObjectID, action));
                }
            }

            m_user.Send(new Dwarrowdelf.Messages.ProceedTurnReplyMessage()
            {
                Actions = list.ToArray()
            });

            m_proceedTurnSent = true;
            m_actionMap.Clear();
        }