Exemplo n.º 1
0
 private void SaveParam()
 {
     ChangeDataToInfo(m_ProcessInfo, m_ProcessData);
     //load info from local cache
     byte[] obj = ThriftSerialize.Serialize(m_ProcessInfo);
     PlayerManager.Instance.GetCharBaseData().CharDeatail = obj;
 }
Exemplo n.º 2
0
    public void SaveTerrainEditFileList(TerrainEditorDataArray filedata, TerrainEditorData editorData)
    {
        if (null == filedata)
        {
            filedata          = new TerrainEditorDataArray();
            filedata.DataList = new System.Collections.Generic.List <TerrainEditorData>();
        }

        if (null != editorData)
        {
            bool bIsNeedAddNew = true;
            for (int i = 0; i < filedata.DataList.Count; ++i)
            {
                if (filedata.DataList[i].ID == editorData.ID)
                {
                    filedata.DataList[i] = editorData;
                    bIsNeedAddNew        = false;
                    break;
                }
            }
            if (bIsNeedAddNew)
            {
                filedata.DataList.Add(editorData);
            }
        }

        byte[] data = ThriftSerialize.Serialize(filedata);
        FileUtils.WriteByteFile(m_strDataPath, data);
    }
Exemplo n.º 3
0
    public static void MergeEventControlDataMap(ref EventControlDataMap fileDataMap)
    {
        if (fileDataMap == null || fileDataMap.MapFileData == null)
        {
            fileDataMap             = new EventControlDataMap();
            fileDataMap.MapFileData = new Dictionary <int, EventControlData>();
        }
        EventControlDataMap remoteDataMap             = ConfigManager.Instance.GetEventControlDataMap();
        Dictionary <int, EventControlData> remoteData = remoteDataMap.MapFileData;
        Dictionary <int, EventControlData> localData  = fileDataMap.MapFileData;

        foreach (int ID in remoteData.Keys)
        {
            if (localData.ContainsKey(ID))
            {
            }
            else
            {
                localData.Add(ID, remoteData[ID]);
            }
        }

        byte[] data = ThriftSerialize.Serialize(fileDataMap);
        FileUtils.WriteByteFile(GetEventControDataPath(), data);
    }
Exemplo n.º 4
0
 public static void SaveDifficultyControlDataMap(DifficultyControlDataMap fileDataMap, int gameID, DifficultyControlData fileData)
 {
     //Init Data Map
     if (fileDataMap == null || fileDataMap.MapFileData == null)
     {
         fileDataMap             = new DifficultyControlDataMap();
         fileDataMap.MapFileData = new Dictionary <int, DifficultyControlData>();
     }
     //Init Data
     if (fileData == null || fileData.DifficultyConfig == null)
     {
         fileData = new DifficultyControlData();
         fileData.DifficultyConfig = new Dictionary <string, DifficultyConfig>();
     }
     //Save Data
     if (fileDataMap.MapFileData.ContainsKey(gameID))
     {
         fileDataMap.MapFileData[gameID] = fileData;
     }
     else
     {
         fileDataMap.MapFileData.Add(gameID, fileData);
     }
     //Save File
     byte[] data = ThriftSerialize.Serialize(fileDataMap);
     FileUtils.WriteByteFile(GetDifficultyControlDataPath(), data);
 }
Exemplo n.º 5
0
    public void ConvertToByteData()
    {
        try
        {
            string xmlData = FileUtils.ReadStringFile(m_strDataOutputPath + "/" + m_strXmlName);

            if (string.IsNullOrEmpty(xmlData))
            {
                Tip("xml 文件为空");
                return;
            }

            TrunkConfigTable table = new TrunkConfigTable();
            table.TrunkConfigXml = xmlData;

            byte[] data = ThriftSerialize.Serialize(table);
            FileUtils.WriteByteFile(m_strDataOutputPath + "/" + m_strByteName, data);
        }
        catch (Exception e)
        {
            Debug.LogException(e);
            Tip(e.Message);
            throw;
        }
    }
Exemplo n.º 6
0
    public static void DeleteActionEditFile(ActionFileDataArray filedatalist, ActionFileData fileData)
    {
        if (null == filedatalist)
        {
            filedatalist = new ActionFileDataArray();
        }

        if (null == filedatalist.DataList)
        {
            filedatalist.DataList = new List <ActionFileData>();
        }

        for (int i = 0; i < filedatalist.DataList.Count; ++i)
        {
            if (filedatalist.DataList[i].ID == fileData.ID)
            {
                filedatalist.DataList[i] = fileData;
                filedatalist.DataList.RemoveAt(i);
                break;
            }
        }

        byte[] data = ThriftSerialize.Serialize(filedatalist);
        FileUtils.WriteByteFile(GetActionFileDataPath(), data);
    }
