Beispiel #1
0
        //private float estimatedServerFrameTime = 0f;

        public ClientNetworking(SocketWrapperSettings settings, int appId)
        {
            FrameID = NetworkConstants.BeforeStartOfGameFrameId;

            packetDispatcher = new PacketDispatcher();
            cpcs             = new ClientPlayerConnectionState(new SocketWrapper(settings), appId);

            // Forward events from the CPCS to IClientNetworking
            cpcs.OnConnect       += () => { OnConnect?.Invoke(); };
            cpcs.OnDisconnect    += (retry) => { OnDisconnect?.Invoke(retry); };
            cpcs.OnLoginResponse += (response) => { OnLoginResponse?.Invoke(response); };

            // We want to know when the server tells us it's frameid, so we can keep in sync
            packetDispatcher.AddListener <ServerTick>(OnServerTickPacket);
        }
Beispiel #2
0
        private void HandleLoginCredentialsValidPacket(LoginCredentialValid packet)
        {
            IsLoggedIn = packet.isValid;
            if (IsLoggedIn)
            {
                // Tell the server that we're ready for moar data
                LoginClientReady temp = (LoginClientReady)IntrepidSerialize.TakeFromPool(PacketType.LoginClientReady);
                Send(temp);
                ClientGameInfoResponse cgir = (ClientGameInfoResponse)IntrepidSerialize.TakeFromPool(PacketType.ClientGameInfoResponse);
                cgir.GameId = ApplicationId;
                Send(cgir);
            }
            else
            {
                // Allows us to try to login again
                hasSentCredentials = false;
            }

            OnLoginResponse?.Invoke(new LoginResponse(packet.isValid));
        }
Beispiel #3
0
        public void Response()
        {
            while (true)
            {
                try
                {
                    byte[] receivebuffer = new byte[this.buffersize];
                    //this..Receive(receivebuffer, 0, receivebuffer.Length, 0);
                    //string response = Encoding.ASCII.GetString(receivebuffer);

                    StringBuilder messageData = new StringBuilder();
                    int           bytes       = -1;
                    do
                    {
                        bytes = sslStream.Read(receivebuffer, 0, receivebuffer.Length);
                        Decoder decoder     = Encoding.UTF8.GetDecoder();
                        char[]  messagepart = new char[decoder.GetCharCount(receivebuffer, 0, bytes)];
                        decoder.GetChars(receivebuffer, 0, bytes, messagepart, 0);
                        messageData.Append(messagepart);
                        if (messageData.ToString().IndexOf("<EOF>") != -1)
                        {
                            break;
                        }
                    } while (bytes != 0);

                    string response = messageData.ToString();
                    response = response.Substring(0, response.Length - 5);



                    Console.WriteLine(response);
                    JObject obj = JObject.Parse(response);
                    if (obj["action"] == null)
                    {
                        /*
                         *  Error shit
                         *  To do:
                         *  Write a file with the logs
                         *  Creating the MedicalProblems object
                         *
                         *
                         */
                        Console.WriteLine("No action has been sent!");

                        return;
                    }
                    string action = (string)obj["action"];
                    switch (action)
                    {
                    case "response":
                        MedicalProblems problem = new MedicalProblems();
                        Console.WriteLine("yes");
                        Console.WriteLine(obj["rezultat"][0][0].GetType());
                        Console.WriteLine(obj["rezultat"][1][1]);
                        problem.Chanse_To_Have         = obj["rezultat"][0][0].ToObject <double>();
                        problem.Chanse_To_Have_Nothing = obj["rezultat"][1][1].ToObject <double>();

                        //Console.WriteLine("Problem with invoke shit");
                        OnResponse?.Invoke(this, new OnReceiveMessageClientEventArgs {
                            Medical = problem
                        });

                        break;

                    case "regresponse":
                        Console.WriteLine("Receiving register response");
                        OnRegisterResponse?.Invoke(this, new OnReceiveRegisterMessageArgs {
                            errorcode = (int)obj["errorcode"], errormessage = (string)obj["errormessage"]
                        });

                        break;

                    case "loginresponse":
                        //Console.WriteLine("Receiving login response");
                        Console.WriteLine("Code..... \n");
                        string errorcodeestring = (string)obj["error"];
                        Console.WriteLine(errorcodeestring);
                        int errorcodee = Int32.Parse(errorcodeestring);
                        Console.WriteLine("Cod de eroare: " + errorcodee);

                        if (errorcodee == 0)
                        {
                            this.Cookie  = (string)obj["cookie"];
                            this.isloged = true;
                        }

                        OnLoginResponse?.Invoke(this, new OnReceiveLoginMessageArgs {
                            errorcode = errorcodee, errormessage = (string)obj["errormessage"], username = (string)obj["username"]
                        });

                        break;

                    case "code_verify_response":
                        Console.WriteLine("Receiving code_verify response");
                        OnCodeVerifyResponse?.Invoke(this, new OnCodeVerifyResponseArgs {
                            errorcode = (int)obj["errorcode"], errormessage = (string)obj["errormessage"]
                        });


                        break;


                    case "results":
                        int errorcode = (int)obj["error"];

                        if (errorcode == 0)
                        {
                            OnReceiveResultArgs args = JsonConvert.DeserializeObject <OnReceiveResultArgs>(response);

                            OnReceiveResults?.Invoke(this, args);
                        }
                        else
                        {
                        }



                        break;

                    default:
                        /*
                         * Some error comming from server
                         * or maybe from client?
                         * IDK
                         *
                         * */
                        break;
                    }
                }
                catch (Exception ex)
                {
                    OnConnectionLost?.Invoke(this, EventArgs.Empty);
                    Console.WriteLine("Wrong format " + ex.Message);
                    this.isloged = false;
                    break;
                }
            }
        }