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


C# KMPCommon类代码示例

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


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

示例1: buildMessageByteArray

        private static byte[] buildMessageByteArray(KMPCommon.ClientMessageID id, byte[] data, byte[] prefix = null)
        {
            byte[] compressed_data = null;
            int prefix_length = 0;
            if (prefix != null)
                prefix_length = prefix.Length;

            int msg_data_length = 0;
            if (data != null)
            {
                compressed_data = KMPCommon.Compress(data);
                if (compressed_data == null) compressed_data = KMPCommon.Compress(data, true);
                msg_data_length = compressed_data.Length;
            }

            byte[] message_bytes = new byte[KMPCommon.MSG_HEADER_LENGTH + msg_data_length + prefix_length];

            int index = 0;

            if (prefix != null)
            {
                prefix.CopyTo(message_bytes, index);
                index += 4;
            }

            KMPCommon.intToBytes((int)id).CopyTo(message_bytes, index);
            index += 4;

            KMPCommon.intToBytes(msg_data_length).CopyTo(message_bytes, index);
            index += 4;

            if (compressed_data != null)
            {
                compressed_data.CopyTo(message_bytes, index);
                index += compressed_data.Length;
            }
            return message_bytes;
        }
开发者ID:paralin,项目名称:KerbalMultiPlayer,代码行数:38,代码来源:KMPClientMain.cs

示例2: enqueueClientInteropMessage

        static void enqueueClientInteropMessage(KMPCommon.ClientInteropMessageID id, byte[] data)
        {
            int msg_data_length = 0;
            if (data != null)
                msg_data_length = data.Length;

            byte[] message_bytes = new byte[KMPCommon.INTEROP_MSG_HEADER_LENGTH + msg_data_length];

            KMPCommon.intToBytes((int)id).CopyTo(message_bytes, 0);
            KMPCommon.intToBytes(msg_data_length).CopyTo(message_bytes, 4);
            if (data != null)
                data.CopyTo(message_bytes, KMPCommon.INTEROP_MSG_HEADER_LENGTH);

            lock (interopOutQueueLock)
            {
                gameManager.acceptClientInterop (message_bytes);
            }
        }
开发者ID:paralin,项目名称:KerbalMultiPlayer,代码行数:18,代码来源:KMPClientMain.cs

示例3: queueOutgoingUDPMessage

 private static void queueOutgoingUDPMessage(KMPCommon.ClientMessageID id, byte[] data)
 {
     byte[] message_bytes = buildMessageByteArray(id, data, KMPCommon.intToBytes(clientID));
     queuedOutUDPMessages.Enqueue (message_bytes);
 }
开发者ID:paralin,项目名称:KerbalMultiPlayer,代码行数:5,代码来源:KMPClientMain.cs

示例4: sendShareCraftMessage

        private static void sendShareCraftMessage(String craft_name, byte[] data, KMPCommon.CraftType type)
        {
            //Encode message
            byte[] name_bytes = encoder.GetBytes(craft_name);

            byte[] bytes = new byte[8 + name_bytes.Length + data.Length];

            //Check size of data to make sure it's not too large
            if ((name_bytes.Length + data.Length) <= KMPCommon.MAX_CRAFT_FILE_BYTES)
            {
                //Copy data
                KMPCommon.intToBytes((int)type).CopyTo(bytes, 0);
                KMPCommon.intToBytes(name_bytes.Length).CopyTo(bytes, 4);
                name_bytes.CopyTo(bytes, 8);
                data.CopyTo(bytes, 8 + name_bytes.Length);

                queueOutgoingMessage(KMPCommon.ClientMessageID.SHARE_CRAFT_FILE, bytes);
            }
            else
                enqueueTextMessage("Craft file is too large to send.", false, true);
        }
开发者ID:paralin,项目名称:KerbalMultiPlayer,代码行数:21,代码来源:KMPClientMain.cs

示例5: enqueuePluginInteropMessage

        private void enqueuePluginInteropMessage(KMPCommon.PluginInteropMessageID id, byte[] data)
        {
            int msg_data_length = 0;
            if (data != null)
                msg_data_length = data.Length;

            byte[] message_bytes = new byte[KMPCommon.INTEROP_MSG_HEADER_LENGTH + msg_data_length];

            KMPCommon.intToBytes((int)id).CopyTo(message_bytes, 0);
            KMPCommon.intToBytes(msg_data_length).CopyTo(message_bytes, 4);
            if (data != null)
                data.CopyTo(message_bytes, KMPCommon.INTEROP_MSG_HEADER_LENGTH);

            interopOutQueue.Enqueue(message_bytes);

            //Enforce max queue size
            while (interopOutQueue.Count > INTEROP_MAX_QUEUE_SIZE)
                interopOutQueue.Dequeue();
        }