Exemplo n.º 7
0
    public static void SaveActionEditFileList(ActionFileDataArray filedatalist, ActionFileData fileData)
    {
        if (null == filedatalist)
        {
            filedatalist = new ActionFileDataArray();
        }

        if (null == filedatalist.DataList)
        {
            filedatalist.DataList = new List <ActionFileData>();
        }

        fileData.TimeStamp = GetTimeStamp();
        bool bIsNeedAddNew = true;

        for (int i = 0; i < filedatalist.DataList.Count; ++i)
        {
            if (filedatalist.DataList[i].ID == fileData.ID)
            {
                filedatalist.DataList[i] = fileData;
                bIsNeedAddNew            = false;
                break;
            }
        }
        if (bIsNeedAddNew)
        {
            filedatalist.DataList.Add(fileData);
        }

        byte[] data = ThriftSerialize.Serialize(filedatalist);
        FileUtils.WriteByteFile(GetActionFileDataPath(), data);
    }
Exemplo n.º 8
0
 public AsyncState DoAsyncTask()
 {
     if (UpdateList == null || UpdateList.Count == 0)
     {
         return(AsyncState.AfterAsync);
     }
     foreach (TBase tbase in UpdateList)
     {
         try
         {
             byte[] bytes = ThriftSerialize.Serialize(tbase);
             if (bytes == null)
             {
                 continue;
             }
             //string sql = string.Format("replace into {0}(id, data) values((@id) ,(@data))");
             //SqliteCommand cmd = SqliteDbAccess.Instance.CreateSqliteCommand();
             //cmd.CommandText = sql;
             //cmd.Parameters.Add(new SqliteParameter("@id", tbase.GetType().FullName));
             //cmd.Parameters.Add(new SqliteParameter("@data", bytes));
             int n = 0;// cmd.ExecuteNonQuery();
             if (n == 0)
             {
                 Debuger.LogError(string.Format("{0} update fail.", tbase.GetType().FullName));
             }
         }
         catch (Exception e)
         {
             Debuger.LogError(e.Message);
         }
     }
     return(AsyncState.AfterAsync);
 }
Exemplo n.º 9
0
    // whether have conflict
    public static bool CombineActionEditFileList(ActionFileDataArray filedatalist, out Dictionary <int, ActionFileData> conflictDataMap)
    {
        // Get Local Data
        Dictionary <int, ActionFileData> localDataMap = new Dictionary <int, ActionFileData>();

        // Conflict Value
        conflictDataMap = new Dictionary <int, ActionFileData>();
        if (filedatalist != null && filedatalist.DataList != null)
        {
            foreach (ActionFileData value in filedatalist.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    Debug.LogWarning("本地Action ID 有冲突!");
                }
            }
        }
        // Get Remote Data
        ActionFileDataArray downloadData = ConfigManager.Instance.GetActionFileDataArray();

        if (downloadData != null && downloadData.DataList != null)
        {
            foreach (ActionFileData value in downloadData.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    if (CheckConflcit(localDataMap[value.ID], value))
                    {
                        conflictDataMap.Add(value.ID, value);
                    }
                }
            }
        }
        // Sycn Data to Local
        if (localDataMap.Count > 0)
        {
            filedatalist          = new ActionFileDataArray();
            filedatalist.DataList = new List <ActionFileData>(localDataMap.Values);
            filedatalist.DataList.Sort(SortFileByID);
            byte[] data = ThriftSerialize.Serialize(filedatalist);
            FileUtils.WriteByteFile(GetActionFileDataPath(), data);
        }
        // return
        if (conflictDataMap.Count > 0)
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 10
0
    public static void BackupEditFileList(string path)
    {
        ActionFileDataArray filedatalist = ConfigManager.Instance.GetActionFileDataArray();

        if (filedatalist != null && filedatalist.DataList != null)
        {
            filedatalist.DataList.Sort(SortFileByID);
            byte[] data = ThriftSerialize.Serialize(filedatalist);
            FileUtils.WriteByteFile(path + "actionConfig_txtpkg.bytes", data);
        }
    }
