public CakeServer(string cakeType, string id, string iid = "")
            : base(cakeType, id, iid)
        {
            var bCached = Init();

            if (!bCached)
            {
                var res = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname)
                          .FindOneData(cakeType
                                       , ADBAccessor.filter_eq(ParamNameDefs.CollectionID, string.IsNullOrEmpty(iid) ? ObjectId.Parse(id) : ObjectId.Parse(iid)));
                if (res == null)
                {
                    var ct = ApiDateTime.SecondsFromBegin();
                    ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname)
                    .UpdateOneData(cakeType
                                   , ADBAccessor.filter_eq(ParamNameDefs.CollectionID, string.IsNullOrEmpty(iid) ? ObjectId.Parse(id) : ObjectId.Parse(iid))
                                   , ADBAccessor.update(ParamNameDefs.CreateTime, ct), true);
                    SetValue(ParamNameDefs.CreateTime, ct.ToString());
                }
                else
                {
                    foreach (var item in res.Names)
                    {
                        SetValue(item, res[item].ToString());
                    }
                }
            }
            bInited = true;
        }
        private void GameHandler_DailyCheckRequest(IResponer responer, PktDailyCheckRequest vo)
        {
            var player = APlayerManager.Instance.OnGetPlayerByConn(responer.playerConnDesc);

            if (player == null)
            {
                return;
            }
            var pinfo = new CakeAvatar(player.psid);

            if (ApiDateTime.IsSameDay(pinfo.GetIntValue(ParamNameDefs.LastDailyCheckTime)))
            {
                return;
            }
            var count = pinfo.GetIntValue(ParamNameDefs.DailyCheckCount);
            var data  = DailyCheckLoader.Instance.OnGetData(count + 1);

            if (data == null)
            {
                count = 1;
                data  = DailyCheckLoader.Instance.OnGetData(count);
            }
            SCommonds.AddItem("dailycheck", player.psid, data.itemID, data.itemCount);
            pinfo.SetValue(ParamNameDefs.LastDailyCheckTime, ApiDateTime.SecondsFromBegin());
            var pkt = new PktDailyCheckResult();

            pkt.eResult = PktDailyCheckResult.EResult.Success;
            pkt.lItems.Add(new Int2()
            {
                int1 = data.itemID, int2 = data.itemCount
            });
            responer.Response(pkt);
        }
    public static ChatMessage OnAddChatHistory(string senderUsername, string targetUsername, string type, string content, string head)
    {
        var time = ApiDateTime.SecondsFromBegin();

        var cm = new ChatMessage();

        cm.s  = senderUsername;
        cm.t  = targetUsername;
        cm.tp = typeParser.intParse(type);
        cm.c  = content;
        cm.tm = time;
        cm.h  = typeParser.intParse(head);

        AWebServices.Avatar.dbavatar.UpdateOneData(TableChat
                                                   , ADBAccessor.filter_eq(InfoNameDefs.SenderName, cm.s)
                                                   & ADBAccessor.filter_eq(InfoNameDefs.TargetName, cm.t)
                                                   & ADBAccessor.filter_eq(InfoNameDefs.SendTime, cm.tm)
                                                   & ADBAccessor.filter_eq(InfoNameDefs.SendContent, cm.c)
                                                   , ADBAccessor.updates_build(
                                                       ADBAccessor.update(InfoNameDefs.SendTime, cm.tm)
                                                       , ADBAccessor.update(InfoNameDefs.SenderName, cm.s)
                                                       , ADBAccessor.update(InfoNameDefs.TargetName, cm.t)
                                                       , ADBAccessor.update(InfoNameDefs.ChatType, cm.tp)
                                                       , ADBAccessor.update(InfoNameDefs.SendTime, cm.tm)
                                                       , ADBAccessor.update(InfoNameDefs.SendContent, cm.c)
                                                       )
                                                   , true);
        return(cm);
    }
Exemple #4
0
        protected override bool Init()
        {
            var bCached = base.Init();

            bInited = true;
            if (!IsMulti)
            {
                if (!bCached)
                {
                    var filter = ADBAccessor.filter_eq(ParamNameDefs.CollectionID, ObjectId.Parse(id));
                    var res    = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname)
                                 .FindOneData(cakeType
                                              , filter);
                    if (res == null)
                    {
                        var ct = ApiDateTime.SecondsFromBegin();
                        ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname)
                        .UpdateOneData(cakeType, filter
                                       , ADBAccessor.update(ParamNameDefs.CreateTime, ct), true);
                    }
                    else
                    {
                        foreach (var item in res.Names)
                        {
                            if (item == ParamNameDefs.CollectionID)
                            {
                                continue;
                            }
                            SetValue(item, res[item].ToString());
                        }
                    }
                }
                return(bCached);
            }
            else if (string.IsNullOrEmpty(iid))
            {
                if (!bCached)
                {
                    var filter = ADBAccessor.filter_eq(ParamNameDefs.OwnerID, id);
                    var res    = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname)
                                 .FindManyData(cakeType, filter);
                    foreach (var r in res)
                    {
                        var cid   = r[ParamNameDefs.ContentID].ToString();
                        var cakes = new CakeServer(cakeType, id);
                        var cake  = cakes.GetSingleItem(cid);
                        foreach (var item in r.Names)
                        {
                            if (item == ParamNameDefs.CollectionID)
                            {
                                continue;
                            }
                            cake.SetValue(item, r[item].ToString());
                        }
                        subCakes.Add(cid, cake);
                    }
                }
            }
            return(bCached);
        }