开发者ID:Jumba,项目名称:KerbalMultiPlayer,代码行数:19,代码来源:KMPManager.cs

示例6: sendMessageUDP

        private static void sendMessageUDP(KMPCommon.ClientMessageID id, byte[] data)
        {
            if (udpSocket != null)
            {
                //Send the packet
                try
                {
                    udpSocket.Send(buildMessageByteArray(id, data, KMPCommon.intToBytes(clientID)));
                }
                catch { }

                lock (udpTimestampLock)
                {
                    lastUDPMessageSendTime = stopwatch.ElapsedMilliseconds;
                }

            }
        }
开发者ID:TacticalPenGuinn,项目名称:KerbalMultiPlayer,代码行数:18,代码来源:KMPClientMain.cs

示例7: handleInteropMessage

        static void handleInteropMessage(KMPCommon.PluginInteropMessageID id, byte[] data)
        {
            switch (id)
            {

                case KMPCommon.PluginInteropMessageID.CHAT_SEND:
                    if (data != null)
                    {
                        String line = encoder.GetString(data);

                        InTextMessage message = new InTextMessage();
                        message.fromServer = false;
                        message.isMOTD = false;
                        message.message = "[" + username + "] " + line;
                        enqueueTextMessage(message, false);

                        handleChatInput(line);
                    }

                    break;

                case KMPCommon.PluginInteropMessageID.PLUGIN_DATA:
                    String new_watch_player_name = String.Empty;

                    if (data != null && data.Length >= 9)
                    {
                        UnicodeEncoding encoder = new UnicodeEncoding();
                        int index = 0;

                        //Read current activity status
                        bool in_flight = data[index] != 0;
                        index++;

                        //Read current game title
                        int current_game_title_length = KMPCommon.intFromBytes(data, index);
                        index += 4;

                        currentGameTitle = encoder.GetString(data, index, current_game_title_length);
                        index += current_game_title_length;

                        //Read the watch player name
                        int watch_player_name_length = KMPCommon.intFromBytes(data, index);
                        index += 4;

                        new_watch_player_name = encoder.GetString(data, index, watch_player_name_length);
                        index += watch_player_name_length;

                        //Send the activity status to the server
                        if (in_flight)
                            queueOutgoingMessage(KMPCommon.ClientMessageID.ACTIVITY_UPDATE_IN_FLIGHT, null);
                        else
                            queueOutgoingMessage(KMPCommon.ClientMessageID.ACTIVITY_UPDATE_IN_GAME, null);
                    }

                    if (watchPlayerName != new_watch_player_name)
                    {
                        watchPlayerName = new_watch_player_name;

                        if (watchPlayerName == username && lastSharedScreenshot != null)
                            enqueueClientInteropMessage(KMPCommon.ClientInteropMessageID.SCREENSHOT_RECEIVE, lastSharedScreenshot);

                        sendScreenshotWatchPlayerMessage(watchPlayerName);
                    }
                    break;

                case KMPCommon.PluginInteropMessageID.PRIMARY_PLUGIN_UPDATE:
                    sendPluginUpdate(data, true);
                    break;

                case KMPCommon.PluginInteropMessageID.SECONDARY_PLUGIN_UPDATE:
                    sendPluginUpdate(data, false);
                    break;

                case KMPCommon.PluginInteropMessageID.SCENARIO_UPDATE:
                    sendScenarioUpdate(data);
                    break;

                case KMPCommon.PluginInteropMessageID.SCREENSHOT_SHARE:
                    if (data != null)
                    {
                        lock (screenshotOutLock)
                        {
                            queuedOutScreenshot = data;
                        }
                    }

                    break;
                case KMPCommon.PluginInteropMessageID.WARPING:
                    queueOutgoingMessage(KMPCommon.ClientMessageID.WARPING, data);
                    break;
                case KMPCommon.PluginInteropMessageID.SSYNC:
                    queueOutgoingMessage(KMPCommon.ClientMessageID.SSYNC, data);
                    break;
            }
        }
开发者ID:paralin,项目名称:KerbalMultiPlayer,代码行数:95,代码来源:KMPClientMain.cs

示例8: queueOutgoingMessage

 public void queueOutgoingMessage(KMPCommon.ServerMessageID id, byte[] data)
 {
     queueOutgoingMessage(Server.buildMessageArray(id, data));
 }
开发者ID:Jumba,项目名称:KerbalMultiPlayer,代码行数:4,代码来源:Client.cs

