public void TryStart()
        {
            if (this.LeftUser != null && this.RightUser != null)
            {
                this.GameTimer.Restart();
                this.Status = WSStatus.Countdown;

                this.LeftUser.WSPlayer  = new WSPlayer(-3, true);
                this.RightUser.WSPlayer = new WSPlayer(4, false);

                ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.R26_20080915_0408_7984_61ccb5f8b8797a3aba62c1fa2ca80169);
                message.Init(r26Outgoing.StartWobbleCountdown);
                message.AppendString("0:" + this.LeftUser.VirtualID, 13);
                message.AppendString("1:" + this.RightUser.VirtualID, 13);
                this.Room.SendToAll(message);
            }
        }
        public void Leave(RoomUnitUser user)
        {
            if (this.Status == WSStatus.Running || this.Status == WSStatus.Countdown)
            {
                this.Status = WSStatus.NotRunning;

                ServerMessage messageEnd = BasicUtilies.GetRevisionServerMessage(Revision.R26_20080915_0408_7984_61ccb5f8b8797a3aba62c1fa2ca80169);
                messageEnd.Init(r26Outgoing.WobbleEnd);
                this.Room.SendToAll(messageEnd);

                if (this.LeftUser == user)
                {
                    this.LeftUser = null;
                }
                else if (this.RightUser == user)
                {
                    this.RightUser = null;
                }
            }
        }
        public void Done(bool left, bool right)
        {
            this.GameTimer.Restart();
            this.Status = WSStatus.Ending;

            bool tie = left && right;

            if (left)
            {
                this.LeftUser.RestrictMovementType &= ~RestrictMovementType.Server;
                this.LeftUser.MoveTo(this.LeftUser.X + (this.LeftUser.WSPlayer.Lean >= 0 ? 1 : -1), this.LeftUser.Y);
                this.LeftUser.AddStatus("swim", "");

                this.LeftUser.WSPlayer = null;
                this.LeftUser          = null;
            }

            if (right)
            {
                this.RightUser.RestrictMovementType &= ~RestrictMovementType.Server;
                this.RightUser.MoveTo(this.RightUser.X + (this.RightUser.WSPlayer.Lean >= 0 ? 1 : -1), this.RightUser.Y);
                this.RightUser.AddStatus("swim", "");

                this.RightUser.WSPlayer = null;
                this.RightUser          = null;
            }

            if (tie)
            {
                ServerMessage messageTie = BasicUtilies.GetRevisionServerMessage(Revision.R26_20080915_0408_7984_61ccb5f8b8797a3aba62c1fa2ca80169);
                messageTie.Init(r26Outgoing.WobbleTie);
                this.Room.SendToAll(messageTie);
            }
            else
            {
                ServerMessage messageWinner = BasicUtilies.GetRevisionServerMessage(Revision.R26_20080915_0408_7984_61ccb5f8b8797a3aba62c1fa2ca80169);
                messageWinner.Init(r26Outgoing.WonWobble);
                messageWinner.AppendString(right ? "0" : "1", null);
                this.Room.SendToAll(messageWinner);
            }
        }
        protected override string OneMinTicket(DateTime?_initTime = default(DateTime?))
        {
            DateTime initTime = _initTime == null ? DateTime.Now : (DateTime)_initTime;
            string   key1     = string.Empty;

            try { new OBMWS.WSConverter().ToMd5Hash(initTime.ToString("yyyyMMddhhmm"), out key1, true); } catch (Exception e) { WSStatus status = WSStatus.NONE.clone(); WSServerMeta.LogError(GetType(), e, ref status); }
            return(key1);
        }
Exemple #5
0
        public void EnterPrivateSession <S>(WSDataContext db, ClientFunctions CFunc, WSTableSource SessionSrc, WSUserToken _user, string _1MinTicket, ref WSStatus statusLines, bool renew = false) where S : WSDynamicEntity
        {
            try
            {
                if (db != null)
                {
                    if (ExitPrivateSession <S>(db, CFunc, SessionSrc, ref statusLines) && renew && _user.IsValid && ValidateOneMinTicket(_1MinTicket))
                    {
                        try
                        {
                            AuthToken.User = _user;

                            S _session = (S)Activator.CreateInstance(typeof(S), new object[] { });

                            setSession(DateTime.Now, SessionID, AuthToken.User.id, ref _session);

                            db.GetTable <S>().InsertOnSubmit(_session);

                            db.SubmitChanges();

                            Func <S, bool> func = s => s.readPropertyValue(WSConstants.PARAMS.SESSIONID.NAME, "").ToString().ToLower().Equals(SessionID.ToLower());

                            Session = db.GetTable <S>().FirstOrDefault(func);
                        }
                        catch (Exception e) { CFunc.RegError(GetType(), e, ref statusLines); Session = null; }
                    }
                }

                if (Session != null)
                {
                    setAuthToken(Session, ref _AuthToken);
                }
            }
            catch (Exception e) { CFunc.RegError(GetType(), e, ref statusLines); }
        }