Exemple #5
0
    public WWW OnDownloadText(string resource, Action <string> downloadedAction, Action <string> errorAction = null)
    {
        if (!Environment.UseAB)
        {
            return(null);
        }
        var url = Utils.BaseURL_Res + resource + $".txt?{ApiDateTime.SecondsFromBegin()}";
        var www = new WWW(url);

        addUpdateAction(() =>
        {
            if (www.isDone)
            {
                if (string.IsNullOrEmpty(www.error))
                {
                    lDownloaded.Add(resource);
                    downloadedAction?.Invoke(www.text);
                }
                else
                {
                    UDebugHotLog.Log($"OnDownloadText {www.url} error {www.error}");
                    errorAction?.Invoke(www.error);
                }
                return(true);
            }
            return(false);
        });
        return(www);
    }
    internal string GameHandler_Move(string arg)
    {
        if (LastMoveTime > 0 &&
            LastMoveTime >= ApiDateTime.SecondsFromBegin())
        {
            return(AWebServerUtils.OnGetJsonError(ErrorDefs.MoveInCold));
        }
        switch (arg)
        {
        case "up":
            if (!CheckCanMoveTo(0, -1))
            {
                return(AWebServerUtils.OnGetJsonError(ErrorDefs.InvalidMove));
            }
            MapY--;
            break;

        case "down":
            if (!CheckCanMoveTo(0, 1))
            {
                return(AWebServerUtils.OnGetJsonError(ErrorDefs.InvalidMove));
            }
            MapY++;
            break;

        case "left":
            if (!CheckCanMoveTo(-1))
            {
                return(AWebServerUtils.OnGetJsonError(ErrorDefs.InvalidMove));
            }
            MapX--;
            break;

        case "right":
            if (!CheckCanMoveTo(1))
            {
                return(AWebServerUtils.OnGetJsonError(ErrorDefs.InvalidMove));
            }
            MapX++;
            break;
        }
        LastMoveTime = ApiDateTime.SecondsFromBegin();

        var l = new List <string>();

        l.AddRange(new string[] { InfoNameDefs.MapX, MapX.ToString()
                                  , InfoNameDefs.MapY, MapY.ToString()
                                  , InfoNameDefs.LastMoveTime, LastMoveTime.ToString() });
        var monster = AMapManager.Instance.OnGetMonster(MapX, MapY);

        if (monster != null)
        {
            l.Add("m");
            l.Add(JsonConvert.SerializeObject(monster));
        }
        return(AWebServerUtils.OnGetJsonError(l.ToArray()));
    }
Exemple #7
0
 internal HttpResponseMessage OnDailyCheck()
 {
     if (ApiDateTime.IsSameDay(LastDailyCheckTime))
     {
         return(ResultToJson.GetErrorJsonResponse(ErrorDefs.DailyChecked));
     }
     LastDailyCheckTime = ApiDateTime.SecondsFromBegin();
     AvatarGold        += 1000;
     return(GetDiryParamResponse());
 }
    IEnumerator DownloadConfig(string configUrl)
    {
        var url = configUrl + "?" + ApiDateTime.SecondsFromBegin();
        var www = new WWW(url);

        yield return(www);

        if (!string.IsNullOrEmpty(www.error))
        {
            if (retried >= retryTime)
            {
                if (delDownloadFailed != null)
                {
                    delDownloadFailed();
                }
            }
            else
            {
                retried++;
                AOutput.Log(url + " error:" + www.error);
                StartCoroutine(DownloadConfig(configUrl));
            }
        }
        else
        {
            var      text   = www.text;
            string[] alines = text.Split(new string[] { "\r", "\n" }, System.StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < alines.Length; i++)
            {
                if (alines[i].StartsWith("#") || alines[i].StartsWith("//"))
                {
                    continue;
                }
                string[] akeyvalue = alines[i].Split(new char[] { '=' }, 2);
                dKeyValue.Add(akeyvalue[0], akeyvalue[1]);
            }

            if (delDownloadComplete != null)
            {
                delDownloadComplete();
            }
            UEventListener.Instance.DispatchEvent(UEvents.DownloadCompleteEvent, true);
        }
        www.Dispose();
    }
Exemple #9
0
 private bool CheckMove(int deltax, int deltay)
 {
     if (deltax == 0)
     {
         var y = UMRemoteAvatarData.data.MapY + deltay;
         if (y > 5 || y < -5)
         {
             return(false);
         }
     }
     else if (deltay == 0)
     {
         var x = UMRemoteAvatarData.data.MapX + deltax;
         if (x > 7 || x < -7)
         {
             return(false);
         }
     }
     return(localLastMoveTime <= ApiDateTime.SecondsFromBegin());
 }
Exemple #10
0
 private bool CheckMove(int deltax, int deltay)
 {
     return(localLastMoveTime <= ApiDateTime.SecondsFromBegin());
 }