示例9: sendMessageUDP

        private static void sendMessageUDP(KMPCommon.ClientMessageID id, byte[] data)
        {
            if (udpSocket != null)
            {
                //Send the packet
                try
                {
                    udpSocket.Send(buildMessageByteArray(id, data, KMPCommon.intToBytes(clientID)));
                }
                catch (Exception e) {
                    KMP.Log.Debug("Exception thrown in sendMessageUDP(), catch 1, Exception: {0}", e.ToString());
                }

                lock (udpTimestampLock)
                {
                    lastUDPMessageSendTime = stopwatch.ElapsedMilliseconds;
                }

            }
        }
开发者ID:RcColes,项目名称:KerbalMultiPlayer,代码行数:20,代码来源:KMPClientMain.cs

示例10: enqueuePluginInteropMessage

        private void enqueuePluginInteropMessage(KMPCommon.PluginInteropMessageID id, byte[] data)
        {
            int msg_data_length = 0;
            if (data != null)
                msg_data_length = data.Length;

            byte[] message_bytes = new byte[KMPCommon.INTEROP_MSG_HEADER_LENGTH + msg_data_length];

            KMPCommon.intToBytes((int)id).CopyTo(message_bytes, 0);
            KMPCommon.intToBytes(msg_data_length).CopyTo(message_bytes, 4);
            if (data != null)
                data.CopyTo(message_bytes, KMPCommon.INTEROP_MSG_HEADER_LENGTH);

            KMPClientMain.acceptPluginInterop (message_bytes);
        }
开发者ID:vosechu,项目名称:KerbalMultiPlayer,代码行数:15,代码来源:KMPManager.cs

示例11: sendMessageTCP

        private static void sendMessageTCP(KMPCommon.ClientMessageID id, byte[] data)
        {
            lock (tcpSendLock)
            {
                byte[] message_bytes = buildMessageByteArray(id, data);
                int send_bytes_actually_sent = 0;
                while (send_bytes_actually_sent < message_bytes.Length)
                {
                    try
                    {
                        //Send message
                        send_bytes_actually_sent += tcpSocket.Send(message_bytes, send_bytes_actually_sent, message_bytes.Length - send_bytes_actually_sent, SocketFlags.None);
                    //					Just do a blocking send
                    //					tcpSocket.BeginSend(message_bytes, 0, message_bytes.Length, SocketFlags.None,
                    //      					new AsyncCallback(SendCallback), tcpSocket);
                    }
                    catch (System.InvalidOperationException e) {
                        KMP.Log.Debug("Exception thrown in sendMessageTCP(), catch 1, Exception: {0}", e.ToString());
                    }
                    catch (KSP.IO.IOException e) {
                        KMP.Log.Debug("Exception thrown in sendMessageTCP(), catch 2, Exception: {0}", e.ToString());
                    }

                }
            }
            lastTCPMessageSendTime = stopwatch.ElapsedMilliseconds;
        }
开发者ID:RcColes,项目名称:KerbalMultiPlayer,代码行数:27,代码来源:KMPClientMain.cs

示例12: messageReceived

 //Messages
 private void messageReceived(KMPCommon.ClientMessageID id, byte[] data)
 {
     if (id == KMPCommon.ClientMessageID.SPLIT_MESSAGE) {
                 if (splitMessageReceiveIndex == 0) {
                     //New split message
                         int split_message_length = KMPCommon.intFromBytes (data, 4);
                         splitMessageData = new byte[8 + split_message_length];
                         data.CopyTo (splitMessageData, 0);
                         splitMessageReceiveIndex = data.Length;
                 } else {
                         //Continued split message
                         data.CopyTo (splitMessageData, splitMessageReceiveIndex);
                         splitMessageReceiveIndex = splitMessageReceiveIndex + data.Length;
                 }
                 //Check if we have filled the byte array, if so, handle the message.
                 if (splitMessageReceiveIndex == splitMessageData.Length) {
                         //Parse the message and feed it into the client queue
                         KMPCommon.ClientMessageID joined_message_id = (KMPCommon.ClientMessageID)KMPCommon.intFromBytes (splitMessageData, 0);
                         int joined_message_length = KMPCommon.intFromBytes (splitMessageData, 4);
                         byte[] joined_message_data = new byte[joined_message_length];
                         Array.Copy (splitMessageData, 8, joined_message_data, 0, joined_message_length);
                         byte[] joined_message_data_decompressed = KMPCommon.Decompress (joined_message_data);
                         parent.queueClientMessage (this, joined_message_id, joined_message_data_decompressed);
                         splitMessageReceiveIndex = 0;
                 }
         } else {
                 parent.queueClientMessage (this, id, data);
         }
 }