Exemplo n.º 11
0
 public static void ReplaceEditFileList(ActionFileDataArray filedatalist)
 {
     filedatalist = ConfigManager.Instance.GetActionFileDataArray();
     if (filedatalist != null && filedatalist.DataList != null)
     {
         Debug.LogWarning("本地所有文件被掩盖");
         filedatalist.DataList.Sort(SortFileByID);
         byte[] data = ThriftSerialize.Serialize(filedatalist);
         FileUtils.WriteByteFile(GetActionFileDataPath(), data);
     }
 }
Exemplo n.º 12
0
    public static void SyncActionEditFileList(ActionFileDataArray filedatalist)
    {
        // Get Local Data
        Dictionary <int, ActionFileData> localDataMap = new Dictionary <int, ActionFileData>();

        if (filedatalist != null && filedatalist.DataList != null)
        {
            foreach (ActionFileData value in filedatalist.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    Debug.LogWarning("本地Action ID 有冲突!");
                }
            }
        }
        // Get Remote Data
        ActionFileDataArray downloadData = ConfigManager.Instance.GetActionFileDataArray();

        if (downloadData != null && downloadData.DataList != null)
        {
            foreach (ActionFileData value in downloadData.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    if (CheckConflcit(localDataMap[value.ID], value))
                    {
                        localDataMap.Remove(value.ID);
                        localDataMap.Add(value.ID, value);
                        Debug.LogWarning("远程的ActionFile与本地有冲突,本地文件已被覆盖!");
                    }
                }
            }
        }
        // Sycn Data to Local
        if (localDataMap.Count > 0)
        {
            filedatalist          = new ActionFileDataArray();
            filedatalist.DataList = new List <ActionFileData>(localDataMap.Values);
            filedatalist.DataList.Sort(SortFileByID);
            byte[] data = ThriftSerialize.Serialize(filedatalist);
            FileUtils.WriteByteFile(GetActionFileDataPath(), data);
        }
    }
Exemplo n.º 13
0
 public void TrySetConfig(string path, TBase value)
 {
     if (m_ConfigPool.ContainsKey(path))
     {
         m_ConfigPool[path] = value;
     }
     else
     {
         m_ConfigPool.Add(path, value);
     }
     //save to file
     FileUtils.EnsureFolder(GetConfigPath() + path);
     byte[] buffer = ThriftSerialize.Serialize(value);
     FileUtils.WriteByteFile(GetConfigPath() + path, buffer);
 }
Exemplo n.º 14
0
        private byte[] Encode(Header header, TBase message)
        {
            byte[] headerBytes = ThriftSerialize.Serialize(header);

            byte[] messageBytes = ThriftSerialize.Serialize(message);

            ByteBuffer buffer = ByteBuffer.Allocate(512);

            buffer.WriteInt(ThriftMessageHelper.GetMessageId(message));
            buffer.WriteInt(headerBytes.Length);
            buffer.WriteBytes(headerBytes);
            buffer.WriteInt(messageBytes.Length);
            buffer.WriteBytes(messageBytes);

            return(buffer.ToArray());
        }
Exemplo n.º 15
0
    private void UpdateTerrainConfig()
    {
        TerrainEditorDataArray newList = new TerrainEditorDataArray();

        newList.DataList = new List <TerrainEditorData>();

        TerrainEditorDataArray remoteConfig = ConfigManager.Instance.GetTerrainEditorDataArray();
        TerrainEditorDataArray localConfig  = GetTerrainEditFileList();

        if (null == remoteConfig || remoteConfig.DataList == null || remoteConfig.DataList.Count == 0)
        {
            return;
        }

        if (remoteConfig != null || remoteConfig.DataList != null)
        {
            foreach (var elemRemote in remoteConfig.DataList)
            {
                //add remote
                newList.DataList.Add(elemRemote);
            }
        }

        if (null != localConfig && null != localConfig.DataList)
        {
            foreach (var elemLocal in localConfig.DataList)
            {
                bool isExistInRemote = false;
                foreach (var elemRemote in remoteConfig.DataList)
                {
                    if (elemLocal.ID == elemRemote.ID)
                    {
                        isExistInRemote = true;
                        break;
                    }
                }
                if (!isExistInRemote)
                {
                    //add local
                    newList.DataList.Add(elemLocal);
                }
            }
        }

        byte[] data = ThriftSerialize.Serialize(newList);
        FileUtils.WriteByteFile(m_strDataPath, data);
    }
