Esempio n. 1
0
        public static void MessageReceived(HS_SocketDataWorker sdw, string message)
        {
            JsonDataMessage request = JsonDataMessage.Parse(message.Trim());

            Log(message);
            if (request.Data1 == "login")
            {
                clients[sdw].userid = request.Data2;
                //TODO make this async
                Log("API call");
                string stringResponse = NetUtil.PostSynchro(Settings.Current.InternalTokenLookupUrl,
                                                            new Dictionary <string, string> {
                    { "code", Settings.Current.InternalApiAccessCode }, { "userid", request.Data2 }
                });
                Log("Response: " + stringResponse);
                ServerResponse response = ServerResponse.Parse(stringResponse);
                clients[sdw].symkey = response.Data1;
                Log("Sym token: " + response.Data1);
                sdw.Symkey = response.Data1;

                JsonDataMessage readyRequest = new JsonDataMessage("ready");
                Log("User joined, sending ready message: " + readyRequest.Json);
                sdw.Send(readyRequest.Json);
                legacy2PlayerQueue.Enqueue(sdw);
            }

            CheckGameStart();
        }
Esempio n. 2
0
        static void MessageReceived(HS_SocketDataWorker sdw, string message)
        {
            //Decrypt
            string       json    = RSAHandler.Decrypt(private_key, message);
            LoginRequest request = LoginRequest.Parse(json);

            Console.WriteLine(json);

            //Check login
            //TODO make this async
            string stringResponse = NetUtil.PostSynchro(Settings.Current.InternalLoginUrl,
                                                        new System.Collections.Generic.Dictionary <string, string>()
            {
                { "code", Settings.Current.InternalApiAccessCode }, { "userid", request.Username },
                { "password", request.Password }, { "key", request.Key }
            });
            ServerResponse response = ServerResponse.Parse(stringResponse);

            Log(stringResponse);

            if (response != null)
            {
                if (response.Result == "success")
                {
                    Log("success sending back");
                    string sec = Convert.ToBase64String(TDESHandler.Encrypt(request.Key, stringResponse));
                    sdw.Send(sec);
                }
                else
                {
                }
            }
        }
Esempio n. 3
0
 public void LoginMessageReceived(HS_SocketDataWorker sdw, string message)
 {
     try{
         string MSG = TDESHandler.Decrypt(sym_key, message);
         Debug.Log("Message received: " + MSG);
         ServerResponse response = ServerResponse.Parse(MSG);
         msg    = response.Result;
         userid = response.Data1;
         //TODO close the socket
         //TODO check result with json
         GameServerLogin();
     }
     catch (Exception e)
     {
         Debug.Log(e.ToString());
     }
 }