Example #1
0
        private static void RmiSend(Socket handler, short rmiId, CCMessage msg)
        {
            var rmiframe = new CCMessage();

            rmiframe.Write(CCMessage.MessageType.Rmi);
            rmiframe.Write(rmiId);
            rmiframe.Write(msg);
            Send(handler, rmiframe);
        }
Example #2
0
        private static void Send(Socket handler, CCMessage data)
        {
            try
            {
                var coreframe = new CCMessage();
                coreframe.Write(Magic);
                coreframe.WriteScalar(data.Length);
                coreframe.Write(data);
                handler.BeginSend(coreframe.Buffer, 0, coreframe.WriteOffset, 0,
                                  SendCallback, handler);
            }
            catch (Exception ex)
            {
                // ignored
#if DEBUG
                Constants.LoginWindow.UpdateLabel($"Error -> {ex.ToString()}");
#endif
            }
        }
        private static void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                var state     = (StateObject)ar.AsyncState;
                var client    = state.WorkSocket;
                var bytesRead = client.EndReceive(ar);

                if (bytesRead > 0)
                {
                    var       msg    = new CCMessage(state.Buffer, bytesRead);
                    short     magic  = 0;
                    ByteArray packet = new CCMessage();
                    if (msg.Read(ref magic) &&
                        magic == Magic &&
                        msg.Read(ref packet))
                    {
                        CCMessage.MessageType coreId = 0;
                        var message = new CCMessage(packet);
                        message.Read(ref coreId);
                        switch (coreId)
                        {
                        case CCMessage.MessageType.Notify:
                        {
                            var info = "";
                            message.Read(ref info);
                            if (info.Contains("<region>") && info.Contains("</region>"))
                            {
                                info = info.Replace("<region>", "");
                                info = info.Replace("</region>", "");
                                if (info == "EU-S4MAX")
                                {
                                    var sendmsg = new CCMessage();
                                    sendmsg.Write(Constants.LoginWindow.GetUsername());
                                    sendmsg.Write(Constants.LoginWindow.GetPassword());
                                    sendmsg.Write(false);

                                    RmiSend(client, 15, sendmsg);
                                    Constants.LoginWindow.UpdateLabel("Authenticating..");
                                }
                                else
                                {
                                    Constants.LoginWindow.UpdateLabel("Error");
                                    Constants.LoginWindow.UpdateErrorLabel("Wrong region/server");
                                }
                            }

                            break;
                        }

                        case CCMessage.MessageType.Rmi:
                        {
                            short rmiId = 0;
                            if (!message.Read(ref rmiId))
                            {
                                Constants.LoginWindow.UpdateLabel("Received corrupted Rmi message.");
                            }
                            else
                            {
                                switch (rmiId)
                                {
                                case 16:
                                {
                                    var success = false;
                                    if (message.Read(ref success) && success)
                                    {
                                        ReceiveDone.Set();
                                        var code = "";
                                        message.Read(ref code);
                                        Constants.LoginWindow.UpdateLabel(
                                            $"Authentication succeeded. code={code}");
                                        Constants.LoginWindow.Ready(code);
                                        _connected = true;
                                        var sendmsg = new CCMessage();
                                        RmiSend(client, 17, sendmsg);
                                        client.Disconnect(false);
                                        client.Close();
                                    }
                                    else
                                    {
                                        ReceiveDone.Set();
                                        var errcode = "";
                                        message.Read(ref errcode);
                                        Constants.LoginWindow.Reset();
                                        Constants.LoginWindow.UpdateErrorLabel($"Failed: {errcode}");
                                        _connected = true;
                                        client.Disconnect(false);
                                        client.Close();
                                    }
                                }
                                break;

                                default:
                                    Constants.LoginWindow.UpdateLabel($"Received unknown rmiId. {rmiId}");
                                    break;
                                }
                            }
                            break;
                        }

                        case CCMessage.MessageType.Encrypted:
                        {
                            break;
                        }
                        }

                        if (!_connected)
                        {
                            client.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0,
                                                ReceiveCallback, state);
                        }
                    }
                    else
                    {
                        ReceiveDone.Set();
                        client.Disconnect(true);
                    }
                }
            }
            catch (Exception e)
            {
                // ignored
#if DEBUG
                Constants.LoginWindow.UpdateLabel($"Error -> {e.ToString()}");
#endif
            }
        }
