Esempio n. 1
0
 protected override void loginHandler(UserThread client, CSMessage msg)
 {
     try
     {
         if ((bool)msg.get(MessageType.STATE))
         {
             client.ClientUser = (CSUser)msg.get(MessageType.USER);
             if (view.isOpened())
             {
                 view.loginHandler(client.ClientUser);
             }
         }
         else
         {
             if (view.isOpened())
             {
                 view.showRegisterOption();
                 view.connectionHandler(client.ClientUser);
             }
             log(Severiry.ERROR, (string)msg.get(MessageType.ERROR));
         }
     }
     catch (Exception e)
     {
         log(Severiry.ERROR, "Controller - " + e.Message);
     }
 }
Esempio n. 2
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                string key = m_Key.Value;
                var    val = m_Value.Value;
                if (val.IsInteger)
                {
                    int v = val.Get <int>();
                    GlobalData.Instance.AddInt(key, v);
                }
                else if (val.IsFloat)
                {
                    float v = val.Get <float>();
                    GlobalData.Instance.AddFloat(key, v);
                }
                else
                {
                    string v = val.StringVal;
                    if (null == v)
                    {
                        v = string.Empty;
                    }
                    GlobalData.Instance.AddStr(key, v);
                }
            }
            return(false);
        }
Esempio n. 3
0
 protected void clearHandler(UserThread client)
 {
     if (view.isOpened())
     {
         view.clearHandler();
     }
 }
Esempio n. 4
0
        protected override bool ExecCommand(StoryInstance instance, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                string key = m_Key.Value;
                object val = m_Value.Value;
                if (val is int)
                {
                    int v = (int)val;
                    GlobalData.Instance.AddInt(key, v);
                }
                else if (val is float)
                {
                    float v = (float)val;
                    GlobalData.Instance.AddFloat(key, v);
                }
                else
                {
                    string v = val as string;
                    if (null == v)
                    {
                        v = string.Empty;
                    }
                    GlobalData.Instance.AddStr(key, v);
                }
            }
            return(false);
        }
