예제 #1
0
        internal OrderHeader WriteOrderHeader(OrderType type, byte gameInstanceId)
        {
            this.WriteBuffer.Position = 0;
            var id     = this.nextOrderId++;
            var header = new OrderHeader(id, type, gameInstanceId, this.client.Id);

            header.Write(this.Writer);
            return(header);
        }
예제 #2
0
        internal OrderHeader WriteOrderHeader(OrderType type)
        {
            this.WriteBuffer.Position = 0;
            var id     = this.nextOrderId++;
            var header = new OrderHeader(id, type, this.Game != null ? this.Game.Id : GameServer.InvalidGameId, this.client.Id);

            header.Write(this.Writer);
            return(header);
        }
예제 #3
0
        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;
            }
        }