当前位置: 首页>>代码示例>>C#>>正文


C# MessageReader类代码示例

本文整理汇总了C#中MessageReader的典型用法代码示例。如果您正苦于以下问题:C# MessageReader类的具体用法?C# MessageReader怎么用?C# MessageReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MessageReader类属于命名空间,在下文中一共展示了MessageReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleSplitMessage

 public static void HandleSplitMessage(ClientObject client, byte[] messageData)
 {
     if (!client.isReceivingSplitMessage)
     {
         //New split message
         using (MessageReader mr = new MessageReader(messageData))
         {
             client.receiveSplitMessage = new ClientMessage();
             client.receiveSplitMessage.type = (ClientMessageType)mr.Read<int>();
             client.receiveSplitMessage.data = new byte[mr.Read<int>()];
             client.receiveSplitMessageBytesLeft = client.receiveSplitMessage.data.Length;
             byte[] firstSplitData = mr.Read<byte[]>();
             firstSplitData.CopyTo(client.receiveSplitMessage.data, 0);
             client.receiveSplitMessageBytesLeft -= firstSplitData.Length;
         }
         client.isReceivingSplitMessage = true;
     }
     else
     {
         //Continued split message
         messageData.CopyTo(client.receiveSplitMessage.data, client.receiveSplitMessage.data.Length - client.receiveSplitMessageBytesLeft);
         client.receiveSplitMessageBytesLeft -= messageData.Length;
     }
     if (client.receiveSplitMessageBytesLeft == 0)
     {
         ClientHandler.HandleMessage(client, client.receiveSplitMessage);
         client.receiveSplitMessage = null;
         client.isReceivingSplitMessage = false;
     }
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:30,代码来源:SplitMessage.cs

示例2: HandleAdminMessage

 public void HandleAdminMessage(byte[] messageData)
 {
     using (MessageReader mr = new MessageReader(messageData))
     {
         AdminMessageType messageType = (AdminMessageType)mr.Read<int>();
         switch (messageType)
         {
             case AdminMessageType.LIST:
                 {
                     string[] adminNames = mr.Read<string[]>();
                     foreach (string adminName in adminNames)
                     {
                         RegisterServerAdmin(adminName);
                     }
                 }
                 break;
             case AdminMessageType.ADD:
                 {
                     string adminName = mr.Read<string>();
                     RegisterServerAdmin(adminName);
                 }
                 break;
             case AdminMessageType.REMOVE:
                 {
                     string adminName = mr.Read<string>();
                     UnregisterServerAdmin(adminName);
                 }
                 break;
         }
     }
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:31,代码来源:AdminSystem.cs

示例3: PrintMessage

    internal static void PrintMessage(Message msg)
    {
        Console.WriteLine ("Message (" + msg.Header.Endianness + " endian, v" + msg.Header.MajorVersion + "):");
        Console.WriteLine (indent + "Type: " + msg.Header.MessageType);
        Console.WriteLine (indent + "Flags: " + msg.Header.Flags);
        Console.WriteLine (indent + "Serial: " + msg.Header.Serial);

        //foreach (HeaderField hf in msg.HeaderFields)
        //	Console.WriteLine (indent + hf.Code + ": " + hf.Value);
        Console.WriteLine (indent + "Header Fields:");
        foreach (KeyValuePair<FieldCode,object> field in msg.Header.Fields)
            Console.WriteLine (indent + indent + field.Key + ": " + field.Value);

        Console.WriteLine (indent + "Body (" + msg.Header.Length + " bytes):");
        if (msg.Body != null) {
            MessageReader reader = new MessageReader (msg);

            //TODO: this needs to be done more intelligently
            //TODO: number the args
            try {
                foreach (DType dtype in msg.Signature.GetBuffer ()) {
                    if (dtype == DType.Invalid)
                        continue;
                    object arg = reader.ReadValue (dtype);
                    Console.WriteLine (indent + indent + dtype + ": " + arg);
                }
            } catch {
                Console.WriteLine (indent + indent + "monitor is too dumb to decode message body");
            }
        }
    }
开发者ID:wuyinggz,项目名称:tools,代码行数:31,代码来源:Monitor.cs

示例4: ReadGroup

 static UnknownFieldCollection ReadGroup(MessageTag startTag, MessageReader reader)
 {
     var group = new UnknownFieldCollection();
     for(int stop = startTag.WithWireType(WireType.EndGroup), tag = reader.ReadInt32(); tag != stop; tag = reader.ReadInt32())
         group.Add(new MessageTag(tag), reader);
     return group;
 }
开发者ID:drunkcod,项目名称:ProtoSharp,代码行数:7,代码来源:UnknownFieldGroup.cs

示例5: HandleMessage

        public void HandleMessage(byte[] messageData)
        {
            using (MessageReader mr = new MessageReader(messageData))
            {
                FlagMessageType messageType = (FlagMessageType)mr.Read<int>();
                switch (messageType)
                {
                    case FlagMessageType.LIST:
                        {
                            //List code
                            string[] serverFlagFiles = mr.Read<string[]>();
                            string[] serverFlagOwners = mr.Read<string[]>();
                            string[] serverFlagShaSums = mr.Read<string[]>();
                            for (int i = 0; i < serverFlagFiles.Length; i++)
                            {
                                FlagInfo fi = new FlagInfo();
                                fi.owner = serverFlagOwners[i];
                                fi.shaSum = serverFlagShaSums[i];
                                serverFlags[Path.GetFileNameWithoutExtension(serverFlagFiles[i])] = fi;
                            }
                            syncComplete = true;
                            //Check if we need to upload the flag
                            flagChangeEvent = true;
                        }
                        break;
                    case FlagMessageType.FLAG_DATA:
                        {
                            FlagRespondMessage frm = new FlagRespondMessage();
                            frm.flagInfo.owner = mr.Read<string>();
                            frm.flagName = mr.Read<string>();
                            frm.flagData = mr.Read<byte[]>();
                            frm.flagInfo.shaSum = Common.CalculateSHA256Hash(frm.flagData);
                            newFlags.Enqueue(frm);
                        }
                        break;
                    case FlagMessageType.DELETE_FILE:
                        {
                            string flagName = mr.Read<string>();
                            string flagFile = Path.Combine(flagPath, flagName);
                            if (File.Exists(flagFile))
                            {
                                try
                                {

                                    if (File.Exists(flagFile))
                                    {
                                        DarkLog.Debug("Deleting flag " + flagFile);
                                        File.Delete(flagFile);
                                    }
                                }
                                catch (Exception e)
                                {
                                    DarkLog.Debug("Error deleting flag " + flagFile + ", exception: " + e);
                                }
                            }
                        }
                        break;
                }
            }
        }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:60,代码来源:FlagSyncer.cs

示例6: HandleVesselsRequest

 public static void HandleVesselsRequest(ClientObject client, byte[] messageData)
 {
     using (MessageReader mr = new MessageReader(messageData))
     {
         int sendVesselCount = 0;
         int cachedVesselCount = 0;
         List<string> clientRequested = new List<string>(mr.Read<string[]>());
         lock (Server.universeSizeLock)
         {
             foreach (string file in Directory.GetFiles(Path.Combine(Server.universeDirectory, "Vessels")))
             {
                 string vesselID = Path.GetFileNameWithoutExtension(file);
                 byte[] vesselData = File.ReadAllBytes(file);
                 string vesselObject = Common.CalculateSHA256Hash(vesselData);
                 if (clientRequested.Contains(vesselObject))
                 {
                     sendVesselCount++;
                     VesselProto.SendVessel(client, vesselID, vesselData);
                 }
                 else
                 {
                     cachedVesselCount++;
                 }
             }
         }
         DarkLog.Debug("Sending " + client.playerName + " " + sendVesselCount + " vessels, cached: " + cachedVesselCount + "...");
         SendVesselsComplete(client);
     }
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:29,代码来源:VesselRequest.cs

示例7: HandleVesselRemoval

 public static void HandleVesselRemoval(ClientObject client, byte[] messageData)
 {
     using (MessageReader mr = new MessageReader(messageData))
     {
         //Don't care about the subspace on the server.
         mr.Read<double>();
         string vesselID = mr.Read<string>();
         bool isDockingUpdate = mr.Read<bool>();
         if (!isDockingUpdate)
         {
             DarkLog.Debug("Removing vessel " + vesselID + " from " + client.playerName);
         }
         else
         {
             DarkLog.Debug("Removing DOCKED vessel " + vesselID + " from " + client.playerName);
         }
         if (File.Exists(Path.Combine(Server.universeDirectory, "Vessels", vesselID + ".txt")))
         {
             lock (Server.universeSizeLock)
             {
                 File.Delete(Path.Combine(Server.universeDirectory, "Vessels", vesselID + ".txt"));
             }
         }
         //Relay the message.
         ServerMessage newMessage = new ServerMessage();
         newMessage.type = ServerMessageType.VESSEL_REMOVE;
         newMessage.data = messageData;
         ClientHandler.SendToAll(client, newMessage, false);
     }
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:30,代码来源:VesselRemove.cs

示例8: HandlePlayerColor

 public static void HandlePlayerColor(ClientObject client, byte[] messageData)
 {
     using (MessageReader mr = new MessageReader(messageData))
     {
         PlayerColorMessageType messageType = (PlayerColorMessageType)mr.Read<int>();
         switch (messageType)
         {
             case PlayerColorMessageType.SET:
                 {
                     string playerName = mr.Read<string>();
                     if (playerName != client.playerName)
                     {
                         DarkLog.Debug(client.playerName + " tried to send a color update for " + playerName + ", kicking.");
                         Messages.ConnectionEnd.SendConnectionEnd(client, "Kicked for sending a color update for another player");
                         return;
                     }
                     client.playerColor = mr.Read<float[]>();
                     //Relay the message
                     ServerMessage newMessage = new ServerMessage();
                     newMessage.type = ServerMessageType.PLAYER_COLOR;
                     newMessage.data = messageData;
                     ClientHandler.SendToAll(client, newMessage, true);
                 }
                 break;
         }
     }
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:27,代码来源:PlayerColor.cs

示例9: ExecuteRequest

        public async Task<Response> ExecuteRequest(Request request)
        {
            if (!_tcpClient.Connected)
            {
                throw new InvalidOperationException("Connect first.");
            }

            var converter = new MessageConverter();

            var requestBuffer = new MemoryStream();
            var streamWriter = new HmBinaryMessageWriter(requestBuffer);
            var requestReader = new MessageReader(request);
            converter.Convert(requestReader, streamWriter);


            var networkStream = _tcpClient.GetStream();
            requestBuffer.Position = 0;
            await requestBuffer.CopyToAsync(networkStream);

            await Task.Delay(100);

            //todo: implement buffered reader
            var streamReader = new HmBinaryMessageReader(networkStream);
            var responseBuilder = new MessageBuilder();

            converter.Convert(streamReader, responseBuilder);

            var response = (Response)responseBuilder.Result;

            return response;
        }
开发者ID:flwn,项目名称:HmLib,代码行数:31,代码来源:HmRpcClient.cs

示例10: HandleWarpControl

 public static void HandleWarpControl(ClientObject client, byte[] messageData)
 {
     using (MessageReader mr = new MessageReader(messageData))
     {
         WarpMessageType warpType = (WarpMessageType)mr.Read<int>();
         switch (warpType)
         {
             case WarpMessageType.REQUEST_CONTROLLER:
                 {
                     HandleRequestController(client);
                 }
                 break;
             case WarpMessageType.RELEASE_CONTROLLER:
                 {
                     HandleReleaseController(client);
                 }
                 break;
             case WarpMessageType.REPLY_VOTE:
                 {
                     bool voteReply = mr.Read<bool>();
                     HandleReplyVote(client, voteReply);
                 }
                 break;
             case WarpMessageType.NEW_SUBSPACE:
                 {
                     long serverTime = mr.Read<long>();
                     double planetTime = mr.Read<double>();
                     float subspaceRate = mr.Read<float>();
                     HandleNewSubspace(client, serverTime, planetTime, subspaceRate);
                 }
                 break;
             case WarpMessageType.CHANGE_SUBSPACE:
                 {
                     int newSubspace = mr.Read<int>();
                     HandleChangeSubspace(client, newSubspace);
                 }
                 break;
             case WarpMessageType.REPORT_RATE:
                 {
                     float newSubspaceRate = mr.Read<float>();
                     HandleReportRate(client, newSubspaceRate);
                 }
                 break;
             case WarpMessageType.CHANGE_WARP:
                 {
                     bool physWarp = mr.Read<bool>();
                     int rateIndex = mr.Read<int>();
                     long serverClock = mr.Read<long>();
                     double planetTime = mr.Read<double>();
                     HandleChangeWarp(client, physWarp, rateIndex, serverClock, planetTime);
                 }
                 break;
                 #if DEBUG
             default:
                 throw new NotImplementedException("Warp type not implemented");
                 #endif
         }
     }
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:59,代码来源:WarpControl.cs

示例11: ToType

		public object ToType (Type conversionType, IFormatProvider provider)
		{
			Signature typeSig = Signature.GetSig (conversionType);
			if (typeSig != signature)
				throw new InvalidCastException ();

			MessageReader reader = new MessageReader (endianness, data);
			return reader.ReadValue (conversionType);
		}
开发者ID:brookpatten,项目名称:dbus-sharp,代码行数:9,代码来源:DValue.cs

示例12: ReadCommand

        /// <summary>
        /// Reads the <see cref="MoveVillageObjectCommand"/> from the specified <see cref="MessageReader"/>.
        /// </summary>
        /// <param name="reader">
        /// <see cref="MessageReader"/> that will be used to read the <see cref="MoveVillageObjectCommand"/>.
        /// </param>
        public override void ReadCommand(MessageReader reader)
        {
            MoveData = new MoveVillageObjectData();
            MoveData.X = reader.ReadInt32();
            MoveData.Y = reader.ReadInt32();
            MoveData.VillageObjectGameIndex = reader.ReadInt32();

            Unknown1 = reader.ReadInt32();
        }
开发者ID:circa94,项目名称:CoCSharp,代码行数:15,代码来源:MoveVillageObjectCommand.cs

示例13: ReadMessage

        /// <summary>
        /// Reads the <see cref="OwnHomeDataMessage"/> from the specified <see cref="MessageReader"/>.
        /// </summary>
        /// <param name="reader">
        /// <see cref="MessageReader"/> that will be used to read the <see cref="OwnHomeDataMessage"/>.
        /// </param>
        public override void ReadMessage(MessageReader reader)
        {
            LastVisit = TimeSpan.FromSeconds(reader.ReadInt32());
            Unknown1 = reader.ReadInt32(); // -1
            Timestamp = DateTimeConverter.FromUnixTimestamp(reader.ReadInt32());

            OwnAvatarData = new AvatarData();
            OwnAvatarData.Read(reader);
        }
开发者ID:circa94,项目名称:CoCSharp,代码行数:15,代码来源:OwnHomeDataMessage.cs

示例14: ReadCommand

        /// <summary>
        /// Reads the <see cref="ClearObstacleCommand"/> from the specified <see cref="MessageReader"/>.
        /// </summary>
        /// <param name="reader">
        /// <see cref="MessageReader"/> that will be used to read the <see cref="ClearObstacleCommand"/>.
        /// </param>
        public override void ReadCommand(MessageReader reader)
        {
            var gameID = reader.ReadInt32();
            if (!Obstacle.ValidGameID(gameID))
                throw new InvalidCommandException("Unexpected game ID: " + gameID, this);

            ObstacleGameIndex = Obstacle.GameIDToIndex(gameID);

            Unknown1 = reader.ReadInt32();
        }
开发者ID:circa94,项目名称:CoCSharp,代码行数:16,代码来源:ClearObstacleCommand.cs

示例15: HandleConnectionEnd

 public static void HandleConnectionEnd(ClientObject client, byte[] messageData)
 {
     string reason = "Unknown";
     using (MessageReader mr = new MessageReader(messageData))
     {
         reason = mr.Read<string>();
     }
     DarkLog.Debug(client.playerName + " sent connection end message, reason: " + reason);
     ClientHandler.DisconnectClient(client);
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:10,代码来源:ConnectionEnd.cs


注:本文中的MessageReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。