Exemple #1
0
        private iMsg ProcessLogin(Connection Ctx, Peer Peer, cMsg Command)
        {
            LoginInfo Params = Command.Read <LoginInfo>();

            if (Server.Local)
            {
                Params.key = "local";
            }

            if ((Params.key == null) || (Params.key.Length < 1))
            {
                return(lJson("Invalid key"));
            }
            if ((Params.serial == null) || (Params.serial.Length < 1))
            {
                return(lJson("Invalid serial"));
            }
            if ((Params.key == "local") && !Server.Local)
            {
                return(lJson("Not local"));
            }

            string cKey = Params.key.Trim();

            List <Connection> MatchList = GetMatches(Ctx);

            if (MatchList == null || MatchList.Count == 0)
            {
                MatchList = (List <Connection>)Server.Get(cKey, true);
                if (MatchList.Count > 0)
                {
                    this.Match(MatchList[MatchList.Count - 1], Ctx);
                }
            }

            if (!Server.Contains(Ctx))
            {
                Ctx.Key    = cKey;
                Ctx.Device = false;

                if (Server.Add(Ctx))
                {
                    RegisterLogin(Ctx);
                }
            }

            if (MatchList.Count == 0)
            {
                if (!Server.Local || !StartDevice(Params, Ctx))
                {
                    return(new sMsg("wait", "Recorder is offline"));
                }
            }

            Mirror(Ctx, MatchList, Command.Json);

            return(new sMsg(Command.type, "Succesfull"));
        }
Exemple #2
0
        private iMsg ProcessRegister(Connection Ctx, Peer Peer, cMsg Command)
        {
            RegisterInfo Params = Command.Read <RegisterInfo>();

            if (Server.Local)
            {
                Params.key = "local";
            }

            if ((Params.key == null) || (Params.key.Length < 1))
            {
                return(lJson("Invalid key"));
            }
            if ((Params.serial == null) || (Params.serial.Length < 1))
            {
                return(lJson("Invalid serial"));
            }

            if (Params.key == "local")
            {
                if (!Server.Local)
                {
                    return(lJson("Not local"));
                }
            }

            string cKey      = Params.key.Trim();
            var    MatchList = GetMatches(Ctx);

            if (MatchList.Count == 0)
            {
                MatchList = (List <Connection>)Server.Get(cKey, false);

                foreach (Connection Match in MatchList)
                {
                    this.Match(Match, Ctx);
                }
            }

            Ctx.Key    = cKey;
            Ctx.Device = true;

            if (Server.Add(Ctx))
            {
                RegisterLogin(Ctx);
            }

            Mirror(Ctx, MatchList, Command.Json);

            return(new sMsg(Command.type, "Succesfull"));
        }