Ejemplo n.º 1
0
        public ReplyData get_temporary_name(IPAddress remoteIP, int remotePort, List <string> arguments, string body, string method, Dictionary <string, string> Headers)
        {
            ReplyData rd = new ReplyData();

            PersonNameGenerator png  = new PersonNameGenerator();
            PlaceNameGenerator  plng = new PlaceNameGenerator();

            // We're generating the entire domain entry in the data store
            DomainMemory.DomainObject DO = new DomainMemory.DomainObject()
            {
                PlaceName = png.GenerateRandomFirstName() + "-" + plng.GenerateRandomPlaceName() + "-" + new Random().Next(500, 9000).ToString(),
                DomainID  = Guid.NewGuid().ToString(),
                IPAddr    = remoteIP.ToString()
            };


            DO.API_Key = Tools.MD5Hash($":{DO.PlaceName}::{DO.DomainID}:{DO.IPAddr}");

            DomainReplyDataWithKey drd = new DomainReplyDataWithKey();

            drd.ice_server_address = DO.IPAddr;
            drd.api_key            = DO.API_Key;
            drd.id   = DO.DomainID;
            drd.name = DO.PlaceName;

            TemporaryPlaceNameReply tpnr = new TemporaryPlaceNameReply();

            tpnr.status = "success";
            tpnr.data   = new Dictionary <string, DomainReplyDataWithKey>();
            tpnr.data.Add("domain", drd);

            rd.Status = 200;
            rd.Body   = JsonConvert.SerializeObject(tpnr);

            DomainMemory.MemoryItem mi = new DomainMemory.MemoryItem();
            mi.Obj = DO;
            Session.Instance.DomainsMem.Itms.Add(DO.DomainID, mi);

            rd.CustomOutputHeaders = new Dictionary <string, string>();
            rd.CustomOutputHeaders.Add("X-Rack-CORS", "miss; no-origin");
            rd.CustomOutputHeaders.Add("Access-Control-Allow-Origin", "*");
            return(rd);
        }
Ejemplo n.º 2
0
        public ReplyData domain_heartbeat(IPAddress remoteIP, int remotePort, List <string> arguments, string body, string method, Dictionary <string, string> Headers)
        {
            // Check the Authorization header for a valid Access token
            // If token is valid, begin updating stuff
            ReplyData rd = new ReplyData();

            rd.Status = 200;
            rd.Body   = "";
            if (Headers.ContainsKey("Authorization"))
            {
                string       Token = Headers["Authorization"].Split(new[] { ' ' })[1];
                UserAccounts ua    = UserAccounts.GetAccounts();
                foreach (KeyValuePair <string, UserAccounts.Account> kvp in ua.AllAccounts)
                {
                    if (kvp.Value.ActiveTokens.ContainsKey(Token))
                    {
                        // Start updating shit
                        Dictionary <string, HeartbeatPacket> requestData = JsonConvert.DeserializeObject <Dictionary <string, HeartbeatPacket> >(body);

                        DomainMemory mem = Session.Instance.DomainsMem;
                        // Check if this domain is in memory!
                        if (mem.Itms.ContainsKey(arguments[0]))
                        {
                            // start

                            DomainMemory.MemoryItem   mi  = mem.Itms[arguments[0]];
                            DomainMemory.DomainObject obj = mi.Obj;
                            // First check that there is a API Key
                            if (obj.API_Key == "" || obj.API_Key == null)
                            {
                                rd.Status = 401;
                                break;
                            }
                            obj.NetworkingMode = requestData["domain"].automatic_networking;
                            HeartbeatData dat = requestData["domain"].heartbeat;
                            obj.Protocol   = dat.protocol;
                            obj.Restricted = dat.restricted;
                            obj.Version    = dat.version;
                            obj.LoggedIn   = dat.num_users;
                            obj.Anon       = dat.num_anon_users;
                            obj.TotalUsers = dat.num_anon_users + dat.num_users;
                            mi.Obj         = obj;

                            Session.Instance.DomainsMem.Itms[arguments[0]] = mi;


                            rd.Status = 200;
                            rd.Body   = "";
                        }
                        else
                        {
                            rd.Status = 404; // this will trigger a new temporary domain name
                        }
                    }
                }
            }


            // fallback
            if (Session.Instance.DomainsMem.Itms.ContainsKey(arguments[0]) == false)
            {
                rd.Status = 404;
            }
            return(rd);
        }