Esempio n. 5
0
        protected override bool ExecCommand(StoryInstance instance, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                ulong    guid = m_UserGuid.Value;
                object   id   = m_ItemId.Value;
                UserInfo ui   = userThread.GetUserInfo(guid);
                if (null != ui)
                {
                    if (id is ulong)
                    {
                        ulong itemGuid = (ulong)id;
                        ui.ItemBag.DelItemData(itemGuid);
                    }
                    else
                    {
                        try {
                            int itemId = (int)id;
                            ui.ItemBag.DelItemData(itemId);
                        } catch {
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 6
0
        protected override void endGameHandler(UserThread client, CSMessage msg)
        {
            try
            {
                CSUser    challenger = (CSUser)msg.get(MessageType.USER);
                bool      play       = (bool)msg.get(MessageType.PLAY_GAME);
                Object    gameStuff  = (Object)msg.get(MessageType.GAME_STUFF);
                GameState state      = GameState.LOST;

                if (msg.get(MessageType.WIN_GAME) != null)
                {
                    client.ClientUser.win();
                    state = GameState.WON;
                }
                else if (msg.get(MessageType.DRAW_GAME) != null)
                {
                    client.ClientUser.draw();
                    state = GameState.DRAW;
                }

                client.ClientUser.incrementParties();
                if (view.isOpened())
                {
                    view.endGameHandler(client.ClientUser, challenger, state, play, gameStuff);
                }
            }
            catch (Exception e)
            {
                log(Severiry.ERROR, "Controller[EndGame] - " + e.Message);
            }
        }
Esempio n. 7
0
        private void TryUpdateValue(StoryInstance instance)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                if (m_UserGuid.HaveValue && m_Index.HaveValue)
                {
                    ulong  userGuid = m_UserGuid.Value;
                    object id       = m_Index.Value;
                    m_HaveValue = true;
                    UserInfo ui = userThread.GetUserInfo(userGuid);
                    if (null != ui)
                    {
                        if (id is ulong)
                        {
                            ulong guid = (ulong)id;
                            m_Value = ui.ItemBag.GetItemData(guid);
                        }
                        else
                        {
                            try {
                                int itemId = (int)id;
                                m_Value = ui.ItemBag.GetItemData(itemId);
                            } catch {
                                m_Value = null;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        private void TryUpdateValue(StoryInstance instance)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                if (m_UserGuid.HaveValue && m_Index.HaveValue)
                {
                    ulong userGuid = m_UserGuid.Value;
                    int   index    = m_Index.Value;
                    m_HaveValue = true;
                    UserInfo ui = userThread.GetUserInfo(userGuid);
                    if (null != ui)
                    {
                        if (index >= 0 && index < ui.MemberInfos.Count)
                        {
                            m_Value = ui.MemberInfos[index];
                        }
                        else
                        {
                            m_Value = null;
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                ulong    guid = m_UserGuid.Value;
                var      id   = m_ItemId.Value;
                UserInfo ui   = userThread.GetUserInfo(guid);
                if (null != ui)
                {
                    if (id.Type == BoxedValue.c_ULongType)
                    {
                        ulong itemGuid = id.Get <ulong>();
                        ui.ItemBag.DelItemData(itemGuid);
                    }
                    else
                    {
                        try {
                            int itemId = id.Get <int>();
                            ui.ItemBag.DelItemData(itemId);
                        } catch {
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 10
0
        /// <summary author="Austin Delaney" Created="2019/04/15">
        /// Returns a UserThread object that matches the requested ID and userName is listed as a participant in the thread.
        /// If no such object previously exists, it will create one with default values and add it to the repo.
        /// </summary>
        /// <param name="threadID">Thread to retrieve.</param>
        /// <param name="userName">Name of the user viewing it.</param>
        /// <returns>Full UserThread object of the thread as viewed by the user.</returns>
        public UserThread GetUserThreadData(int threadID, string userName)
        {
            var thread = FindThread(threadID).FirstOrDefault(t => t.Alias == userName);

            if (thread == null)
            {
                thread = FindThread(threadID).First(u => GetThreadParticipantEmailAndAlias(u.ThreadID).Select(kp => kp.Key).Contains(userName));

                thread = new UserThread
                {
                    ThreadID = thread.ThreadID,
                    ParticipantsWithAlias = thread.ParticipantsWithAlias,
                    Messages       = thread.Messages,
                    Alias          = userName,
                    HasNewMessages = true,
                    Archived       = thread.Archived,
                    Hidden         = false,
                    Silenced       = false
                };

                mockThreadRepo.Add(thread);
            }

            return(thread);
        }
Esempio n. 11
0
        private void TryUpdateValue(StoryInstance instance)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                if (m_Key.HaveValue && m_Type.HaveValue)
                {
                    string key  = m_Key.Value;
                    string type = m_Type.Value;
                    m_HaveValue = true;
                    if (type == "int")
                    {
                        m_Value = GlobalData.Instance.GetInt(key);
                    }
                    else if (type == "float")
                    {
                        m_Value = GlobalData.Instance.GetFloat(key);
                    }
                    else
                    {
                        m_Value = GlobalData.Instance.GetStr(key);
                    }
                }
            }
        }
Esempio n. 12
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                ulong    guid = m_UserGuid.Value;
                string   key  = m_Key.Value;
                string   type = m_Type.Value;
                UserInfo ui   = userThread.GetUserInfo(guid);
                if (null != ui)
                {
                    if (type == "int")
                    {
                        ui.IntDatas.Remove(key);
                    }
                    else if (type == "float")
                    {
                        ui.FloatDatas.Remove(key);
                    }
                    else
                    {
                        ui.StringDatas.Remove(key);
                    }
                }
            }
            return(false);
        }
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                ulong     userGuid = m_UserGuid.Value;
                string    dictId   = m_DictId.Value;
                ArrayList arglist  = new ArrayList();
                for (int i = 0; i < m_DictArgs.Count; ++i)
                {
                    IStoryValue val = m_DictArgs[i];
                    arglist.Add(val.Value);
                }
                object[] args = arglist.ToArray();

                Msg_LC_HighlightPrompt builder = new Msg_LC_HighlightPrompt();
                builder.dict_id = dictId;
                foreach (object arg in args)
                {
                    builder.argument.Add(arg.ToString());
                }
                if (userGuid > 0)
                {
                    userThread.NotifyUser(userGuid, LobbyMessageDefine.Msg_LC_HighlightPrompt, builder);
                }
                else
                {
                    userThread.NotifyAllUser(LobbyMessageDefine.Msg_LC_HighlightPrompt, builder);
                }
            }
            return(false);
        }
        private void TryUpdateValue(StoryInstance instance)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                if (m_UserGuid.HaveValue && m_Index.HaveValue)
                {
                    ulong userGuid = m_UserGuid.Value;
                    var   id       = m_Index.Value;
                    m_HaveValue = true;
                    UserInfo ui = userThread.GetUserInfo(userGuid);
                    if (null != ui)
                    {
                        if (id.Type == BoxedValue.c_ULongType)
                        {
                            ulong guid = id.Get <ulong>();
                            m_Value = BoxedValue.From(ui.ItemBag.GetItemData(guid));
                        }
                        else
                        {
                            try {
                                int itemId = id.Get <int>();
                                m_Value = BoxedValue.From(ui.ItemBag.GetItemData(itemId));
                            } catch {
                                m_Value = BoxedValue.NullObject;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 15
0
        protected override void stopGameHandler(UserThread client, CSMessage msg)
        {
            try
            {
                ServerThread cl1 = (ServerThread)client;
                if (cl1.playing())
                {
                    ServerThread cl2 = cl1.CurrentChallenger;
                    if (cl2.playing())
                    {
                        msg.add(MessageType.USER, cl1.ClientUser);
                        cl2.send(msg);
                    }
                    cl2.CurrentChallenger = null;
                    cl1.CurrentChallenger = null;
                    if (view != null && view.isOpened())
                    {
                        view.removeParty(cl1.ClientUser, cl2.ClientUser);
                    }

                    broadcast();
                }
            }
            catch (Exception e)
            {
                log(Severiry.ERROR, "Controller[STOPGAME] - " + e.Message);
            }
        }
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                string evname = m_EventName.Value;
                string group  = m_Group.Value;

                Msg_LC_PublishEvent msg = new Msg_LC_PublishEvent();
                msg.group          = group;
                msg.ev_name        = evname;
                msg.is_logic_event = false;

                for (int i = 0; i < m_Args.Count; ++i)
                {
                    IStoryValue val = m_Args[i];
                    object      v   = val.Value;
                    if (null == v)
                    {
                        Msg_LC_PublishEvent.EventArg arg = new Msg_LC_PublishEvent.EventArg();
                        arg.val_type = LobbyArgType.NULL;
                        arg.str_val  = "";
                        msg.args.Add(arg);
                    }
                    else if (v is int)
                    {
                        Msg_LC_PublishEvent.EventArg arg = new Msg_LC_PublishEvent.EventArg();
                        arg.val_type = LobbyArgType.INT;
                        arg.str_val  = ((int)v).ToString();
                        msg.args.Add(arg);
                    }
                    else if (v is float)
                    {
                        Msg_LC_PublishEvent.EventArg arg = new Msg_LC_PublishEvent.EventArg();
                        arg.val_type = LobbyArgType.FLOAT;
                        arg.str_val  = ((float)v).ToString();
                        msg.args.Add(arg);
                    }
                    else
                    {
                        Msg_LC_PublishEvent.EventArg arg = new Msg_LC_PublishEvent.EventArg();
                        arg.val_type = LobbyArgType.STRING;
                        arg.str_val  = v.ToString();
                        msg.args.Add(arg);
                    }
                }
                if (m_HaveUserGuid)
                {
                    ulong userGuid = m_UserGuid.Value;
                    userThread.NotifyUser(userGuid, LobbyMessageDefine.Msg_LC_PublishEvent, msg);
                }
                else
                {
                    userThread.NotifyAllUser(LobbyMessageDefine.Msg_LC_PublishEvent, msg);
                }
            }
            return(false);
        }
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                string objname = m_ObjTag.Value;
                string _msg    = m_Msg.Value;

                Msg_LC_SendGfxMessage msg = new Msg_LC_SendGfxMessage();
                msg.is_with_tag = true;
                msg.name        = objname;
                msg.msg         = _msg;

                for (int i = 0; i < m_Args.Count; ++i)
                {
                    IStoryValue val = m_Args[i];
                    object      v   = val.Value;
                    if (null == v)
                    {
                        Msg_LC_SendGfxMessage.EventArg arg = new Msg_LC_SendGfxMessage.EventArg();
                        arg.val_type = LobbyArgType.NULL;
                        arg.str_val  = "";
                        msg.args.Add(arg);
                    }
                    else if (v is int)
                    {
                        Msg_LC_SendGfxMessage.EventArg arg = new Msg_LC_SendGfxMessage.EventArg();
                        arg.val_type = LobbyArgType.INT;
                        arg.str_val  = ((int)v).ToString();
                        msg.args.Add(arg);
                    }
                    else if (v is float)
                    {
                        Msg_LC_SendGfxMessage.EventArg arg = new Msg_LC_SendGfxMessage.EventArg();
                        arg.val_type = LobbyArgType.FLOAT;
                        arg.str_val  = ((float)v).ToString();
                        msg.args.Add(arg);
                    }
                    else
                    {
                        Msg_LC_SendGfxMessage.EventArg arg = new Msg_LC_SendGfxMessage.EventArg();
                        arg.val_type = LobbyArgType.STRING;
                        arg.str_val  = v.ToString();
                        msg.args.Add(arg);
                    }
                }
                if (m_HaveUserGuid)
                {
                    ulong userGuid = m_UserGuid.Value;
                    userThread.NotifyUser(userGuid, LobbyMessageDefine.Msg_LC_SendGfxMessage, msg);
                }
                else
                {
                    userThread.NotifyAllUser(LobbyMessageDefine.Msg_LC_SendGfxMessage, msg);
                }
            }
            return(false);
        }
Esempio n. 18
0
 protected override void deconnectionHandler(UserThread client)
 {
     if (view.isOpened())
     {
         view.deconnectionHandler();
         log(Severiry.WARNING, "Server stopped");
     }
 }
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                string _msg = m_Msg.Value;

                Msg_LRL_StoryMessage msg = new Msg_LRL_StoryMessage();
                msg.MsgId = _msg;

                for (int i = 0; i < m_Args.Count; ++i)
                {
                    IStoryValue val = m_Args[i];
                    object      v   = val.Value;
                    if (null == v)
                    {
                        Msg_LRL_StoryMessage.MessageArg arg = new Msg_LRL_StoryMessage.MessageArg();
                        arg.val_type = Msg_LRL_StoryMessage.ArgType.NULL;
                        arg.str_val  = "";
                        msg.Args.Add(arg);
                    }
                    else if (v is int)
                    {
                        Msg_LRL_StoryMessage.MessageArg arg = new Msg_LRL_StoryMessage.MessageArg();
                        arg.val_type = Msg_LRL_StoryMessage.ArgType.INT;
                        arg.str_val  = ((int)v).ToString();
                        msg.Args.Add(arg);
                    }
                    else if (v is float)
                    {
                        Msg_LRL_StoryMessage.MessageArg arg = new Msg_LRL_StoryMessage.MessageArg();
                        arg.val_type = Msg_LRL_StoryMessage.ArgType.FLOAT;
                        arg.str_val  = ((float)v).ToString();
                        msg.Args.Add(arg);
                    }
                    else
                    {
                        Msg_LRL_StoryMessage.MessageArg arg = new Msg_LRL_StoryMessage.MessageArg();
                        arg.val_type = Msg_LRL_StoryMessage.ArgType.STRING;
                        arg.str_val  = v.ToString();
                        msg.Args.Add(arg);
                    }
                }
                if (m_HaveUserGuid)
                {
                    ulong userGuid = m_UserGuid.Value;
                    msg.UserGuid = userGuid;
                    userThread.SendServerMessage(msg);
                }
                else
                {
                    userThread.SendServerMessage(msg);
                }
            }
            return(false);
        }
Esempio n. 20
0
 //Запуск потоков
 public void StartThreads()
 {
     StartLog("Запуск потоков").Run(() =>
     {
         ReadThread.StartProcess();
         UserThread.StartProcess();
         ArchiveThread.StartProcess();
     });
 }
Esempio n. 21
0
 //Останов потоков
 public void StopThreads()
 {
     StartLog("Остановка потоков").Run(() =>
     {
         ReadThread.StopProcess();
         UserThread.StartProcess();
         ArchiveThread.StartProcess();
     });
 }
Esempio n. 22
0
        public static string ReceiveRequest(UserThread thread, string request)
        {
            AbstractQuery query = QueryFactory.GetQueryFactory().GetQuery(new XmlMessage(request), thread);

            Console.WriteLine(thread.username);
            query.ValidateParameters();
            query.Execute();
            return(query.GetResult());
        }
Esempio n. 23
0
        protected override bool ExecCommand(StoryInstance instance, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                ulong    guid = m_UserGuid.Value;
                string   key  = m_Key.Value;
                object   val  = m_Value.Value;
                UserInfo ui   = userThread.GetUserInfo(guid);
                if (null != ui)
                {
                    if (val is int)
                    {
                        int v = (int)val;
                        if (ui.IntDatas.ContainsKey(key))
                        {
                            ui.IntDatas[key] = v;
                        }
                        else
                        {
                            ui.IntDatas.Add(key, v);
                        }
                    }
                    else if (val is float)
                    {
                        float v = (float)val;
                        if (ui.FloatDatas.ContainsKey(key))
                        {
                            ui.FloatDatas[key] = v;
                        }
                        else
                        {
                            ui.FloatDatas.Add(key, v);
                        }
                    }
                    else
                    {
                        string v = val as string;
                        if (null == v)
                        {
                            v = string.Empty;
                        }
                        if (ui.StringDatas.ContainsKey(key))
                        {
                            ui.StringDatas[key] = v;
                        }
                        else
                        {
                            ui.StringDatas.Add(key, v);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 24
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                ulong    guid = m_UserGuid.Value;
                string   key  = m_Key.Value;
                var      val  = m_Value.Value;
                UserInfo ui   = userThread.GetUserInfo(guid);
                if (null != ui)
                {
                    if (val.IsInteger)
                    {
                        int v = val.Get <int>();
                        if (ui.IntDatas.ContainsKey(key))
                        {
                            ui.IntDatas[key] = v;
                        }
                        else
                        {
                            ui.IntDatas.Add(key, v);
                        }
                    }
                    else if (val.IsFloat)
                    {
                        float v = val.Get <float>();
                        if (ui.FloatDatas.ContainsKey(key))
                        {
                            ui.FloatDatas[key] = v;
                        }
                        else
                        {
                            ui.FloatDatas.Add(key, v);
                        }
                    }
                    else
                    {
                        string v = val.StringVal;
                        if (null == v)
                        {
                            v = string.Empty;
                        }
                        if (ui.StringDatas.ContainsKey(key))
                        {
                            ui.StringDatas[key] = v;
                        }
                        else
                        {
                            ui.StringDatas.Add(key, v);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 25
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                GlobalData.Instance.Clear();
            }
            return(false);
        }
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                userThread.QueueAction(userThread.StorySystem.StartStory, m_StoryId.Value);
            }
            return(false);
        }
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                userThread.StorySystem.MarkStoryTerminated(m_StoryId.Value);
            }
            return(false);
        }
Esempio n. 28
0
        private XmlNode GetUserThread(UserThread userThread, XmlDocument xml)
        {
            XmlElement userThreadNode = xml.CreateElement("userThread");

            userThreadNode.AppendChild(xml.CreateElement("threadId")).InnerText = userThread.ThreadId.ToString();

            userThreadNode.AppendChild(xml.CreateElement("lastSeen")).InnerText = userThread.LastSeen.ToString();

            return(userThreadNode);
        }
Esempio n. 29
0
        protected override bool ExecCommand(StoryInstance instance, StoryMessageHandler handler, long delta)
        {
            UserThread userThread = instance.Context as UserThread;

            if (null != userThread)
            {
                ulong guid = m_UserGuid.Value;
                userThread.SyncItems(guid);
            }
            return(false);
        }
Esempio n. 30
0
        /// <summary>
        /// On create instance of User
        /// </summary>
        partial void OnCreated()
        {
            // Start the async control.
            _asyncAccount                = new Nequeo.Threading.AsyncExecutionHandler <User>();
            _asyncAccount.AsyncError    += new Threading.EventHandler <Exception>(_asyncAccount_AsyncError);
            _asyncAccount.AsyncComplete += new Threading.EventHandler <object, string>(_asyncAccount_AsyncComplete);
            _asyncAccount.InitiliseAsyncInstance(this);

            _threadUserContext             = new UserThread(this);
            _threadUserContext.AsyncError += new Threading.EventHandler <Exception>(_asyncAccount_AsyncError);
        }
 internal void Init(UserThread userThread)
 {
     StaticInit();
       m_CurUserThread = userThread;
 }