//处理重命名请求 public void ReqRename(MsgPack pack) { ReqRename data = pack.msg.reqRename; GameMsg msg = new GameMsg { cmd = (int)CMD.RespondRename, //下面的代码太早了,这个名字也许存在 //respondRename = new RespondRename //{ // name = data.name //} }; //名字存在,返回错误码 if (cacheSrv.IsNameExist(data.name)) { msg.err = (int)ErroroCode.NameIsExist; } //不存在,更新缓存和数据库数据 else { PlayerData playerData = cacheSrv.GetPlayerDataBySession(pack.serverSession); playerData.name = data.name; //数据库更新出错 if (!cacheSrv.UpdatePlayerData(playerData.id, playerData)) { msg.err = (int)ErroroCode.UpdateDBError; } else { msg.respondRename = new RespondRename { name = data.name }; } } //发送回去 pack.serverSession.SendMsg(msg); }