Exemple #6
0
        public bool ExitPrivateSession <S>(WSDataContext db, ClientFunctions CFunc, WSTableSource SessionSrc, ref WSStatus statusLines) where S : WSDynamicEntity
        {
            bool DEAUTHORIZED = false;

            try
            {
                AuthToken.issued     = DateTime.MinValue;
                AuthToken.expires    = DateTime.MinValue;
                AuthToken.expires_in = 0;
                AuthToken.User       = null;

                if (Session == null)
                {
                    DEAUTHORIZED = true;
                }
                else
                {
                    if (db != null)
                    {
                        //TODO@ANDVO:2016-11-09 : instead of looking for Primary Key value, - look for 'SessionID' field to make sure ALL related records will be removed

                        string idName  = SessionSrc.PrimParams.Any() && SessionSrc.PrimParams.Count() == 1 ? SessionSrc.PrimParams.Single().WSColumnRef.NAME : null;
                        object idValue = null;

                        if (Session.TryReadPropertyValue(idName, out idValue))
                        {
                            ParameterExpression paramExp = Expression.Parameter(SessionSrc.ReturnType, "x");

                            Expression <Func <S, bool> > expr = new WSJValue(idValue.ToString()).GetFieldFilter(CFunc, (WSTableParam)SessionSrc.GetXParam(idName), paramExp, 0).ToLambda <S>(paramExp);

                            S delItem = db.GetTable <S>().FirstOrDefault(expr);

                            db.GetTable <S>().DeleteOnSubmit(delItem);
                            db.SubmitChanges();
                            DEAUTHORIZED = true;
                        }
                    }
                }
                if (DEAUTHORIZED)
                {
                    AuthToken.status = WSConstants.AUTH_STATES.DEAUTHORIZED;
                }
            }
            catch (Exception e)
            {
                CFunc.RegError(GetType(), e, ref statusLines);
                AuthToken.status = WSConstants.AUTH_STATES.FAILED_DEAUTHORIZE;
            }
            finally { WSServerMeta.ClearCache(SessionID); }
            return(DEAUTHORIZED);
        }
        public void OnCycle()
        {
            if (this.Status == WSStatus.Countdown)
            {
                if (this.GameTimer.Elapsed.TotalSeconds >= 3)
                {
                    this.GameTimer.Restart();
                    this.Status = WSStatus.Running;

                    ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.R26_20080915_0408_7984_61ccb5f8b8797a3aba62c1fa2ca80169);
                    message.Init(r26Outgoing.StartWobbleGame);
                    message.AppendString("0:" + this.LeftUser.VirtualID, 13);
                    message.AppendString("1:" + this.RightUser.VirtualID, 13);
                    this.Room.SendToAll(message);
                }
            }
            else if (this.Status == WSStatus.Running)
            {
                if (this.GameTimer.Elapsed.TotalSeconds <= 90)
                {
                    if (this.LeftUser.WSPlayer.NeedUpdate || this.RightUser.WSPlayer.NeedUpdate)
                    {
                        this.LeftUser.WSPlayer.NeedUpdate  = false;
                        this.RightUser.WSPlayer.NeedUpdate = false;

                        ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.R26_20080915_0408_7984_61ccb5f8b8797a3aba62c1fa2ca80169);
                        message.Init(r26Outgoing.WobbleUpdate);
                        message.AppendString(this.LeftUser.WSPlayer.Location.ToString(), 9);
                        message.AppendString(this.LeftUser.WSPlayer.Lean.ToString(), 9);
                        message.AppendString(this.LeftUser.WSPlayer.Action, 9);
                        message.AppendString(this.LeftUser.WSPlayer.BeenHit ? "h" : "", 13);

                        message.AppendString(this.RightUser.WSPlayer.Location.ToString(), 9);
                        message.AppendString(this.RightUser.WSPlayer.Lean.ToString(), 9);
                        message.AppendString(this.RightUser.WSPlayer.Action, 9);
                        message.AppendString(this.RightUser.WSPlayer.BeenHit ? "h" : "", 9);
                        this.Room.SendToAll(message);

                        this.LeftUser.WSPlayer.Action  = "-";
                        this.RightUser.WSPlayer.Action = "-";

                        this.LeftUser.WSPlayer.BeenHit  = false;
                        this.RightUser.WSPlayer.BeenHit = false;
                    }

                    if (Math.Abs(this.LeftUser.WSPlayer.Lean) >= 100 && Math.Abs(this.RightUser.WSPlayer.Lean) >= 100)
                    {
                        this.Done(true, true);
                    }
                    else if (Math.Abs(this.LeftUser.WSPlayer.Lean) >= 100)
                    {
                        this.Done(true, false);
                    }
                    else if (Math.Abs(this.RightUser.WSPlayer.Lean) >= 100)
                    {
                        this.Done(false, true);
                    }
                }
                else
                {
                    ServerMessage messageTimeout = BasicUtilies.GetRevisionServerMessage(Revision.R26_20080915_0408_7984_61ccb5f8b8797a3aba62c1fa2ca80169);
                    messageTimeout.Init(r26Outgoing.WobbleTimeout);
                    this.Room.SendToAll(messageTimeout);

                    if (this.RightUser.WSPlayer.HitsTakenTotal == this.LeftUser.WSPlayer.HitsTakenTotal)
                    {
                        this.Done(true, true); //Tie I guess
                    }
                    else
                    {
                        if (this.RightUser.WSPlayer.HitsTakenTotal > this.LeftUser.WSPlayer.HitsTakenTotal)
                        {
                            this.Done(false, true);
                        }
                        else
                        {
                            this.Done(true, false);
                        }
                    }
                }
            }
            else if (this.Status == WSStatus.Ending)
            {
                if (this.GameTimer.Elapsed.TotalSeconds >= 1.5)
                {
                    this.Status = WSStatus.NotRunning;

                    ServerMessage messageEnd = BasicUtilies.GetRevisionServerMessage(Revision.R26_20080915_0408_7984_61ccb5f8b8797a3aba62c1fa2ca80169);
                    messageEnd.Init(r26Outgoing.WobbleEnd);
                    this.Room.SendToAll(messageEnd);
                }
            }
        }
 public RoomWobbleSquabbleManager(Room room)
 {
     this.Room      = room;
     this.GameTimer = Stopwatch.StartNew();
     this.Status    = WSStatus.NotRunning;
 }