开发者ID:Josvth,项目名称:KerbalMultiPlayer,代码行数:30,代码来源:Client.cs

示例13: handleMessage

        static void handleMessage(KMPCommon.ServerMessageID id, byte[] data)
        {
            //LogAndShare("Message ID: " + id.ToString() + " data: " + (data == null ? "0" : System.Text.Encoding.ASCII.GetString(data)));
            switch (id)
            {
                case KMPCommon.ServerMessageID.HANDSHAKE:
                    Int32 protocol_version = KMPCommon.intFromBytes(data);

                    if (data.Length >= 8)
                    {
                        Int32 server_version_length = KMPCommon.intFromBytes(data, 4);

                        if (data.Length >= 12 + server_version_length)
                        {
                            String server_version = encoder.GetString(data, 8, server_version_length);
                            clientID = KMPCommon.intFromBytes(data, 8 + server_version_length);

                            SetMessage("Handshake received. Server version: " + server_version);
                        }
                    }

                    //End the session if the protocol versions don't match
                    if (protocol_version != KMPCommon.NET_PROTOCOL_VERSION)
                    {
                        endSession = true;
                        intentionalConnectionEnd = true;
                    }
                    else
                    {
                        sendHandshakeMessage(); //Reply to the handshake
                        lock (udpTimestampLock)
                        {
                            lastUDPMessageSendTime = stopwatch.ElapsedMilliseconds;
                        }
                        handshakeCompleted = true;
                    }

                    break;

                case KMPCommon.ServerMessageID.HANDSHAKE_REFUSAL:

                    String refusal_message = encoder.GetString(data, 0, data.Length);

                    endSession = true;
                    intentionalConnectionEnd = true;

                    enqueuePluginChatMessage("Server refused connection. Reason: " + refusal_message, true);

                    break;

                case KMPCommon.ServerMessageID.SERVER_MESSAGE:
                case KMPCommon.ServerMessageID.TEXT_MESSAGE:

                    if (data != null)
                    {

                        InTextMessage in_message = new InTextMessage();

                        in_message.fromServer = (id == KMPCommon.ServerMessageID.SERVER_MESSAGE);
                        in_message.message = encoder.GetString(data, 0, data.Length);

                        //Queue the message
                        enqueueTextMessage(in_message);
                    }

                    break;

                case KMPCommon.ServerMessageID.PLUGIN_UPDATE:

                    if (data != null)
                        enqueueClientInteropMessage(KMPCommon.ClientInteropMessageID.PLUGIN_UPDATE, data);

                    break;

                case KMPCommon.ServerMessageID.SERVER_SETTINGS:

                    lock (serverSettingsLock)
                    {
                        if (data != null && data.Length >= KMPCommon.SERVER_SETTINGS_LENGTH && handshakeCompleted)
                        {

                            updateInterval = KMPCommon.intFromBytes(data, 0);
                            screenshotInterval = KMPCommon.intFromBytes(data, 4);

                            lock (clientDataLock)
                            {
                                int new_screenshot_height = KMPCommon.intFromBytes(data, 8);
                                if (screenshotSettings.maxHeight != new_screenshot_height)
                                {
                                    screenshotSettings.maxHeight = new_screenshot_height;
                                    lastClientDataChangeTime = stopwatch.ElapsedMilliseconds;
                                    enqueueTextMessage("Screenshot Height has been set to " + screenshotSettings.maxHeight);
                                }

                                if (inactiveShipsPerUpdate != data[12])
                                {
                                    inactiveShipsPerUpdate = data[12];
                                    lastClientDataChangeTime = stopwatch.ElapsedMilliseconds;
                                }
                            }
//.........这里部分代码省略.........
开发者ID:TacticalPenGuinn,项目名称:KerbalMultiPlayer,代码行数:101,代码来源:KMPClientMain.cs

示例14: findCraftFilename

        static String findCraftFilename(String craft_name, ref KMPCommon.CraftType craft_type)
        {
            String vab_filename = getCraftFilename(craft_name, KMPCommon.CraftType.VAB);
            if (vab_filename != null && System.IO.File.Exists(vab_filename))
            {
                craft_type = KMPCommon.CraftType.VAB;
                return vab_filename;
            }

            String sph_filename = getCraftFilename(craft_name, KMPCommon.CraftType.SPH);
            if (sph_filename != null && System.IO.File.Exists(sph_filename))
            {
                craft_type = KMPCommon.CraftType.SPH;
                return sph_filename;
            }

            String subassembly_filename = getCraftFilename(craft_name, KMPCommon.CraftType.SUBASSEMBLY);
            if (subassembly_filename != null && System.IO.File.Exists(subassembly_filename))
            {
                craft_type = KMPCommon.CraftType.SUBASSEMBLY;
                return subassembly_filename;
            }

            return null;
        }
开发者ID:paralin,项目名称:KerbalMultiPlayer,代码行数:25,代码来源:KMPClientMain.cs

示例15: handleMessage

        static void handleMessage(KMPCommon.ServerMessageID id, byte[] data)
        {
            //LogAndShare("Message ID: " + id.ToString() + " data: " + (data == null ? "0" : System.Text.Encoding.ASCII.GetString(data)));
            switch (id)
            {
                case KMPCommon.ServerMessageID.HANDSHAKE:
                    Int32 protocol_version = KMPCommon.intFromBytes(data);

                    if (data.Length >= 8)
                    {
                        Int32 server_version_length = KMPCommon.intFromBytes(data, 4);

                        if (data.Length >= 12 + server_version_length)
                        {
                            String server_version = encoder.GetString(data, 8, server_version_length);
                            clientID = KMPCommon.intFromBytes(data, 8 + server_version_length);
                            gameManager.gameMode = KMPCommon.intFromBytes(data, 12 + server_version_length);
                            int kmpModControl_length = KMPCommon.intFromBytes(data, 16 + server_version_length);
                            kmpModControl_bytes = new byte[kmpModControl_length];
                            Array.Copy(data, 20 + server_version_length, kmpModControl_bytes, 0, kmpModControl_length);

                            SetMessage("Handshake received. Server version: " + server_version);
                        }
                    }

                    //End the session if the protocol versions don't match
                    if (protocol_version != KMPCommon.NET_PROTOCOL_VERSION)
                    {
                        endSession = true;
                        intentionalConnectionEnd = true;
                        gameManager.disconnect("Your client is incompatible with this server");
                    }
                    else
                    {
                        if (!modCheck(kmpModControl_bytes))
                        {
                            endSession = true;
                            intentionalConnectionEnd = true;
                            gameManager.disconnect(modMismatchError);
                        }
                        else
                        {
                            sendHandshakeMessage(); //Reply to the handshake
                            lock (udpTimestampLock)
                            {
                                lastUDPMessageSendTime = stopwatch.ElapsedMilliseconds;
                            }
                            handshakeCompleted = true;
                        }
                    }

                    break;

                case KMPCommon.ServerMessageID.HANDSHAKE_REFUSAL:

                    String refusal_message = encoder.GetString(data, 0, data.Length);

                    endSession = true;
                    intentionalConnectionEnd = true;

                    enqueuePluginChatMessage("Server refused connection. Reason: " + refusal_message, true);

                    break;

                case KMPCommon.ServerMessageID.SERVER_MESSAGE:
                case KMPCommon.ServerMessageID.TEXT_MESSAGE:

                    if (data != null)
                    {

                        InTextMessage in_message = new InTextMessage();

                        in_message.fromServer = (id == KMPCommon.ServerMessageID.SERVER_MESSAGE);
                        in_message.isMOTD = (id == KMPCommon.ServerMessageID.MOTD_MESSAGE);
                        in_message.message = encoder.GetString(data, 0, data.Length);
                        if (in_message.message.Contains(" has shared a screenshot.")) {
                            int screenshotSharePlayerNameIndex = in_message.message.IndexOf(" has shared a screenshot.");
                            string screenshotSharePlayerName = in_message.message.Substring(0, screenshotSharePlayerNameIndex);
                            if (screenshotSharePlayerName != username) {
                                bool listPlayerNameInScreenshotsWaiting = false;
                                foreach (string listPlayer in screenshotsWaiting)
                                {
                                    if (listPlayer == screenshotSharePlayerName) {
                                        listPlayerNameInScreenshotsWaiting = true;
                                    }
                                }
                                if (listPlayerNameInScreenshotsWaiting == false)
                                {
                                    screenshotsWaiting.Add(screenshotSharePlayerName);
                                }
                            }
                        }

                        if (in_message.message.Contains(" has disconnected : ")) {
                            int quitPlayerNameIndex = in_message.message.IndexOf(" has disconnected : ");
                            string quitPlayerName = in_message.message.Substring(0, quitPlayerNameIndex);
                            if (quitPlayerName != username) {
                                bool listPlayerNameInScreenshotsWaiting = false;
                                foreach (string listPlayer in screenshotsWaiting)
                                {
//.........这里部分代码省略.........
开发者ID:paralin,项目名称:KerbalMultiPlayer,代码行数:101,代码来源:KMPClientMain.cs


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