예제 #1
0
 public static void EnableServer()
 {
     CreateWindow();
     Persistence.ServerState = 1;
     FireServerEnabled();
     XLog.Log("Enabled Server");
 }
예제 #2
0
 public static void DisableServer()
 {
     DestroyWindow();
     Persistence.ServerState = 0;
     FireServerDisabled();
     XLog.Log("Disabled Server");
 }
예제 #3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="url"></param>
    /// <returns>json:{"status"}</returns>
    private void EditorGetString(object obj)
    {
        DownloadResult result = obj as DownloadResult;

        try
        {
            string         content = "";
            HttpWebRequest request = WebRequest.Create(result.Url) as HttpWebRequest;
            request.Method      = "GET";
            request.ContentType = "text/html;charset=UTF-8";
            HttpWebResponse response   = request.GetResponse() as HttpWebResponse;
            int             statusCode = (int)response.StatusCode;
            if (response.StatusCode == HttpStatusCode.OK)
            {
                XLog.Log(TAG, "请求成功");
                Stream       stream       = response.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, Encoding.GetEncoding("utf-8"));
                content = streamReader.ReadToEnd();
                streamReader.Close();
                response.Close();
            }
            result.StatusCode = statusCode;
            result.Content    = content;
            Results.Add(result);
        }
        catch (Exception exception)
        {
            XLog.LogError(TAG, exception.Message);
            result.StatusCode = -1;
            Results.Add(result);
        }
    }
예제 #4
0
        public PacketIn ProcessPacket(TCPConnection con, byte[] buf, int start, int size)
        {
            PacketIn packet = new PacketIn(buf, start, size);

            switch (packet.ID)
            {
            case 72:     // TS_AC_AES_KEY_IV
                var pAES = new AUTH_PACKETS.AES_KEY_IV(packet);
                m_pAES_KEY = m_cRSA.PrivateDecrypt(pAES.nKey, OpenSSL.Crypto.RSA.Padding.PKCS1);
                GenerateLoginPacket(m_pAES_KEY, con);
                break;

            case 10000:     // TS_AC_RESULT
                var pResult = new AUTH_PACKETS.RESULT(packet.ReadUInt16(), packet.ReadUInt16(), packet.ReadInt32());
                if (pResult.nLoginFlag == 1)
                {
                    PacketOut o = new PacketOut(10021);
                    con.SendTCP(o);
                }
                else
                {
                    m_cAuthConnection.Disconnect();
                    XLog.Log("Login failed. Result: {0} - Disconnecting...", pResult.nResult);
                }
                m_szPassword = string.Empty;
                break;

            case 10022:     // TS_AC_SERVER_LIST
                m_iAuthServerList = new AUTH_PACKETS.SERVER_LIST(packet);
                XLog.Log("Server selection. Please use /select ID to connect to one of the listed servers below.");
                for (int i = 0; i < m_iAuthServerList.count; i++)
                {
                    XLog.Log(string.Format("-> Server {0}: {1}", i + 1, m_iAuthServerList.list[i].server_name));
                }
                break;

            case 10024:     // TS_AC_SELECT_SERVER
                con.Disconnect();

                var pSelectServer = new AUTH_PACKETS.SELECT_SERVER(packet, ref m_pAES_KEY);

                Config.ConfigNet conf = new Config.ConfigNet();
                conf.Port     = m_iAuthServerList.list[m_nSelectedServerIdx].server_port;
                conf.ListenIp = System.Net.IPAddress.Parse(m_iAuthServerList.list[m_nSelectedServerIdx].server_ip);

                PacketOut oEncrypt = new PacketOut(2005);
                oEncrypt.FillString(m_szName, 61);
                oEncrypt.Write(pSelectServer.encrypted_data, 0, pSelectServer.encrypted_data.Length);
                oEncrypt.FinalizeLengthAndChecksum();
                con.Close();
                m_cClientBase.CreateGameServerSession(oEncrypt, conf, m_szName);
                break;

            default:
                break;
            }
            return(packet);
        }
예제 #5
0
 public void CreateServerSelectPacket(int nIndex)
 {
     try {
         PacketOut o = new PacketOut(10023);
         o.WriteUInt16(m_iAuthServerList.list[nIndex - 1].server_idx);
         m_nSelectedServerIdx = nIndex - 1;
         m_cAuthConnection.SendTCP(o);
     }
     catch (Exception e) {
         m_cAuthConnection.Disconnect();
         XLog.Log("Can't connect to server: {0}", e.Message);
     }
 }
