コード例 #1
0
        private async System.Threading.Tasks.Task <OrderHeader> ForOrderResponse(uint orderId)
        {
            while (this.orders[orderId].Status != OrderStatus.Executed &&
                   this.orders[orderId].Status != OrderStatus.Refused)
            {
                await System.Threading.Tasks.Task.Yield();
            }

            OrderHeader header = this.orders[orderId];

            switch (header.Status)
            {
            case OrderStatus.Refused:
            case OrderStatus.Executed:
                break;

            default:
                throw new System.Exception($"Invalid order status {header.Status}");
            }

            this.orders.Remove(header.Id);
            return(header);
        }
コード例 #2
0
ファイル: GameServer.cs プロジェクト: Tichau/MoultiGrind
        private void OnMessageReceived(byte clientId, MessageHeader header, BinaryReader buffer)
        {
            switch (header.Type)
            {
            case MessageType.GameOrder:
                OrderHeader orderHeader = new OrderHeader(header, buffer);

                Debug.Log($"[GameServer] {orderHeader.Type} order received from client {clientId}.");

                if (orderHeader.Type == OrderType.Invalid)
                {
                    Debug.LogWarning("Invalid order.");
                    return;
                }

                if (!this.TryGetOrderData(orderHeader, out var orderData))
                {
                    Debug.LogWarning($"No order data found for order {orderHeader.Type}.");
                    return;
                }

                Debug.Assert(orderData.Context != OrderContext.Invalid, $"No server pass context for order {orderData.Type}.");
                Debug.Assert(orderData.ServerPass != null, $"No server pass for order {orderData.Type}.");

                this.WriteBuffer.Position = 0;
                orderHeader.Write(this.Writer);
                orderHeader.Status = orderData.ServerPass.Invoke(buffer, this.Writer);
                Debug.Assert(this.WriteBuffer.Position - MessageHeader.SizeOf >= 0);
                orderHeader.BaseHeader.Size = (ushort)(this.WriteBuffer.Position - MessageHeader.SizeOf);

                // Update order size and status.
                this.WriteBuffer.Position = 0;
                this.Writer.Write(orderHeader.BaseHeader.Size);
                this.WriteBuffer.Position = OrderHeader.StatusPosition;
                this.Writer.Write((byte)orderHeader.Status);

                switch (orderData.Context)
                {
                case OrderContext.Invalid:
                    Debug.LogWarning("Invalid order context.");
                    break;

                case OrderContext.Server:
                    this.server.SendMessage(clientId, this.WriteBuffer);
                    break;

                case OrderContext.Game:
                case OrderContext.Player:
                    this.BroadcastOrder(orderHeader, this.WriteBuffer);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                break;

            default:
                break;
            }
        }
コード例 #3
0
 internal async System.Threading.Tasks.Task <OrderHeader> PostOrder(OrderHeader header)
 {
     this.SendOrderFromWriteBuffer(header);
     return(await this.ForOrderResponse(header.Id));
 }
コード例 #4
0
 private void SendOrderFromWriteBuffer(OrderHeader header)
 {
     this.orders.Add(header.Id, header);
     this.client.SendMessage(this.WriteBuffer);
 }
コード例 #5
0
ファイル: GameInterface.cs プロジェクト: Tichau/MoultiGrind
 public bool Test_TryGetOrderData(OrderHeader header, out OrderData orderData)
 {
     return(this.TryGetOrderData(header, out orderData));
 }