def updateCharteLevel(characterid,level): '''角色等级同步 @param characterid: int 角色id @param level: int 等级 ''' chater=ChaterManager().addChaterByid(characterid) chater.level=level
def pushChatToObjectList(id,tid): '''推送私聊角色列表''' from app.chatServer.core.ChaterManager import ChaterManager from app.chatServer.core.ChaterLogManager import ChaterLogManager response=ChatToObjectListInfo1010_pb2.ChatToObjectListResponse() clog=ChaterLogManager().addChatLog(id)#获取聊天类 listid=clog.getFriends()#获取角色私聊对象id列表 if len(listid)<0: return gamer=ChaterManager().getChaterByCharacterId(id) if not gamer: return gamerid=gamer.getDynamicId() for cid in listid: gamer1=ChaterManager().getChaterByCharacterId(cid) info=response.chatObjectInfo.add() info.chatObjectId=cid info.name=gamer1.getCharacterName() info.level=str(gamer1.level) if gamer1.island: info.chatObjectPos=gamer1.scenename else: info.chatObjectPos=lg().g(106) info.readFlag=ChaterLogManager().getFriendReaderState(id,cid) msg=response.SerializeToString() pushApplyMessage(1010,msg,[gamer1])
def senGuildCement(msg, targetList=[]): '''发送错误提示''' for k in ChaterManager()._chaters: targetId = ChaterManager()._chaters[k].dynamicId targetList.append(targetId) pushChatMessage(7, -1, Lg().g(128), 0, msg, [], targetList)
def sendAnnouncement(msg): '''发送系统公告''' targetList = [] for k in ChaterManager()._chaters: targetId = ChaterManager()._chaters[k].dynamicId targetList.append(targetId) pushChatMessage(7, -1, Lg().g(128), 0, msg, [], targetList)
def getLog(self, id, tid): """获取聊天记录 @param id: int 当前角色id @param tid: int 私聊对象id """ from app.chatServer.core.ChaterManager import ChaterManager clog = self.addChatLog(id) # 获取或添加私聊类 result = clog.getChat(tid) # 获取私聊信息 clog.delReaderList(tid) # 在未读信息列表中删除此角色id相应数据 clog.addFriends(tid) # 添加私聊最近联系人 clog.setReading(tid) # 设置当前跟谁聊天 data = {} players = ChaterManager().getChaterByCharacterId(tid) data["name"] = players.charactername data["level"] = str(players.level) data["perfession"] = players.getProfessionName() if not players.island: # 如果角色不在线 data["chatObjectPos"] = Lg().g(106) else: data["chatObjectPos"] = players.scenename data["result"] = result return data
def SendChatMessageRequest_1013(dynamicId,request_proto): '''当前角色发送私聊信息''' import time from app.chatServer.core.ChaterManager import ChaterManager argument=SendChatMessage1013_pb2.SendChatMessageRequest() argument.ParseFromString(request_proto) response=SendChatMessage1013_pb2.SendChatMessageResponse() id=argument.id tid=argument.chatId context=argument.chatMessage chater=ChaterManager().getChaterByCharacterId(id) if chater.donttalk==0:#不禁言 timet=ste(time.strftime('%Y-%m-%d %X')) title="<font color='#ffffff'>" title+=chater.getrCharacterName() title+=":</font><br/>" title+=u"<font color='#ffffff'> %s</font><br/>"%context ChaterLogManager().addLog(id,tid,title,timet) response.result=True response.message=u'' else:#禁言 response.result=True response.message=Lg().g(644) return response.SerializeToString()
def SendChatMessageRequest_1013(dynamicId, request_proto): '''当前角色发送私聊信息''' import time from app.chatServer.core.ChaterManager import ChaterManager argument = SendChatMessage1013_pb2.SendChatMessageRequest() argument.ParseFromString(request_proto) response = SendChatMessage1013_pb2.SendChatMessageResponse() id = argument.id tid = argument.chatId context = argument.chatMessage chater=ChaterManager().getChaterByCharacterId(id) if chater.donttalk==0:#不禁言 timet=str(time.strftime('%Y-%m-%d %X')) title="<font color='#ffffff'>" title+=chater.getCharacterName() title+=":</font><br/>" title+=u"<font color='#ffffff'> %s</font><br/>"%context ChaterLogManager().addLog(id, tid, title,timet) response.result =True response.message =u'' else:#禁言 response.result =True response.message =Lg().g(644) return response.SerializeToString()
def doGmCommand(characterId,content): if content.startswith('\\'): chater = ChaterManager().getChaterByCharacterId(characterId) if chater: roomId = chater.getRoomId() if roomId<5000: childnode = 200000 + roomId # chatroot.callChild(201000,'GmCommand',characterId,content) GlobalObject().root.callChild("scense_1000","GmCommand",characterId,content) return True return False
def doGmCommand(characterId, content): if content.startswith('\\'): chater = ChaterManager().getChaterByCharacterId(characterId) if chater: roomId = chater.getRoomId() if roomId < 5000: childnode = 200000 + roomId GlobalObject().root.callChild("scense_1000", "GmCommand", characterId, content) return True return False
def sendMessage(dynamicId,characterId,topic,content,linkData,tonickname=None): '''发送聊天信息 @param dynamicId: int 客户端的id @param characterId: int 角色的id @param topic: int 频道的编号 @param content: string 发送的消息内容 @param linkData: dict list 连接信息内容 ''' chater = ChaterManager().getChaterByCharacterId(characterId) if not chater: return {'result':False,'message':Lg().g(639)} if topic==7: toplayer=ChaterManager().getChaterByCharacterId(characterId) if not toplayer: return {'result':False,"message":Lg().g(640)} else: topic=toplayer.baseInfo.id targetList = [] chaterName = chater.getCharacterName() profession = chater.getProfession() if topic==1: #世界频道聊天 idlist = ChaterManager().getAlldynamicId() targetList=idlist elif topic==2:#当前 相当于同场景 roomId = chater.getRoomId() targetList = ChatRoomManager().getRoomMember(roomId) elif topic==3:#国 gid=chater.guildid if gid<1: return {'result':False,"message":Lg().g(641)} else: # return {'result':False,"message":u"国聊天功能暂未开放,敬请期待"} # idlist = ChaterManager().getAlldynamicId() # targetList=idlist # content=u"国聊天暂未开放" plist=GuildManager().getdtidListBygid(gid) if plist: targetList=list(plist) # gid=player.guild.getID()#返回行会id # resut=setGuildPlayerDynamicId(gid,targetList) #设置添加targetList,国聊天角色动态id列表,返回是否成功 # if not resut: # return {'result':False,"message":Lg().g(641)} result = doGmCommand(characterId,content) # if not result: pushChatMessage(topic,characterId, chaterName, profession, dbshieldword.replaceIllegalChar(content),linkData, targetList) return {'result':True}
def updateGuild(characterid,guild,tag): '''角色行会同步 @param characterid: int 角色id @param guild: int 行会id @param tag: int 1加入国 0退出国 ''' chater=ChaterManager().addChaterByid(characterid) if tag==1: GuildManager().add(chater.dynamicId, guild) chater.guildid=guild if tag==0: GuildManager().delete(chater.dynamicId, guild) chater.guildid=0
def leaveRoom(characterId): ''' @param characterId: int character id @param roomId: int room id ''' chater = ChaterManager().getChaterByCharacterId(characterId) if not chater: return clientId = chater.getDynamicId() oldroomId = chater.getRoomId() if not oldroomId or clientId < 0: return if oldroomId : ChatRoomManager().leaveRoom(clientId, oldroomId)
def addLog(self, id, tid, context, time): '''添加聊天记录 @param id: int 当前角色id @param tid: int 接受聊天信息对象id @param contxt: int 聊天内容 ''' from app.chatServer.core.ChaterManager import ChaterManager chater = ChaterManager().getChaterByCharacterId(tid) #聊天接收者 dyid = ChaterManager().getChaterByCharacterId(id).dynamicId ftypeid = chater.isf(id) #1好友 2黑名单 0没有关系 if ftypeid == 2: pushObjectNetInterface.pushOtherMessage(905, Lg().g(643), [dyid]) return clog = self.addChatLog(id) #获取或添加私聊类 clog.addFriends(tid) #当前角色添加私聊好友 clog.addChat(tid, context, time) #添加聊天记录 clog1 = self.addChatLog(tid) #获取或添加私聊类(聊天接受者聊天类) clog1.addReaderList(id) #设置聊天接受者有未读信息 clog1.addFriends(id) #聊天接受者角色添加私聊好友 cter = ChaterManager().getChaterByCharacterId(tid) #聊天接收者 sid = clog.getReading() #获取正在聊天角色id if sid == tid: #当前角色正在跟聊天接受者私聊中(并且私聊面板开启中) ct = self.getLogonly(id, tid) pushObjectNetInterface.pushChatToObjectList(id, tid) #推送给聊天发送者,聊天成员列表 if cter.island: #如果聊天接收者在线 pushObjectNetInterface.pushChatToObjectList( tid, id) #推送给聊天发接收者,聊天成员列表 pushObjectNetInterface.pushServerSendChatInfo(id, ct, tid) #推送聊天信息 if clog1.getReading() == id: #如果对方也正在跟我聊天 pushObjectNetInterface.pushServerSendChatInfo(tid, ct, id) #推送聊天信息 clog1.delReaderList(id) # else: # pushObjectNetInterface.pushChatToObjectList(tid, id) #推送给聊天接受者,聊天成员列表 else: # 当前角色正在跟其他角色饲料中(或者私聊面板关闭) pushObjectNetInterface.pushChatToObjectList(id, tid) #推送给聊天发送者,聊天成员列表 if not cter.island: #如果对方已经下线 return pushObjectNetInterface.pushChatToObjectList(tid, id) #推送给聊天接受者,聊天成员列表 # pushObjectNetInterface.pushServerSendChatInfo(id, context) clog.setReading(tid) #设置当前角色正在和tid聊天
def updateDontTalk(characterId, flg): '''更新角色禁言状态 @param characterId:int 角色id @param flg:int 0:不禁言 1:禁言 return 是否成功 True or Flase ''' return ChaterManager().donttalk(characterId, flg)
def updateDontTalk(characterid,flg): '''更爱角色禁言状态 @param characterid: int 角色id @param flg: int 0:不禁言 1禁言 return 是否成功 True or False ''' return ChaterManager().donttalk(characterid, flg)
def pushSystemchat(strInfo): '''推送聊天框系统消息 @param strInfo: str 系统消息内容 ''' sendList = [ chater.getDynamicId() for chater in ChaterManager()._chaters.values() ] pushChatMessage(5, -1, Lg().g(128), 0, strInfo, [], sendList)
def addLog(self, id, tid, context, time): """添加聊天记录 @param id: int 当前角色id @param tid: int 接受聊天信息对象id @param contxt: int 聊天内容 """ from app.chatServer.core.ChaterManager import ChaterManager chater = ChaterManager().getChaterByCharacterId(tid) # 聊天接收者 dyid = ChaterManager().getChaterByCharacterId(id).dynamicId ftypeid = chater.isf(id) # 1好友 2黑名单 0没有关系 if ftypeid == 2: pushObjectNetInterface.pushOtherMessage(905, Lg().g(643), [dyid]) return clog = self.addChatLog(id) # 获取或添加私聊类 clog.addFriends(tid) # 当前角色添加私聊好友 clog.addChat(tid, context, time) # 添加聊天记录 clog1 = self.addChatLog(tid) # 获取或添加私聊类(聊天接受者聊天类) clog1.addReaderList(id) # 设置聊天接受者有未读信息 clog1.addFriends(id) # 聊天接受者角色添加私聊好友 cter = ChaterManager().getChaterByCharacterId(tid) # 聊天接收者 sid = clog.getReading() # 获取正在聊天角色id if sid == tid: # 当前角色正在跟聊天接受者私聊中(并且私聊面板开启中) ct = self.getLogonly(id, tid) pushObjectNetInterface.pushChatToObjectList(id, tid) # 推送给聊天发送者,聊天成员列表 if cter.island: # 如果聊天接收者在线 pushObjectNetInterface.pushChatToObjectList(tid, id) # 推送给聊天发接收者,聊天成员列表 pushObjectNetInterface.pushServerSendChatInfo(id, ct, tid) # 推送聊天信息 if clog1.getReading() == id: # 如果对方也正在跟我聊天 pushObjectNetInterface.pushServerSendChatInfo(tid, ct, id) # 推送聊天信息 clog1.delReaderList(id) # else: # pushObjectNetInterface.pushChatToObjectList(tid, id) #推送给聊天接受者,聊天成员列表 else: # 当前角色正在跟其他角色饲料中(或者私聊面板关闭) pushObjectNetInterface.pushChatToObjectList(id, tid) # 推送给聊天发送者,聊天成员列表 if not cter.island: # 如果对方已经下线 return pushObjectNetInterface.pushChatToObjectList(tid, id) # 推送给聊天接受者,聊天成员列表 # pushObjectNetInterface.pushServerSendChatInfo(id, context) clog.setReading(tid) # 设置当前角色正在和tid聊天
def pushChatToObjectList(id,tid): '''推送私聊角色列表''' from app.chatServer.core.ChaterManager import ChaterManager from app.chatServer.core.ChaterLogManager import ChaterLogManager response=ChatToObjectListInfo1010_pb2.ChatToObjectListResponse() clog=ChaterLogManager().addChatLog(id) #获取聊天类 listid=clog.getFriends()#获取角色私聊对象id列表 if len(listid)<0: return player=ChaterManager().getChaterByCharacterId(id) # player=PlayersManager().getPlayerByID(id) if not player: #print "推送私聊角色列表时没有角色"+str(id) return #print "角色私聊角色列表发送给"+player.baseInfo.getNickName() playerid=player.getDynamicId() for cid in listid: player1=ChaterManager().getChaterByCharacterId(cid) info=response.chatObjectInfo.add() info.chatObjectId=cid info.name=player1.getCharacterName() #print "私聊信息角色列表:"+player1.baseInfo.getNickName() info.level=str(player1.level) info.perfession=player1.getProfessionName() if player1.island: info.chatObjectPos=player1.scenename else: info.chatObjectPos=Lg().g(106) info.readFlag=ChaterLogManager().getFriendReaderState(id, cid) #print "------------------------------------------------------------------" msg = response.SerializeToString() pushApplyMessage(1010,msg,[playerid])
def loginToChatServer(dynamicId, characterId, roomId): '''登录聊天服务器 @param dynamicId:int 客户端的id @param characterId:int int角色的id ''' chater = ChaterManager().addChaterByid(characterId) if chater: ChaterManager().updateOnland(characterId, dynamicId) chater.setRoomId(roomId) ChatRoomManager().joinRoom(dynamicId, roomId) gid = chater.guildid #公会id 没有公会默认0 dtid = chater.dynamicId GuildManager().add(dtid, gid) targetList = [] targetList.append(dynamicId) content = Lg().g(638) pushChatMessage(5, -1, Lg().g(128), content, [], targetList) return {'result': True, 'message': Lg().g(25)}
def loginToChatServer(dynamicId,characterId,roomId): '''登陆聊天服务器 @param dynamicId: int 客户端的id @param characterId: int角色的id ''' chater = ChaterManager().addChaterByid(characterId) if chater: ChaterManager().updateOnland(characterId,dynamicId) chater.setRoomId(roomId) ChatRoomManager().joinRoom( dynamicId, roomId) gid=chater.guildid#行会id 没有行会默认0 dtid=chater.dynamicId GuildManager().add(dtid, gid) targetList = [] targetList.append(dynamicId) content = Lg().g(638) pushChatMessage(5, -1, Lg().g(128), 0, content,[], targetList) return {'result':True,'message':Lg().g(25)}
def sendMessage(dynamicId, characterId, topic, content, linkData, tonickname=None): '''发送聊天信息 @param dynamicId: int 客户端的id @param characterId: int 角色的id @param topic: int 频道的编号 @param content: string 发送的消息内容 @param linkData: dict list 连接信息内容 ''' chater = ChaterManager().getChaterByCharacterId(characterId) if not chater: return {'result': False, 'message': Lg().g(639)} if topic == 7: toplayer = ChaterManager().getChaterByCharacterId(characterId) if not toplayer: return {'result': False, "message": Lg().g(640)} else: topic = toplayer.baseInfo.id targetList = [] chaterName = chater.getCharacterName() profession = chater.getProfession() if topic == 1: #世界频道聊天 idlist = ChaterManager().getAlldynamicId() targetList = idlist elif topic == 2: #当前 相当于同场景 roomId = chater.getRoomId() targetList = ChatRoomManager().getRoomMember(roomId) elif topic == 3: #国 gid = chater.guildid if gid < 1: return {'result': False, "message": Lg().g(641)} else: # return {'result':False,"message":u"国聊天功能暂未开放,敬请期待"} # idlist = ChaterManager().getAlldynamicId() # targetList=idlist # content=u"国聊天暂未开放" plist = GuildManager().getdtidListBygid(gid) if plist: targetList = list(plist) # gid=player.guild.getID()#返回行会id # resut=setGuildPlayerDynamicId(gid,targetList) #设置添加targetList,国聊天角色动态id列表,返回是否成功 # if not resut: # return {'result':False,"message":Lg().g(641)} result = doGmCommand(characterId, content) # if not result: pushChatMessage(topic, characterId, chaterName, profession, dbshieldword.replaceIllegalChar(content), linkData, targetList) return {'result': True}
def setToPlayerDynamicId(characterid, targetList): '''设置私聊成员的动态id-根据接收方角色id 有返回值(True or False) @param characterid: int 接收方角色id ''' inco = ChaterManager().getChaterByCharacterId(characterid) if inco: targetList.append(inco.dynamicId) return True else: return False #{'result':False,"message":Lg().g(640)}
def pushSystemToInfo(strInfo): '''推送系统消息''' response=SystemToInfo2700_pb2.SystemToInfoResponse() try: response.s_info=strInfo except Exception: response.s_info=strInfo.decode('utf8') sendList = [charter.getDynamicId() for charter in ChaterManager()._chaters.values()] data = response.SerializeToString() GlobalObject().netfactory.pushObject(2700 , data, sendList)
def setToPlayerDynamicId(characterId, targetList): '''设置私聊成成员的动态id-根据接收方角色id 有返回值(True or False) @param characterId:int 接收方角色id ''' inco = ChaterManager().getChaterByCharacterId(characterId) if inco: targetList.append(inco.dynamicId) return True else: return False
def sendSysInfomation(msg, dynamicId, linkData=[]): '''发送系统提示消息 @param msg: 发送的聊天信息 @param linkData: 物品的有提示信息 @param dynamicId:角色动态id ''' targetList = [] dynamicId = ChaterManager().getChaterDynamicId if dynamicId: targetList.append(dynamicId) pushChatMessage(5, -1, Lg().g(128), -1, msg, linkData, targetList)
def sendMessage(dynamicId,characterId,topic,content,linkData,tonickname=None): '''发送聊天信息 @param dynamicId:int 客户端的id @param characterId:int 角色的id @param topic :int 频道的编号 @param content:string 发送的消息内容 @param linkData: dict list 连接信息内容 ''' chater=ChaterManager().getChaterByCharacterId(characterId) if not chater: return {'result':False,'message':Lg().g(639)} if topic==7: toplayer=ChaterManager().getChaterByCharacterId(characterId) if not toplayer: return {'result':False,"message":Lg().g(640)} else: topic=toplayer.baseInfo.id targetList=[] chaterName=chater.getCharacterName() if topic==1:#世界聊天 idlist=ChaterManager().getAlldynamicId() targetList=idlist elif topic==2:#当前场景 roomId=chater.getRoomId() targetList=ChatRoomManager().getRoomMember(roomId) elif topic==3:#公会 gid=chater.guildid if gid<1: return {'result':False,"message":Lg().g(641)} else: plist=GuildManager().getdtidListBygid(gid) if plist: targetList=list(plist) result=doGmCommand(characterId,content) pushChatMessage(topic,characterId,chaterName,dbShieldWord.replaceIllegalChar(content),linkData,targetList) return {'result':True}
def pushServerSendChatInfo(id, message, tid): '''推送的私聊信息 @param id: int 私聊对象角色id @param tid: int 私聊对象角色id @param message: str 聊天内容 ''' from app.chatServer.core.ChaterManager import ChaterManager response['id'] = tid response['chatMessage'] = message chater = ChaterManager().getChaterByCharacterId(id) #推送给这个人的角色 dyid = chater.dynamicId pushApplyMessage(1012, json.dumps(response), [dyid])
def zxListxxList(self): '''获取最近联系人中在线列表和不在线列表''' from app.chatServer.core.ChaterManager import ChaterManager zxList = [] #在线最近联系人列表 xxList = [] #下线最近联系人列表 for id in self.friendList: if ChaterManager().getChaterByCharacterId(id).island: #如果在线 zxList.append(id) else: xxList.append(id) self.friendList = zxList + xxList return zxList, xxList
def pushChatToObjectList(id, tid): '''推送私聊角色列表''' from app.chatServer.core.ChaterManager import ChaterManager from app.chatServer.core.ChaterLogManager import ChaterLogManager response = ChatToObjectListInfo1010_pb2.ChatToObjectListResponse() clog = ChaterLogManager().addChatLog(id) #获取聊天类 listid = clog.getFriends() #获取角色私聊对象id列表 if len(listid) < 0: return gamer = ChaterManager().getChaterByCharacterId(id) if not gamer: return gamerid = gamer.getDynamicId() for cid in listid: gamer1 = ChaterManager().getChaterByCharacterId(cid) info = response.chatObjectInfo.add() info.chatObjectId = cid info.name = gamer1.getCharacterName() info.level = str(gamer1.level) if gamer1.island: info.chatObjectPos = gamer1.scenename else: info.chatObjectPos = lg().g(106) info.readFlag = ChaterLogManager().getFriendReaderState(id, cid) msg = response.SerializeToString() pushApplyMessage(1010, msg, [gamer1])
def pushServerSendChatInfo(id,message,tid): '''推送的私聊信息 @param id: int 私聊对象角色id @param tid: int 私聊角色id @param message: str 聊天内容 ''' from app.chatServer.core.ChaterManager import ChaterManager response=ServerSendChatInfo1012_pb2.ServerSendChatInfoResponse() response.id=tid response.chatMessage=message msg=response.SerializeToString() chater=ChaterManager().getChaterByCharacterId(id)#推送给这个人的角色 dyid=chater.dynamicId pushApplyMessage(1012,msg,[dyid])
def setGuildPlayerDynamicId(gid, targetList): '''设置所在公会中在线聊天成员的动态id列表-根据公会id 有返回值(True or False) @param gid: int 公会id @param targetList: [] 存储角色动态id ''' rgetList1 = '' #返回角色Id列表 if len(rgetList1) >= 1: for l in rgetList1: icno = ChaterManager().getChaterByCharacterId(l) if icno: targetList.append(icno.dynamicId) else: return False return True
def addWhitelist(id,tid): ''' @param id: int nowplayerid @param tid: int player id ''' chater=ChaterManager().addChaterByid(id) if tid in chater.whitelist: return elif tid in chater.blacklist: chater.blacklist.remove(tid) chater.whitelist.add(tid) else: chater.whitelist.add(tid)
def getLog(self, id, tid): '''获取聊天记录 @param id: int 当前角色id @param tid: int 私聊对象id ''' from app.chatServer.core.ChaterManager import ChaterManager clog = self.addChatLog(id) #获取或添加私聊类 result = clog.getChat(tid) #获取私聊信息 clog.delReaderList(tid) #在未读信息列表中删除此角色id相应数据 clog.addFriends(tid) #添加私聊最近联系人 clog.setReading(tid) #设置当前跟谁聊天 data = {} players = ChaterManager().getChaterByCharacterId(tid) data['name'] = players.charactername data['level'] = str(players.level) data['perfession'] = players.getProfessionName() if not players.island: #如果角色不在线 data['chatObjectPos'] = Lg().g(106) else: data['chatObjectPos'] = players.scenename data['result'] = result return data
def JoinRoom(characterId,roomId,scenename): ''' @param characterId: int character id @param roomId: int room id ''' chater = ChaterManager().addChaterByid(characterId) if not chater: return clientId = chater.getDynamicId() oldroomId = chater.getRoomId() chater.setSceneName(scenename) if not oldroomId or clientId < 0: return if oldroomId : ChatRoomManager().leaveRoom(clientId, oldroomId) chater.setRoomId(roomId) ChatRoomManager().joinRoom(clientId, roomId)
def zxListxxList(self): '''获取最近联系人中在线列表和不在线列表''' from app.chatServer.core.ChaterManager import ChaterManager zxList = [] #在线最近联系人列表 xxList = [] #下线最近联系人列表 for id in self.friendList: if ChaterManager().getChaterByCharacterId(id).island: #如果在线 zxList.append(id) else: xxList.append(id) self.friendList = zxList + xxList return zxList, xxList def setReading(self, id): '''设置正在跟谁聊天 @param id: int 角色id ''' self.reading = id def getReading(self): '''获取正在跟谁聊天''' return self.reading def getReaderList(self): '''获取未读信息角色id列表''' return self.readerList def addReaderList(self, id): '''设置未读信息 @param id:int 未读信息的角色id ''' from app.chatServer.net import pushObjectNetInterface if not id in self.readerList: self.readerList.append(id) pushObjectNetInterface.pushChatToObjectList(self.id, id) def delReaderList(self, id): '''删除未读信息 @param id: int 未读信息的角色id ''' from app.chatServer.net import pushObjectNetInterface if id in self.readerList: self.readerList.remove(id) pushObjectNetInterface.pushChatToObjectList(self.id, id)
def sendMessage(dynamicId, characterId, topic, content, linkData, tonickname=None): '''发送聊天信息 @param dynamicId:int 客户端的id @param characterId:int 角色的id @param topic :int 频道的编号 @param content:string 发送的消息内容 @param linkData: dict list 连接信息内容 ''' chater = ChaterManager().getChaterByCharacterId(characterId) if not chater: return {'result': False, 'message': Lg().g(639)} if topic == 7: toplayer = ChaterManager().getChaterByCharacterId(characterId) if not toplayer: return {'result': False, "message": Lg().g(640)} else: topic = toplayer.baseInfo.id targetList = [] chaterName = chater.getCharacterName() if topic == 1: #世界聊天 idlist = ChaterManager().getAlldynamicId() targetList = idlist elif topic == 2: #当前场景 roomId = chater.getRoomId() targetList = ChatRoomManager().getRoomMember(roomId) elif topic == 3: #公会 gid = chater.guildid if gid < 1: return {'result': False, "message": Lg().g(641)} else: plist = GuildManager().getdtidListBygid(gid) if plist: targetList = list(plist) result = doGmCommand(characterId, content) pushChatMessage(topic, characterId, chaterName, dbShieldWord.replaceIllegalChar(content), linkData, targetList) return {'result': True}
def sendMessage_1003(_conn, request_proto): '''发送聊天消息''' from app.chatServer.core.ChaterManager import ChaterManager # from core.Item import Item argument = sendMessage1003_pb2.chatConectingRequest() argument.ParseFromString(request_proto) response = sendMessage1003_pb2.chatConectingResponse() dynamicId = _conn.transport.sessionno characterId = argument.id #当前角色id topic = argument.topic #频道号 tonickname=argument.chatOjbect #角色昵称 content = argument.content #内容 chater=ChaterManager().getChaterByCharacterId(characterId) if chater.donttalk==0:#不禁言 linkData = [] #聊天连接信息 for _item in argument.linkData: item = {} item['chatEquipType'] = _item.chatEquipType #0物品 1角色 2怪物 item['id'] = _item.id item['name'] = _item.name if _item.chatEquipType==0: item1=Item(id=_item.id) item['itemInfo']=item1 # elif _item.chatEquipType==1: # linkData.append(item) # continue linkData.append(item) Lt().add(characterId, tonickname, content) data = chat.sendMessage(dynamicId, characterId, topic, content,linkData,tonickname) response.result = data.get('result',False) response.message = data.get('message',u'') else:#禁言 response.result = False response.message =Lg().g(644) return response.SerializeToString()
def sendSysInfomations_Item(msg, dynamicId, itemlist): """(根据物品实例列表)发送系统提示消息 @param mag: 发送的聊天信息 @param itemlist: 物品实例列表 @param dynamicId: 角色动态id """ targetList = [] dynamicId = ChaterManager().getChaterDynamicId if dynamicId: targetList.append(dynamicId) if not itemlist: return linkData = [] for item in itemlist: it = {} it['id'] = item.baseInfo.id it['name'] = item.baseInfo.getItemTemplateInfo().get('name', '') it['chatEquipType'] = 0 it['itemInfo'] = item msg += u"[%" + it['name'] + u"%] " linkData.append(it) pushChatMessage(5, -1, Lg().g(128), -1, Lg().g(642) + msg, linkData, targetList)