// 增加世界历史信息 func addNewWorldMessage(responseObj *responseDataObject.SocketResponseObject) { worldHistoryMessageMutex.Lock() defer worldHistoryMessageMutex.Unlock() worldHistoryMessageList = append(worldHistoryMessageList, responseObj) if len(worldHistoryMessageList) > configBLL.MaxHistoryCount() { worldHistoryMessageList = worldHistoryMessageList[len(worldHistoryMessageList)-configBLL.MaxHistoryCount():] } }
// 加载公会历史消息 func loadUnionHistoryMessage(unionId string) { // 判断是否已经加载过公会的历史消息文件 if ifHasLoaded(unionId) { return } // 判断是否存在文件夹 if !fileUtil.IsDirExists(con_HistoryPath) { return } // 读取公会对应文件内容 bytes, err := fileUtil.ReadFileBytes(filepath.Join(con_HistoryPath, getUnionHistoryMessageFileName(unionId))) if err != nil { // 判断文件是否存在,如果不存在直接返回 if os.IsNotExist(err) { return } panic(fmt.Errorf("加载公会历史消息错误,错误信息为:%s", err)) } // 反序列化文件 messageList := make([]*responseDataObject.SocketResponseObject, 0, configBLL.MaxHistoryCount()) if err = json.Unmarshal(bytes, &messageList); err != nil { panic(fmt.Errorf("反序列化公会历史消息错误,错误信息为:%s", err)) } // 加锁 unionHistoryMessageMutex.Lock() defer unionHistoryMessageMutex.Unlock() // 保存到unionHistoryMessageList中 unionHistoryMessageList[unionId] = messageList }
// 增加公会历史信息 func addNewUnionMessage(unionId string, responseObj *responseDataObject.SocketResponseObject) { unionHistoryMessageMutex.Lock() defer unionHistoryMessageMutex.Unlock() // 如果不存在公会,则初始化信息 var messageList []*responseDataObject.SocketResponseObject var exists bool if messageList, exists = unionHistoryMessageList[unionId]; !exists { messageList = make([]*responseDataObject.SocketResponseObject, 0, configBLL.MaxHistoryCount()) } // 将信息添加到公会列表中 messageList = append(messageList, responseObj) if len(messageList) > configBLL.MaxHistoryCount() { messageList = messageList[len(messageList)-configBLL.MaxHistoryCount():] } // 最后将信息更新回map中 unionHistoryMessageList[unionId] = messageList }