Example #4
0
        private static void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                var state     = (StateObject)ar.AsyncState;
                var client    = state.WorkSocket;
                var bytesRead = client.EndReceive(ar);

                if (bytesRead > 0)
                {
                    var       msg    = new CCMessage(state.Buffer, bytesRead);
                    short     magic  = 0;
                    ByteArray packet = new CCMessage();
                    if (msg.Read(ref magic) &&
                        magic == Magic &&
                        msg.Read(ref packet))
                    {
                        CCMessage.MessageType coreId = 0;
                        var message = new CCMessage(packet);
                        message.Read(ref coreId);
                        switch (coreId)
                        {
                        case CCMessage.MessageType.Notify:
                        {
                            var info = "";
                            message.Read(ref info);
                            if (info.Contains("<region>") && info.Contains("</region>"))
                            {
                                info = info.Replace("<region>", "");
                                info = info.Replace("</region>", "");
                                if (info == "S4Violet362")
                                {
                                    var sendmsg = new CCMessage();
                                    sendmsg.Write(Constants.LoginWindow.GetUsername());
                                    sendmsg.Write(Constants.LoginWindow.GetPassword());
                                    sendmsg.Write(FingerPrint.Value());
                                    sendmsg.Write("test");

                                    RmiSend(client, 15, sendmsg);
                                    Constants.LoginWindow.UpdateLabel("Connecting...");
                                }
                                else
                                {
                                    Constants.LoginWindow.UpdateLabel("Error");
                                }
                            }

                            break;
                        }

                        case CCMessage.MessageType.Rmi:
                        {
                            short rmiId = 0;
                            if (!message.Read(ref rmiId))
                            {
                                Constants.LoginWindow.UpdateLabel("Received corrupted Rmi message.");
                            }
                            else
                            {
                                switch (rmiId)
                                {
                                case 16:
                                {
                                    var success = false;
                                    if (message.Read(ref success) && success)
                                    {
                                        ReceiveDone.Set();
                                        var code = "";
                                        message.Read(ref code);
                                        Constants.LoginWindow.UpdateLabel(
                                            $"");
                                        Constants.LoginWindow.Ready(code);
                                        _connected = true;
                                        var sendmsg = new CCMessage();
                                        RmiSend(client, 17, sendmsg);
                                        client.Disconnect(false);
                                        client.Close();

                                        Process.Start("S4client.exe", string.Format("-rc:eu -lac:eng -auth_server_ip:{0} -aeria_acc_code:{1}", Constants.ConnectEndPoint.Address, Constants.LoginWindow.AuthCode));
                                        Environment.Exit(0);
                                    }
                                    else
                                    {
                                        ReceiveDone.Set();
                                        var errcode = "";
                                        message.Read(ref errcode);
                                        Constants.LoginWindow.UpdateLabel($"Failed: {errcode}");
                                        Constants.LoginWindow.Reset();
                                        _connected = true;
                                        client.Disconnect(false);
                                        client.Close();
                                    }
                                }
                                break;

                                default:
                                    Constants.LoginWindow.UpdateLabel($"Received unknown rmiId. {rmiId}");
                                    break;
                                }
                            }
                            break;
                        }

                        case CCMessage.MessageType.Encrypted:
                        {
                            break;
                        }
                        }

                        if (!_connected)
                        {
                            client.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0,
                                                ReceiveCallback, state);
                        }
                    }
                    else
                    {
                        ReceiveDone.Set();
                        client.Disconnect(true);
                    }
                }
            }
            catch (Exception e)
            {
                // ignored
#if DEBUG
                Constants.LoginWindow.UpdateLabel($"Error -> {e.ToString()}");
#endif
            }
        }
Example #5
0
 internal void Write(CCMessage obj)
 {
     Write(obj.Buffer);
 }