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


C# MessageReader.Read方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: HandleScenarioModuleData

        public static void HandleScenarioModuleData(ClientObject client, byte[] messageData)
        {
            using (MessageReader mr = new MessageReader(messageData))
            {
                //Don't care about subspace / send time.
                string[] scenarioName = mr.Read<string[]>();
                DarkLog.Debug("Saving " + scenarioName.Length + " scenario modules from " + client.playerName);

                for (int i = 0; i < scenarioName.Length; i++)
                {
                    byte[] scenarioData = Compression.DecompressIfNeeded(mr.Read<byte[]>());
                    File.WriteAllBytes(Path.Combine(Server.universeDirectory, "Scenarios", client.playerName, scenarioName[i] + ".txt"), scenarioData);
                }
            }
        }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:15,代码来源:ScenarioData.cs

示例6: HandleModDataMessage

 public static void HandleModDataMessage(ClientObject client, byte[] messageData)
 {
     using (MessageReader mr = new MessageReader(messageData))
     {
         string modName = mr.Read<string>();
         bool relay = mr.Read<bool>();
         bool highPriority = mr.Read<bool>();
         byte[] modData = mr.Read<byte[]>();
         if (relay)
         {
             DMPModInterface.SendDMPModMessageToAll(client, modName, modData, highPriority);
         }
         DMPModInterface.OnModMessageReceived(client, modName, modData);
     }
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:15,代码来源:ModData.cs

示例7: HandleLockMessage

 public void HandleLockMessage(byte[] messageData)
 {
     lock (lockObject)
     {
         using (MessageReader mr = new MessageReader(messageData, false))
         {
             LockMessageType lockMessageType = (LockMessageType)mr.Read<int>();
             switch (lockMessageType)
             {
                 case LockMessageType.LIST:
                     {
                         //We shouldn't need to clear this as LIST is only sent once, but better safe than sorry.
                         serverLocks.Clear();
                         string[] lockKeys = mr.Read<string[]>();
                         string[] lockValues = mr.Read<string[]>();
                         for (int i = 0; i < lockKeys.Length; i++)
                         {
                             serverLocks.Add(lockKeys[i], lockValues[i]);
                         }
                     }
                     break;
                 case LockMessageType.ACQUIRE:
                     {
                         string playerName = mr.Read<string>();
                         string lockName = mr.Read<string>();
                         bool lockResult = mr.Read<bool>();
                         if (lockResult)
                         {
                             serverLocks[lockName] = playerName;
                         }
                         FireAcquireEvent(playerName, lockName, lockResult);
                     }
                     break;
                 case LockMessageType.RELEASE:
                     {
                         string playerName = mr.Read<string>();
                         string lockName = mr.Read<string>();
                         if (serverLocks.ContainsKey(lockName))
                         {
                             serverLocks.Remove(lockName);
                         }
                         FireReleaseEvent(playerName, lockName);
                     }
                     break;
             }
         }
     }
 }
开发者ID:nevercast,项目名称:DarkMultiPlayer,代码行数:48,代码来源:LockSystem.cs

示例8: 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

示例9: 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

示例10: OnMessageReceived

 public void OnMessageReceived(ClientObject client, ClientMessage message)
 {
     if (message.type == ClientMessageType.CHAT_MESSAGE)
     {
         using (MessageReader mr = new MessageReader(message.data, false))
         {
             ChatMessageType messageType = (ChatMessageType)mr.Read<int>();
             string fromPlayer = mr.Read<string>();
             if (messageType == ChatMessageType.CHANNEL_MESSAGE)
             {
                 string channel = mr.Read<string>();
                 string umessage = mr.Read<string>();
                 ircClient.Channels["#" + channel].SendMessage(String.Format("{0} -> {1}", fromPlayer, umessage));
             }
         }
     }
 }
开发者ID:JoshBlake,项目名称:DarkChat,代码行数:17,代码来源:DarkChat.cs

示例11: 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

示例12: 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

示例13: HandlePlayerStatus

 public static void HandlePlayerStatus(ClientObject client, byte[] messageData)
 {
     using (MessageReader mr = new MessageReader(messageData))
     {
         string playerName = mr.Read<string>();
         if (playerName != client.playerName)
         {
             DarkLog.Debug(client.playerName + " tried to send an update for " + playerName + ", kicking.");
             Messages.ConnectionEnd.SendConnectionEnd(client, "Kicked for sending an update for another player");
             return;
         }
         client.playerStatus.vesselText = mr.Read<string>();
         client.playerStatus.statusText = mr.Read<string>();
     }
     //Relay the message
     ServerMessage newMessage = new ServerMessage();
     newMessage.type = ServerMessageType.PLAYER_STATUS;
     newMessage.data = messageData;
     ClientHandler.SendToAll(client, newMessage, false);
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:20,代码来源:PlayerStatus.cs

示例14: HandleKerbalProto

 public static void HandleKerbalProto(ClientObject client, byte[] messageData)
 {
     //Send kerbal
     using (MessageReader mr = new MessageReader(messageData))
     {
         //Don't care about subspace / send time.
         mr.Read<double>();
         string kerbalName = mr.Read<string>();
         DarkLog.Debug("Saving kerbal " + kerbalName + " from " + client.playerName);
         byte[] kerbalData = mr.Read<byte[]>();
         lock (Server.universeSizeLock)
         {
             File.WriteAllBytes(Path.Combine(Server.universeDirectory, "Kerbals", kerbalName + ".txt"), kerbalData);
         }
     }
     ServerMessage newMessage = new ServerMessage();
     newMessage.type = ServerMessageType.KERBAL_REPLY;
     newMessage.data = messageData;
     ClientHandler.SendToAll(client, newMessage, false);
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:20,代码来源:KerbalProto.cs

示例15: OnCKANRequest

 //Receive message data (PROTOCOL 1):
 //int ckan protocol version
 //int ckan request type:
 //1: CKAN metadata file
 //Send message data (PROTOCOL 1):
 //int ckan protocol version
 //bool ckan available (true/false)
 //if ckan available: UTF-8 string (ckan export data)
 private void OnCKANRequest(ClientObject client, byte[] messageData)
 {
     using (MessageReader mr = new MessageReader(messageData))
     {
         int clientProtocol = mr.Read<int>();
         if (clientProtocol != CKAN_PROTOCOL_VERSION)
         {
             DarkLog.Error("Client " + client.playerName + " connected with CKAN protocol " + clientProtocol + ", server version: " + CKAN_PROTOCOL_VERSION);
             return;
         }
         int requestType = mr.Read<int>();
         switch (requestType)
         {
             case 1:
                 SendCKANFileToClient(client);
                 break;
             default:
                 DarkLog.Error("Unknown CKAN request type: " + requestType);
                 break;
         }
     }
 }
开发者ID:godarklight,项目名称:DMPCkanPlugin,代码行数:30,代码来源:DMPServerPlugin.cs


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