예제 #6
0
 public XClientGameEmulator(Config.ConfigNet conf, TCPManager man, XChat.XClientEmulator pBase, string pAccount, PacketOut pOut)
 {
     m_szAccount       = pAccount;
     m_cGameConnection = new TCPConnection(man, null, this, conf);
     try {
         m_cGameConnection.Start();
         m_cGameConnection.SendTCP(CreateVersionPacket());
         m_cGameConnection.SendTCP(pOut);
     }
     catch {
         XLog.Log("Can't connect to Game Server!");
     }
 }
예제 #7
0
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == WM_COPYDATA)
     {
         try
         {
             Handle_CopyData(ref m);
         }
         catch (Exception e)
         {
             XLog.Log($"HandleOnCopyData Exception: {e.Message} {e.StackTrace}");
         }
     }
     base.WndProc(ref m);
 }
예제 #8
0
 /// <summary>
 /// Logs your character into the game
 /// </summary>
 /// <param name="nIndex">Selected Character Index</param>
 /// <returns></returns>
 public void CreateLoginPacket(int nIndex)
 {
     try {
         PacketOut oLogin = new PacketOut(1);
         oLogin.FillString(m_iGameCharacterList.nList[nIndex - 1].szName, 61);
         oLogin.WriteByte((byte)m_iGameCharacterList.nList[nIndex - 1].nRace);
         oLogin.FinalizeLengthAndChecksum();
         m_dHandles.Add(0, m_iGameCharacterList.nList[nIndex - 1].szName);
         m_cGameConnection.SendTCP(oLogin);
         XLog.AddMessage("", "", -5);   // Clear box
     }
     catch (Exception e) {
         XLog.Log("Error while logging in to the server: {0}", e.Message);
     }
 }
예제 #9
0
        public XClientAuthEmulator(TCPManager man, Config.ConfigNet conf, string pAccount, string pPassword, XChat.XClientEmulator cBase)
        {
            m_szName      = pAccount;
            m_szPassword  = pPassword;
            m_cClientBase = cBase;

            try {
                m_cAuthConnection = new TCPConnection(man, null, this, conf);
                m_cAuthConnection.Start();
                m_cAuthConnection.SendTCP(this.CreateVersionPacket());
                m_cAuthConnection.SendTCP(this.CreateAESPacket());
            }
            catch {
                XLog.Log("Can't connect to Authentication Server!");
            }
        }
예제 #10
0
    public void AlipayPayFailed(string json)
    {
        XLog.Log(TAG, "alipay failed:" + json);
        Trade trade = new Trade();

        try
        {
            trade.FromJson(json);

            foreach (AlipayListener listener in Listeners)
            {
                listener.PayFailed(trade);
            }
        }
        catch (Exception exception)
        {
            XLog.LogError(TAG, exception.Message);
        }
    }
예제 #11
0
    public void WxShareResult(string json)
    {
        XLog.Log(TAG, "share result : " + json + ",last share:" + (LastShareInfo == null?"":LastShareInfo.ToString()));

        try
        {
            JsonNode    node          = JsonNode.FromJson(json);
            JsonNode    errorCodeNode = node["errorCode"];
            int         code          = errorCodeNode;
            WxErrorCode errorCode     = (WxErrorCode)code;
            foreach (ShareResultListener listener in Listeners)
            {
                listener.Result(errorCode, LastShareInfo);
            }
        }
        catch (Exception exception)
        {
            XLog.LogError(TAG, exception.Message);
        }
    }