Exemplo n.º 16
0
    public void EncodeGamePackage(object messageBody)
    {
        try
        {
            // clear send buffer
            ResetSendBuffer();

            //
            int messageId = 0;
            if (!m_MessageMapTypeToId.TryGetValue(messageBody.GetType(), out messageId))
            {
                Debug.LogError("Can't encode message " + messageId);
                return;
            }

            // push message id
            Array.Copy(ByteArrayUtil.intToBytes(messageId), 0, m_SendBuffer, m_SendBufferSize, 4);
            m_SendBufferSize += 4;

            // push prefix
            m_SendBufferSize += 4;

            //push header (default length = 0,body = null)
            Array.Copy(ByteArrayUtil.shortToByteArray(0), 0, m_SendBuffer, m_SendBufferSize, 2);
            m_SendBufferSize += 2;

            // push message body length
            TBase  Message     = messageBody as TBase;
            byte[] tmpSendBody = ThriftSerialize.Serialize(Message);
            Array.Copy(ByteArrayUtil.intToBytes(tmpSendBody.Length), 0, m_SendBuffer, m_SendBufferSize, 4);
            m_SendBufferSize += 4;

            Array.Copy(tmpSendBody, 0, m_SendBuffer, m_SendBufferSize, tmpSendBody.Length);
            m_SendBufferSize += tmpSendBody.Length;

            Debug.Log("Send msg:" + messageBody.ToString());
        }
        catch (Exception e)
        {
            Debug.LogError("Error on encode game package ");
            Debug.LogException(e);
        }
    }
Exemplo n.º 17
0
    public static void MergeActionEditFileList(ActionFileDataArray filedatalist, Dictionary <int, ActionFileData> conflictDataMap)
    {
        // Get Local Data
        Dictionary <int, ActionFileData> localDataMap = new Dictionary <int, ActionFileData>();

        if (filedatalist != null && filedatalist.DataList != null)
        {
            foreach (ActionFileData value in filedatalist.DataList)
            {
                if (!localDataMap.ContainsKey(value.ID))
                {
                    localDataMap.Add(value.ID, value);
                }
                else
                {
                    Debug.LogWarning("本地Action ID 有冲突!");
                }
            }
        }
        // Merge Data
        if (conflictDataMap != null)
        {
            foreach (int key in conflictDataMap.Keys)
            {
                if (localDataMap.ContainsKey(key))
                {
                    localDataMap.Remove(key);
                    localDataMap.Add(key, conflictDataMap[key]);
                    Debug.LogWarning("冲突解决,本地文件 : " + key.ToString() + " 已被覆盖!");
                }
            }
        }
        // Sycn Data to Local
        if (localDataMap.Count > 0)
        {
            filedatalist          = new ActionFileDataArray();
            filedatalist.DataList = new List <ActionFileData>(localDataMap.Values);
            filedatalist.DataList.Sort(SortFileByID);
            byte[] data = ThriftSerialize.Serialize(filedatalist);
            FileUtils.WriteByteFile(GetActionFileDataPath(), data);
        }
    }
        public void Encode(NetWork.ByteBuffer buffer, object value)
        {
            CharacterDataSnapshot data = value as CharacterDataSnapshot;

            buffer.WriteByte(FLAG_VERSION);
            buffer.WriteLong(data.Version);
            buffer.WriteByte(FLAG_DATA_LIST);

            int size = data.DataList != null ? data.DataList.Count : 0;

            buffer.WriteShort((short)size);
            if (size > 0)
            {
                foreach (TBase tbase in data.DataList)
                {
                    buffer.WriteString(tbase.GetType().FullName);
                    byte[] tbaseBytes = ThriftSerialize.Serialize(tbase);
                    buffer.WriteInt(tbaseBytes.Length);
                    buffer.WriteBytes(tbaseBytes);
                }
            }

            buffer.WriteByte(FLAG_END);
        }
Exemplo n.º 19
0
 public static void SaveData(TBase data, string savePath)
 {
     byte[] fileData = ThriftSerialize.Serialize(data);
     FileUtils.WriteByteFile(savePath, fileData);
 }
Exemplo n.º 20
0
 //Save Data
 public static void SaveDefaultUserTalentMap(DefaultUserTalent fileDataMap)
 {
     byte[] data = ThriftSerialize.Serialize(fileDataMap);
     FileUtils.WriteByteFile(GetDefaultUserTalentDataPath(), data);
 }