예제 #12
0
    /// <summary>
    /// 初始化
    /// </summary>
    public static void Init(string partnerId, string sellerId, string rsaPrivateKey)
    {
        XLog.Log(TAG, "alipay init");
        try
        {
#if UNITY_IPHONE
            _alipayInit(partnerId, sellerId, rsaPrivateKey);
#elif UNITY_ANDROID
            using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
            {
                using (AndroidJavaObject activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity"))
                {
                    AndroidJavaClass cls = new AndroidJavaClass("com.morln.game.plugin.alipay.UnityMorlnAlipay");
                    cls.CallStatic("init", activity, partnerId, sellerId, rsaPrivateKey);
                }
            }
#endif
        }
        catch (Exception exception)
        {
            XLog.LogError(TAG, exception.Message);
        }
    }
예제 #13
0
    /// <summary>
    /// 支付,可以使安卓支付,也可以是iOS支付宝支付
    /// </summary>
    /// <param name="trade"></param>
    public static void Pay(string subject, string body, string totalFee, string outTradeNo, string notifyUrl)
    {
        XLog.Log(TAG, "alipay pay");
        try
        {
#if UNITY_IPHONE
            _alipayPay(subject, body, totalFee, outTradeNo, notifyUrl);
#elif UNITY_ANDROID
            using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
            {
                using (AndroidJavaObject activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity"))
                {
                    AndroidJavaClass cls = new AndroidJavaClass("com.morln.game.plugin.alipay.UnityMorlnAlipay");
                    cls.CallStatic("pay", subject, body, totalFee, outTradeNo, notifyUrl);
                }
            }
#endif
        }
        catch (Exception exception)
        {
            XLog.LogError(TAG, exception.Message);
        }
    }
예제 #14
0
    private void EditorGetFile(object obj)
    {
        DownloadResult result = obj as DownloadResult;

        try
        {
            HttpWebRequest request = WebRequest.Create(result.Url) as HttpWebRequest;
            request.Method = "GET";
            HttpWebResponse response   = request.GetResponse() as HttpWebResponse;
            int             statusCode = (int)response.StatusCode;
            if (response.StatusCode == HttpStatusCode.OK)
            {
                XLog.Log(TAG, "请求成功");
                Stream     stream = response.GetResponseStream();
                FileStream fs     = File.Create(result.Path);
                byte[]     tmp    = new byte[1024];
                int        size   = 0;
                while ((size = stream.Read(tmp, 0, 1024)) > 0)
                {
                    fs.Write(tmp, 0, size);
                }
                stream.Close();
                fs.Close();
                XLog.Log(TAG, "写文件成功");
            }

            result.StatusCode = statusCode;
            Results.Add(result);
        }
        catch (Exception exception)
        {
            XLog.LogError(TAG, exception.Message);
            result.StatusCode = -1;
            Results.Add(result);
        }
    }
예제 #15
0
 // ===============================================================================
 //                                                              Execute Status Log
 //                                                              ==================
 protected void Log(String msg)
 {
     XLog.Log(msg);
 }
예제 #16
0
 /// <summary>
 /// Mostly unused method here, getting called when the socket is disconnected.
 /// </summary>
 /// <param name="id">ID</param>
 /// <param name="connection">Socket/TCPConnection</param>
 /// <returns>Nothing</returns>
 public void onDisconnect(int id, TCPConnection connection)
 {
     XLog.Log("Disconnected from Game Server");
 }
예제 #17
0
 /// <summary>
 /// Mostly unused method here, getting called when the socket is connected.
 /// </summary>
 /// <param name="id">ID</param>
 /// <param name="connection">Socket/TCPConnection</param>
 /// <returns>Nothing</returns>
 public void onConnect(int id, TCPConnection connection)
 {
     XLog.Log("Connected to Game Server");
 }
예제 #18
0
        /// <summary>
        /// The function which is used to proceed an incoming packet to the active TCPConnection
        /// </summary>
        /// <param name="con">The connection which received the packet</param>
        /// <param name="buf">byte[] array containing the raw content of the received packet</param>
        /// <param name="start">Start of the content in buf, usually 0</param>
        /// <param name="size">Size of the packet (minus start)</param>
        /// <returns>PacketIn -> Converted raw package to MemoryStream based PacketIn</returns>
        public PacketIn ProcessPacket(TCPConnection con, byte[] buf, int start, int size)
        {
            PacketIn packet = new PacketIn(buf, start, size);

            switch (packet.ID)
            {
            case 0:     // ResultMsg
                var res = new AUTH_PACKETS.RESULT(packet.ReadUInt16(), packet.ReadUInt16(), packet.ReadInt32());
                if (res.nRequestPacket == 2005)
                {
                    if (res.nResult == 0)
                    {
                        con.SendTCP(CreateReportPacket());
                        con.SendTCP(CreateCharacterListPacket());
                    }
                    else
                    {
                        con.Disconnect();
                        XLog.Log("Can't connect to game server. Result: {0} - disconnecting...", res.nResult);
                    }
                }
                break;

            case 2004:     // CharacterList
                m_iGameCharacterList = new GAME_PACKETS.CharacterList(packet);
                XLog.Log("Character selection. Please use /use ID to select a character.");
                for (int i = 0; i < m_iGameCharacterList.nCount; i++)
                {
                    XLog.Log("-> Character {0}: {1}", i + 1, m_iGameCharacterList.nList[i].szName);
                }
                break;

            case 21:     // ChatLocal
                var    tmp      = packet.ReadInt32();
                string szSource = m_dHandles.ContainsKey(tmp) ? m_dHandles[tmp] : "INVALID-HANDLE:" + tmp;
                int    nLen     = packet.ReadByte();
                int    nType    = packet.ReadByte();
                XLog.AddMessage(szSource, packet.ReadString(nLen), nType);
                break;

            case 22:     // ChatMsg
                var pMessage = new GAME_PACKETS.ChatMessage(packet);
                XLog.AddMessage(pMessage.szName, pMessage.szMessage, pMessage.nType);
                break;

            case 3:     // Enter: Handle -> Name, small hack so we don't have to read the full packet (which is f*****g large)
                if (packet.ReadByte() == 0)
                {
                    int key = packet.ReadInt32();
                    if (m_dHandles.ContainsKey(key))
                    {
                        m_dHandles.Remove(key);
                    }
                    packet.Seek(77, System.IO.SeekOrigin.Current);
                    string value = packet.ReadString(19);
                    m_dHandles.Add(key, value);
                }
                break;

            case 507:     // Property: Own Name -> Handle
                if (m_dHandles.ContainsKey(0) && m_tPingThread == null)
                {
                    var szName = m_dHandles[0];
                    m_dHandles.Remove(0);
                    m_dHandles.Add(packet.ReadInt32(), szName);
                    m_tPingThread = new System.Threading.Thread(new System.Threading.ThreadStart(SendPingPacket));
                    m_tPingThread.IsBackground = true;
                    m_tPingThread.Start();
                }
                break;

            default:
                break;
            }
            return(packet);
        }
예제 #19
0
    public void Handle_CopyData(ref Message m)
    {
        XLog.Log($"Begin Request: {RequestNumber}");
        RequestNumber++;
        var cdsRequest = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT));

        var request         = "";
        var requestEncoding = Persistence.RequestEncoding;

        XLog.Log($"RequestEncoding: {requestEncoding}");
        if (requestEncoding == IdexEncoding.Ansi)
        {
            request = Marshal.PtrToStringAnsi(cdsRequest.lpData);
        }
        else
        {
            request = Marshal.PtrToStringUni(cdsRequest.lpData);
        }

        XLog.Log($"ClaimMarkerInRequest: {Persistence.ClaimMarkerInRequest}");
        if (Persistence.ClaimMarkerInRequest)
        {
            if (XString.StartsWith(request, Marker))
            {
                XLog.Log($"Eliminate Marker: {Marker}");
                request = request.Substring(Marker.Length).Trim();
            }
            else
            {
                XLog.Log($"Marker is expected but not present. Request is denied.");
                return;
            }
        }

        XLog.Log($"Parse Request");
        string requestServerId = "";
        string requestClientId = "";
        var    requestLines    = XString.SplitIntoLines(request);

        if (requestLines.Length >= 3)
        {
            for (int i = 0; i < 3; i++)
            {
                string requestLine = requestLines[i];
                string left, right;
                XString.ParseAssoc(requestLine, out left, out right);
                if (XString.Eq(left, "ServerId") || XString.Eq(left, "sid"))
                {
                    requestServerId = right;
                }
                else if (XString.Eq(left, "ClientId") || XString.Eq(left, "cid"))
                {
                    requestClientId = right;
                }
            }
        }

        XLog.Log($"Identify client");
        IntPtr clientHandle = IntPtr.Zero;

        if (requestClientId != "")
        {
            XLog.Log($"ClientId: {requestClientId}");
            clientHandle = Native.FindWindow(null, requestClientId);
        }
        if (clientHandle == IntPtr.Zero)
        {
            XLog.Log($"Cannot find client");
            return;
        }
        XLog.Log($"ClientHandle: {clientHandle}");

        var response = "";

        foreach (var actionLine in requestLines)
        {
            if (XString.StartsWith(actionLine, "o ", "g ", "s "))
            {
                var actionPrefix = actionLine.Substring(0, 2).Trim();
                var actionBody   = actionLine.Substring(2).Trim();
                if (XString.Eq(actionPrefix, "o"))
                {
                    XLog.Log($"Execute action: {actionPrefix} {actionBody}");
                    response += actionBody;
                }
                else if (XString.Eq(actionPrefix, "g"))
                {
                    if (Persistence.SupportGetOps)
                    {
                        XLog.Log($"Execute action: {actionPrefix} {actionBody}");
                        var result = Ide.TryGetOp(actionBody);
                        response += result;
                    }
                }
                else if (XString.Eq(actionPrefix, "s"))
                {
                    if (Persistence.SupportSetOps)
                    {
                        XLog.Log($"Execute action: {actionPrefix} {actionBody}");
                        string left, right;
                        XString.ParseAssoc(actionBody, out left, out right);
                        Ide.TrySetOp(left, right);
                    }
                }
            }
            else if (XString.StartsWith(actionLine, "Document."))
            {
                string rest         = actionLine.Substring(9);
                int    openBracket  = rest.IndexOf('(');
                string functionName = rest.Substring(0, openBracket);
                rest = rest.Substring(openBracket + 1);
                int closingBracket = rest.IndexOf(')');
                rest = rest.Substring(0, closingBracket);
                var args = rest.Split(',');
                if (XString.Eq(functionName
                               , "SetSelectedRange"))
                {
                    int startIndex = int.Parse(args[0]);
                    int endIndex   = int.Parse(args[1]);
                    Ide.Document_SetSelectedRange(startIndex, endIndex);
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedRange"))
                {
                    int startIndex = 0;
                    int endIndex   = 0;
                    Ide.Document_GetSelectedRange(out startIndex, out endIndex);
                    response += startIndex + "," + endIndex;
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedText"))
                {
                    string text = Ide.Document_GetSelectedText();
                    response += text;
                }
                else if (XString.Eq(functionName
                                    , "ReplaceSelectedText"))
                {
                    Ide.Document_ReplaceSelectedText();
                }
                else if (XString.Eq(functionName
                                    , "DeleteSelectedText"))
                {
                    Ide.Document_DeleteSelectedText();
                }
                else if (XString.Eq(functionName
                                    , "GetLineIndexByChar"
                                    ))
                {
                    int charIndex = int.Parse(args[0]);
                    int lineIndex = Ide.Document_GetLineIndexByChar(charIndex);
                    response += lineIndex.ToString();
                }
                else if (XString.Eq(functionName
                                    , "GetLine"
                                    ))
                {
                    int    lineIndex   = int.Parse(args[0]);
                    string lineContent = Ide.Document_GetLine(lineIndex);
                    response += lineContent.ToString();
                }
                else if (XString.Eq(functionName
                                    , "SelectLine"
                                    ))
                {
                    int lineIndex = int.Parse(args[0]);
                    Ide.Document_SelectLine(lineIndex);
                }
                else if (XString.Eq(functionName
                                    , "GetLineLength"
                                    ))
                {
                    int charIndex = int.Parse(args[0]);
                    int charCount = Ide.Document_GetLineLength(charIndex);
                    response += charCount.ToString();
                }
                else if (XString.Eq(functionName
                                    , "GetCharIndexByLine"
                                    ))
                {
                    int lineIndex = int.Parse(args[0]);
                    int charIndex = Ide.Document_GetCharIndexByLine(lineIndex);
                    response += charIndex.ToString();
                }
                else if (XString.Eq(functionName
                                    , "GetTextLength"
                                    ))
                {
                    int charCount = Ide.Document_GetTextLength();
                    response += charCount.ToString();
                }
                else if (XString.Eq(functionName
                                    , "GetText"
                                    ))
                {
                    string chars = Ide.Document_GetText();
                    response += chars;
                }
                else if (XString.Eq(functionName
                                    , "ScrollToEnd"
                                    ))
                {
                    Ide.Document_ScrollToEnd();
                }
                else if (XString.Eq(functionName
                                    , "GetCaretLineIndex"
                                    ))
                {
                    response += Ide.Document_GetCaretLineIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetCaretColumnIndex"
                                    ))
                {
                    response += Ide.Document_GetCaretColumnIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedStartLineIndex"
                                    ))
                {
                    response += Ide.Document_GetSelectedStartLineIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedEndLineIndex"
                                    ))
                {
                    response += Ide.Document_GetSelectedEndLineIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedRangeCount"
                                    ))
                {
                    response += Ide.Document_GetSelectedRangeCount();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedStartCharIndex"
                                    ))
                {
                    response += Ide.Document_GetSelectedStartCharIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedEndCharIndex"
                                    ))
                {
                    response += Ide.Document_GetSelectedEndCharIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetOpenDocuments"
                                    ))
                {
                    response += Ide.Document_GetOpenDocuments();
                }
            }
            else if (XString.StartsWith(actionLine, "SolutionExplorer."))
            {
                string   functionName = null;
                string[] args         = null;
                ParseActionLine(actionLine, "SolutionExplorer.",
                                out functionName, out args);

                if (XString.Eq(functionName
                               , "GetSelectedItems"
                               ))
                {
                    response += Ide.SolutionExplorer_GetSelectedItems();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedItemCount"
                                    ))
                {
                    response += Ide.SolutionExplorer_GetSelectedItemCount();
                }
            }
            else if (XString.StartsWith(actionLine, "Base."))
            {
                string   functionName = null;
                string[] args         = null;
                ParseActionLine(actionLine, "Base.",
                                out functionName, out args);

                if (XString.Eq(functionName
                               , "GetServerId"
                               ))
                {
                    response += Ide.Base_GetServerId();
                }
                else if (XString.Eq(functionName
                                    , "SetServerId"
                                    ))
                {
                    string serverId = args[0];
                    Ide.Base_SetServerId(serverId);
                }
                else if (XString.Eq(functionName
                                    , "GetServerHandle"
                                    ))
                {
                    response += Ide.Base_GetServerHandle();
                }
            }
            else if (XString.StartsWith(actionLine, "Output."))
            {
                string   functionName = null;
                string[] args         = null;
                ParseActionLine(actionLine, "Output.",
                                out functionName, out args);

                if (XString.Eq(functionName
                               , "WriteCR"
                               ))
                {
                    response += Ide.Output_WriteCR();
                }
                else if (XString.Eq(functionName
                                    , "WriteLF"
                                    ))
                {
                    response += Ide.Output_WriteLF();
                }
                else if (XString.Eq(functionName
                                    , "WriteCRLF"
                                    ))
                {
                    response += Ide.Output_WriteCRLF();
                }
                else if (XString.Eq(functionName
                                    , "WriteHT"
                                    ))
                {
                    response += Ide.Output_WriteHT();
                }
                else if (XString.Eq(functionName
                                    , "WriteSP"
                                    ))
                {
                    response += Ide.Output_WriteSP();
                }
                else if (XString.Eq(functionName
                                    , "Write"
                                    ))
                {
                    string text = args[0].Trim('"');
                    response += Ide.Output_Write(text);
                }
            }
        }

        XLog.Log($"IncludeMarkerInResponse: {Persistence.IncludeMarkerInResponse}");
        if (Persistence.IncludeMarkerInResponse)
        {
            response += Marker + "\r\n";
        }

        var responseEncoding = Persistence.ResponseEncoding;

        XLog.Log($"ResponseEncoding: {responseEncoding}");
        var sizeInBytes     = (response.Length + 1) * 2;
        var responsePointer = IntPtr.Zero;

        try
        {
            if (responseEncoding == IdexEncoding.Ansi)
            {
                responsePointer = Marshal.StringToCoTaskMemAnsi(response);
            }
            else
            {
                responsePointer = Marshal.StringToCoTaskMemUni(response);
            }

            var cds = new COPYDATASTRUCT();
            cds.cbData = sizeInBytes;
            cds.lpData = responsePointer;
            Native.SendMessage(clientHandle, WM_COPYDATA, IntPtr.Zero, ref cds);
            int errorCode = Marshal.GetLastWin32Error();
            if (errorCode != 0)
            {
                XLog.Log($"SendMessage Code: {errorCode}");
            }
        }
        finally
        {
            XLog.Log($"Free native objects");
            if (responseEncoding == IdexEncoding.Ansi)
            {
                Marshal.ZeroFreeCoTaskMemAnsi(responsePointer);
            }
            else
            {
                Marshal.ZeroFreeCoTaskMemUnicode(responsePointer);
            }
        }
        XLog.Log($"End Request");
    }
예제 #20
0
 public static void Log(string msg)
 {
     XLog.Log(TAG, msg);
 }
예제 #21
0
 /// <summary>
 /// Mostly unused method here, getting called when the socket is disconnected.
 /// </summary>
 /// <param name="id">ID</param>
 /// <param name="connection">Socket/TCPConnection</param>
 /// <returns>Nothing</returns>
 public void onDisconnect(int id, TCPConnection connection)
 {
     XLog.Log("Disconnected from Authentication server.");
 }
예제 #22
0
 /// <summary>
 /// Mostly unused method here, getting called when the socket is connected.
 /// </summary>
 /// <param name="id">ID</param>
 /// <param name="connection">Socket/TCPConnection</param>
 /// <returns>Nothing</returns>
 public void onConnect(int id, TCPConnection connection)
 {
     XLog.Log("Connected to Authentication server.");
 }