How to use getError method in ava

Best JavaScript code snippet using ava

playerHandler.js

Source:playerHandler.js Github

copy

Full Screen

...33 var finishNow = msg.finishNow34 var e = null35 if(!_.isNumber(location) || location % 1 !== 0 || location < 1 || location > 22){36 e = new Error("location 不合法")37 next(e, ErrorUtils.getError(e))38 return39 }40 if(!_.isBoolean(finishNow)){41 e = new Error("finishNow 不合法")42 next(e, ErrorUtils.getError(e))43 return44 }45 this.request(session, 'upgradeBuilding', [session.uid, location, finishNow]).then(function(playerData){46 next(null, {code:200, playerData:playerData})47 }).catch(function(e){48 next(null, ErrorUtils.getError(e))49 })50}51/**52 * 转换生产建筑类型53 * @param msg54 * @param session55 * @param next56 */57pro.switchBuilding = function(msg, session, next){58 var buildingLocation = msg.buildingLocation59 var newBuildingName = msg.newBuildingName60 var e = null61 if(!_.isNumber(buildingLocation) || buildingLocation % 1 !== 0 || buildingLocation < 1){62 e = new Error("buildingLocation 不合法")63 next(e, ErrorUtils.getError(e))64 return65 }66 if(!_.contains(_.values(Consts.ResourceBuildingMap), newBuildingName) || _.isEqual("townHall", newBuildingName)){67 e = new Error("newBuildingName 不合法")68 next(e, ErrorUtils.getError(e))69 return70 }71 this.request(session, 'switchBuilding', [session.uid, buildingLocation, newBuildingName]).then(function(playerData){72 next(null, {code:200, playerData:playerData})73 }).catch(function(e){74 next(null, ErrorUtils.getError(e))75 })76}77/**78 * 创建小建筑79 * @param msg80 * @param session81 * @param next82 */83pro.createHouse = function(msg, session, next){84 var buildingLocation = msg.buildingLocation85 var houseType = msg.houseType86 var houseLocation = msg.houseLocation87 var finishNow = msg.finishNow88 var e = null89 if(!_.isNumber(buildingLocation) || buildingLocation % 1 !== 0 || buildingLocation < 1 || buildingLocation > 20){90 e = new Error("buildingLocation 不合法")91 next(e, ErrorUtils.getError(e))92 return93 }94 if(!_.isString(houseType)){95 e = new Error("houseType 不合法")96 next(e, ErrorUtils.getError(e))97 return98 }99 if(!_.isNumber(houseLocation) || houseLocation % 1 !== 0 || houseLocation < 1 || houseLocation > 3){100 e = new Error("houseLocation 不合法")101 next(e, ErrorUtils.getError(e))102 return103 }104 if(!_.isBoolean(finishNow)){105 e = new Error("finishNow 不合法")106 next(e, ErrorUtils.getError(e))107 return108 }109 this.request(session, 'createHouse', [session.uid, buildingLocation, houseType, houseLocation, finishNow]).then(function(playerData){110 next(null, {code:200, playerData:playerData})111 }).catch(function(e){112 next(null, ErrorUtils.getError(e))113 })114}115/**116 * 升级小建筑117 * @param msg118 * @param session119 * @param next120 */121pro.upgradeHouse = function(msg, session, next){122 var buildingLocation = msg.buildingLocation123 var houseLocation = msg.houseLocation124 var finishNow = msg.finishNow125 var e = null126 if(!_.isNumber(buildingLocation) || buildingLocation % 1 !== 0 || buildingLocation < 1 || buildingLocation > 20){127 e = new Error("buildingLocation 不合法")128 next(e, ErrorUtils.getError(e))129 return130 }131 if(!_.isNumber(houseLocation) || houseLocation % 1 !== 0 || houseLocation < 1 || houseLocation > 3){132 e = new Error("houseLocation 不合法")133 next(e, ErrorUtils.getError(e))134 return135 }136 if(!_.isBoolean(finishNow)){137 e = new Error("finishNow 不合法")138 next(e, ErrorUtils.getError(e))139 return140 }141 this.request(session, 'upgradeHouse', [session.uid, buildingLocation, houseLocation, finishNow]).then(function(playerData){142 next(null, {code:200, playerData:playerData})143 }).catch(function(e){144 next(null, ErrorUtils.getError(e))145 })146}147/**148 * 免费加速149 * @param msg150 * @param session151 * @param next152 */153pro.freeSpeedUp = function(msg, session, next){154 var eventType = msg.eventType155 var eventId = msg.eventId156 var e = null157 if(!_.contains(Consts.FreeSpeedUpAbleEventTypes, eventType)){158 e = new Error("eventType 不合法")159 next(e, ErrorUtils.getError(e))160 return161 }162 if(!_.isString(eventId)){163 e = new Error("eventId 不合法")164 next(e, ErrorUtils.getError(e))165 return166 }167 this.request(session, 'freeSpeedUp', [session.uid, eventType, eventId]).then(function(playerData){168 next(null, {code:200, playerData:playerData})169 }).catch(function(e){170 next(null, ErrorUtils.getError(e))171 })172}173/**174 * 宝石加速175 * @param msg176 * @param session177 * @param next178 */179pro.speedUp = function(msg, session, next){180 var eventType = msg.eventType181 var eventId = msg.eventId182 var e = null183 if(!_.contains(Consts.SpeedUpEventTypes, eventType)){184 e = new Error("eventType 不合法")185 next(e, ErrorUtils.getError(e))186 return187 }188 if(!_.isString(eventId)){189 e = new Error("eventId 不合法")190 next(e, ErrorUtils.getError(e))191 return192 }193 this.request(session, 'speedUp', [session.uid, eventType, eventId]).then(function(playerData){194 next(null, {code:200, playerData:playerData})195 }).catch(function(e){196 next(null, ErrorUtils.getError(e))197 })198}199/**200 * 制作材料201 * @param msg202 * @param session203 * @param next204 */205pro.makeMaterial = function(msg, session, next){206 var type = msg.type207 var finishNow = msg.finishNow208 var e = null209 if(!_.contains(Consts.MaterialType, type)){210 e = new Error("type 不合法")211 next(e, ErrorUtils.getError(e))212 return213 }214 if(!_.isBoolean(finishNow)){215 e = new Error("finishNow 不合法")216 next(e, ErrorUtils.getError(e))217 return218 }219 this.request(session, 'makeMaterial', [session.uid, type, finishNow]).then(function(playerData){220 next(null, {code:200, playerData:playerData})221 }).catch(function(e){222 next(null, ErrorUtils.getError(e))223 })224}225/**226 * 领取制作完成227 * @param msg228 * @param session229 * @param next230 */231pro.getMaterials = function(msg, session, next){232 var eventId = msg.eventId233 var e = null234 if(!_.isString(eventId)){235 e = new Error("eventId 不合法")236 next(e, ErrorUtils.getError(e))237 return238 }239 this.request(session, 'getMaterials', [session.uid, eventId]).then(function(playerData){240 next(null, {code:200, playerData:playerData})241 }).catch(function(e){242 next(null, ErrorUtils.getError(e))243 })244}245/**246 * 招募普通士兵247 * @param msg248 * @param session249 * @param next250 */251pro.recruitNormalSoldier = function(msg, session, next){252 var soldierName = msg.soldierName253 var count = msg.count254 var finishNow = msg.finishNow255 var e = null256 if(!DataUtils.isNormalSoldier(soldierName)){257 e = new Error("soldierName 不合法")258 next(e, ErrorUtils.getError(e))259 return260 }261 if(!_.isNumber(count) || count % 1 !== 0 || count < 1){262 e = new Error("count 不合法")263 next(e, ErrorUtils.getError(e))264 return265 }266 if(!_.isBoolean(finishNow)){267 e = new Error("finishNow 不合法")268 next(e, ErrorUtils.getError(e))269 return270 }271 this.request(session, 'recruitNormalSoldier', [session.uid, soldierName, count, finishNow]).then(function(playerData){272 next(null, {code:200, playerData:playerData})273 }).catch(function(e){274 next(null, ErrorUtils.getError(e))275 })276}277/**278 * 招募特殊士兵279 * @param msg280 * @param session281 * @param next282 */283pro.recruitSpecialSoldier = function(msg, session, next){284 var soldierName = msg.soldierName285 var count = msg.count286 var finishNow = msg.finishNow287 var e = null288 if(!DataUtils.hasSpecialSoldier(soldierName)){289 e = new Error("soldierName 不合法")290 next(e, ErrorUtils.getError(e))291 return292 }293 if(!_.isNumber(count) || count % 1 !== 0 || count < 1){294 e = new Error("count 不合法")295 next(e, ErrorUtils.getError(e))296 return297 }298 if(!_.isBoolean(finishNow)){299 e = new Error("finishNow 不合法")300 next(e, ErrorUtils.getError(e))301 return302 }303 this.request(session, 'recruitSpecialSoldier', [session.uid, soldierName, count, finishNow]).then(function(playerData){304 next(null, {code:200, playerData:playerData})305 }).catch(function(e){306 next(null, ErrorUtils.getError(e))307 })308}309/**310 * 制作龙装备311 * @param msg312 * @param session313 * @param next314 */315pro.makeDragonEquipment = function(msg, session, next){316 var equipmentName = msg.equipmentName317 var finishNow = msg.finishNow318 var e = null319 if(!DataUtils.isDragonEquipment(equipmentName)){320 e = new Error("equipmentName 不合法")321 next(e, ErrorUtils.getError(e))322 return323 }324 if(!_.isBoolean(finishNow)){325 e = new Error("finishNow 不合法")326 next(e, ErrorUtils.getError(e))327 return328 }329 this.request(session, 'makeDragonEquipment', [session.uid, equipmentName, finishNow]).then(function(playerData){330 next(null, {code:200, playerData:playerData})331 }).catch(function(e){332 next(null, ErrorUtils.getError(e))333 })334}335/**336 * 治疗士兵337 * @param msg338 * @param session339 * @param next340 */341pro.treatSoldier = function(msg, session, next){342 var soldiers = msg.soldiers343 var finishNow = msg.finishNow344 var e = null345 if(!_.isArray(soldiers)){346 e = new Error("soldiers 不合法")347 next(e, ErrorUtils.getError(e))348 return349 }350 if(!_.isBoolean(finishNow)){351 e = new Error("finishNow 不合法")352 next(e, ErrorUtils.getError(e))353 return354 }355 this.request(session, 'treatSoldier', [session.uid, soldiers, finishNow]).then(function(playerData){356 next(null, {code:200, playerData:playerData})357 }).catch(function(e){358 next(null, ErrorUtils.getError(e))359 })360}361/**362 * 孵化龙蛋363 * @param msg364 * @param session365 * @param next366 */367pro.hatchDragon = function(msg, session, next){368 var dragonType = msg.dragonType369 var e = null370 if(!DataUtils.isDragonTypeExist(dragonType)){371 e = new Error("dragonType 不合法")372 next(e, ErrorUtils.getError(e))373 return374 }375 this.request(session, 'hatchDragon', [session.uid, dragonType]).then(function(playerData){376 next(null, {code:200, playerData:playerData})377 }).catch(function(e){378 next(null, ErrorUtils.getError(e))379 })380}381/**382 * 设置龙的装备383 * @param msg384 * @param session385 * @param next386 */387pro.setDragonEquipment = function(msg, session, next){388 var dragonType = msg.dragonType389 var equipmentCategory = msg.equipmentCategory390 var equipmentName = msg.equipmentName391 var e = null392 if(!DataUtils.isDragonTypeExist(dragonType)){393 e = new Error("dragonType 不合法")394 next(e, ErrorUtils.getError(e))395 return396 }397 if(!_.contains(Consts.DragonEquipmentCategory, equipmentCategory)){398 e = new Error("equipmentCategory 不合法")399 next(e, ErrorUtils.getError(e))400 return401 }402 if(!DataUtils.isDragonEquipment(equipmentName)){403 e = new Error("equipmentName 不合法")404 next(e, ErrorUtils.getError(e))405 return406 }407 if(!DataUtils.isDragonEquipmentLegalAtCategory(equipmentName, equipmentCategory)){408 e = new Error("equipmentName 不能装备到equipmentCategory")409 next(e, ErrorUtils.getError(e))410 return411 }412 if(!DataUtils.isDragonEquipmentLegalOnDragon(equipmentName, dragonType)){413 e = new Error("equipmentName 不能装备到dragonType")414 next(e, ErrorUtils.getError(e))415 return416 }417 this.request(session, 'setDragonEquipment', [session.uid, dragonType, equipmentCategory, equipmentName]).then(function(playerData){418 next(null, {code:200, playerData:playerData})419 }).catch(function(e){420 next(null, ErrorUtils.getError(e))421 })422}423/**424 * 强化龙的装备425 * @param msg426 * @param session427 * @param next428 */429pro.enhanceDragonEquipment = function(msg, session, next){430 var dragonType = msg.dragonType431 var equipmentCategory = msg.equipmentCategory432 var equipments = msg.equipments433 var e = null434 if(!DataUtils.isDragonTypeExist(dragonType)){435 e = new Error("dragonType 不合法")436 next(e, ErrorUtils.getError(e))437 return438 }439 if(!_.contains(Consts.DragonEquipmentCategory, equipmentCategory)){440 e = new Error("equipmentCategory 不合法")441 next(e, ErrorUtils.getError(e))442 return443 }444 if(!_.isArray(equipments)){445 e = new Error("equipments 不合法")446 next(e, ErrorUtils.getError(e))447 return448 }449 this.request(session, 'enhanceDragonEquipment', [session.uid, dragonType, equipmentCategory, equipments]).then(function(playerData){450 next(null, {code:200, playerData:playerData})451 }).catch(function(e){452 next(null, ErrorUtils.getError(e))453 })454}455/**456 * 重置龙的装备的随机Buff457 * @param msg458 * @param session459 * @param next460 */461pro.resetDragonEquipment = function(msg, session, next){462 var dragonType = msg.dragonType463 var equipmentCategory = msg.equipmentCategory464 var e = null465 if(!DataUtils.isDragonTypeExist(dragonType)){466 e = new Error("dragonType 不合法")467 next(e, ErrorUtils.getError(e))468 return469 }470 if(!_.contains(Consts.DragonEquipmentCategory, equipmentCategory)){471 e = new Error("equipmentCategory 不合法")472 next(e, ErrorUtils.getError(e))473 return474 }475 this.request(session, 'resetDragonEquipment', [session.uid, dragonType, equipmentCategory]).then(function(playerData){476 next(null, {code:200, playerData:playerData})477 }).catch(function(e){478 next(null, ErrorUtils.getError(e))479 })480}481/**482 * 升级龙的技能483 * @param msg484 * @param session485 * @param next486 */487pro.upgradeDragonSkill = function(msg, session, next){488 var dragonType = msg.dragonType489 var skillKey = msg.skillKey490 var e = null491 if(!DataUtils.isDragonTypeExist(dragonType)){492 e = new Error("dragonType 不合法")493 next(e, ErrorUtils.getError(e))494 return495 }496 if(!_.isString(skillKey) || skillKey.trim().length === 0 || skillKey.trim().length > Define.InputLength.DragonSkillKey){497 e = new Error("skillKey 不合法")498 next(e, ErrorUtils.getError(e))499 return500 }501 this.request(session, 'upgradeDragonSkill', [session.uid, dragonType, skillKey]).then(function(playerData){502 next(null, {code:200, playerData:playerData})503 }).catch(function(e){504 next(null, ErrorUtils.getError(e))505 })506}507/**508 * 升级龙的星级509 * @param msg510 * @param session511 * @param next512 */513pro.upgradeDragonStar = function(msg, session, next){514 var dragonType = msg.dragonType515 var e = null516 if(!DataUtils.isDragonTypeExist(dragonType)){517 e = new Error("dragonType 不合法")518 next(e, ErrorUtils.getError(e))519 return520 }521 this.request(session, 'upgradeDragonStar', [session.uid, dragonType]).then(function(playerData){522 next(null, {code:200, playerData:playerData})523 }).catch(function(e){524 next(null, ErrorUtils.getError(e))525 })526}527/**528 * 获取每日任务列表529 * @param msg530 * @param session531 * @param next532 */533pro.getDailyQuests = function(msg, session, next){534 this.request(session, 'getDailyQuests', [session.uid]).then(function(playerData){535 next(null, {code:200, playerData:playerData})536 }).catch(function(e){537 next(null, ErrorUtils.getError(e))538 })539}540/**541 * 为每日任务中某个任务增加星级542 * @param msg543 * @param session544 * @param next545 */546pro.addDailyQuestStar = function(msg, session, next){547 var questId = msg.questId548 var e = null549 if(!_.isString(questId) || !ShortId.isValid(questId)){550 e = new Error("questId 不合法")551 next(e, ErrorUtils.getError(e))552 return553 }554 this.request(session, 'addDailyQuestStar', [session.uid, questId]).then(function(playerData){555 next(null, {code:200, playerData:playerData})556 }).catch(function(e){557 next(null, ErrorUtils.getError(e))558 })559}560/**561 * 开始一个每日任务562 * @param msg563 * @param session564 * @param next565 */566pro.startDailyQuest = function(msg, session, next){567 var questId = msg.questId568 var e = null569 if(!_.isString(questId) || !ShortId.isValid(questId)){570 e = new Error("questId 不合法")571 next(e, ErrorUtils.getError(e))572 return573 }574 this.request(session, 'startDailyQuest', [session.uid, questId]).then(function(playerData){575 next(null, {code:200, playerData:playerData})576 }).catch(function(e){577 next(null, ErrorUtils.getError(e))578 })579}580/**581 * 领取每日任务奖励582 * @param msg583 * @param session584 * @param next585 */586pro.getDailyQeustReward = function(msg, session, next){587 var questEventId = msg.questEventId588 var e = null589 if(!_.isString(questEventId) || !ShortId.isValid(questEventId)){590 e = new Error("questEventId 不合法")591 next(e, ErrorUtils.getError(e))592 return593 }594 this.request(session, 'getDailyQeustReward', [session.uid, questEventId]).then(function(playerData){595 next(null, {code:200, playerData:playerData})596 }).catch(function(e){597 next(null, ErrorUtils.getError(e))598 })599}600/**601 * 设置玩家语言602 * @param msg603 * @param session604 * @param next605 */606pro.setPlayerLanguage = function(msg, session, next){607 var language = msg.language608 var e = null609 if(!_.contains(Consts.PlayerLanguage, language)){610 e = new Error("language 不合法")611 next(e, ErrorUtils.getError(e))612 return613 }614 this.request(session, 'setPlayerLanguage', [session.uid, language]).then(function(playerData){615 next(null, {code:200, playerData:playerData})616 }).catch(function(e){617 next(null, ErrorUtils.getError(e))618 })619}620/**621 * 获取玩家个人信息622 * @param msg623 * @param session624 * @param next625 */626pro.getPlayerInfo = function(msg, session, next){627 var self = this;628 var memberId = msg.memberId;629 var e = null630 if(!_.isString(memberId) || !ShortId.isValid(memberId)){631 e = new Error("memberId 不合法")632 next(e, ErrorUtils.getError(e))633 return634 }635 self.app.get('Player').findById(memberId, 'serverId').then(function(doc){636 if(!_.isObject(doc)){637 return Promise.reject(ErrorUtils.playerNotExist(session.uid, memberId));638 }639 return self.request(session, 'getPlayerInfo', [session.uid, memberId], doc.serverId);640 }).then(function(playerViewData){641 next(null, {code:200, playerViewData:playerViewData})642 }).catch(function(e){643 next(null, ErrorUtils.getError(e))644 })645}646/**647 * 发送个人邮件648 * @param msg649 * @param session650 * @param next651 */652pro.sendMail = function(msg, session, next){653 var self = this;654 var memberId = msg.memberId;655 var title = msg.title;656 var content = msg.content;657 var sendAsMod = msg.sendAsMod;658 var replyMod = msg.replyMod;659 var e = null660 if(!_.isString(memberId) || !ShortId.isValid(memberId)){661 e = new Error("memberId 不合法")662 return next(e, ErrorUtils.getError(e))663 }664 if(_.isEqual(session.uid, memberId)){665 e = new Error("不能给自己发邮件")666 return next(e, ErrorUtils.getError(e))667 }668 if(!_.isString(title) || title.trim().length === 0 || title.trim().length > Define.InputLength.MailTitle){669 e = new Error("title 不合法")670 return next(e, ErrorUtils.getError(e))671 }672 if(!_.isString(content) || content.trim().length === 0 || content.trim().length > Define.InputLength.MailContent){673 e = new Error("content 不合法")674 return next(e, ErrorUtils.getError(e))675 }676 var amModDoc = null;677 var targetModDoc = null;678 var memberDoc = null;679 var Player = this.app.get('Player');680 Player.findById(memberId, 'serverId basicInfo.name').then(function(doc){681 if(!_.isObject(doc)){682 return Promise.reject(ErrorUtils.playerNotExist(session.uid, memberId));683 }684 memberDoc = doc;685 }).then(function(){686 if(!!sendAsMod){687 return self.app.get('Mod').findById(session.uid).then(function(doc){688 if(!doc){689 return Promise.reject(ErrorUtils.youAreNotTheMod(session.uid));690 }691 amModDoc = doc;692 })693 }694 }).then(function(){695 if(!!replyMod){696 return self.app.get('Mod').findById(memberId).then(function(doc){697 if(!doc){698 return Promise.reject(ErrorUtils.targetNotModNowCanNotReply(session.uid, memberId));699 }700 targetModDoc = doc;701 })702 }703 }).then(function(){704 var playerId = session.uid;705 var fromName = !!sendAsMod ? amModDoc.name : session.get('name');706 var fromIcon = !!sendAsMod ? -1 : session.get('icon');707 var fromAllianceTag = !!sendAsMod ? '' : session.get('allianceTag');708 var toName = !!replyMod ? targetModDoc.name : memberDoc.basicInfo.name;709 var toIcon = !!replyMod ? -1 : memberDoc.basicInfo.icon;710 var mailToMember = {711 id:ShortId.generate(),712 title:title,713 fromId:playerId,714 fromName:fromName,715 fromIcon:fromIcon,716 fromAllianceTag:fromAllianceTag,717 toIcon:toIcon,718 content:content,719 sendTime:Date.now(),720 rewards:[],721 rewardGetted:false,722 isRead:false,723 isSaved:false724 }725 var mailToPlayer = {726 id:ShortId.generate(),727 title:title,728 fromName:fromName,729 fromIcon:fromIcon,730 fromAllianceTag:fromAllianceTag,731 toId:memberId,732 toName:toName,733 toIcon:toIcon,734 content:content,735 sendTime:Date.now()736 }737 return self.request(session, 'addMail', [memberId, mailToMember], memberDoc.serverId).then(function(){738 return self.request(session, 'addSendMail', [playerId, mailToPlayer])739 })740 }).then(function(){741 next(null, {code:200})742 }).catch(function(e){743 console.error(e)744 next(null, ErrorUtils.getError(e))745 })746}747/**748 * 阅读邮件749 * @param msg750 * @param session751 * @param next752 */753pro.readMails = function(msg, session, next){754 var mailIds = msg.mailIds755 var e = null756 if(!_.isArray(mailIds) || mailIds.length == 0){757 e = new Error("mailIds 不合法")758 next(e, ErrorUtils.getError(e))759 return760 }761 for(var i = 0; i < mailIds.length; i++){762 if(!ShortId.isValid(mailIds[i])){763 e = new Error("mailIds 不合法")764 next(e, ErrorUtils.getError(e))765 return766 }767 }768 this.request(session, 'readMails', [session.uid, mailIds]).then(function(playerData){769 next(null, {code:200, playerData:playerData})770 }).catch(function(e){771 next(null, ErrorUtils.getError(e))772 })773}774/**775 * 收藏邮件776 * @param msg777 * @param session778 * @param next779 */780pro.saveMail = function(msg, session, next){781 var mailId = msg.mailId782 var e = null783 if(!_.isString(mailId) || !ShortId.isValid(mailId)){784 e = new Error("mailId 不合法")785 next(e, ErrorUtils.getError(e))786 return787 }788 this.request(session, 'saveMail', [session.uid, mailId]).then(function(playerData){789 next(null, {code:200, playerData:playerData})790 }).catch(function(e){791 next(null, ErrorUtils.getError(e))792 })793}794/**795 * 取消收藏邮件796 * @param msg797 * @param session798 * @param next799 */800pro.unSaveMail = function(msg, session, next){801 var mailId = msg.mailId802 var e = null803 if(!_.isString(mailId) || !ShortId.isValid(mailId)){804 e = new Error("mailId 不合法")805 next(e, ErrorUtils.getError(e))806 return807 }808 this.request(session, 'unSaveMail', [session.uid, mailId]).then(function(playerData){809 next(null, {code:200, playerData:playerData})810 }).catch(function(e){811 next(null, ErrorUtils.getError(e))812 })813}814/**815 * 获取玩家邮件816 * @param msg817 * @param session818 * @param next819 */820pro.getMails = function(msg, session, next){821 var fromIndex = msg.fromIndex822 var e = null823 if(!_.isNumber(fromIndex) || fromIndex % 1 !== 0 || fromIndex < 0){824 e = new Error("fromIndex 不合法")825 next(e, ErrorUtils.getError(e))826 return827 }828 this.request(session, 'getMails', [session.uid, fromIndex]).then(function(mails){829 next(null, {code:200, mails:mails})830 }).catch(function(e){831 next(null, ErrorUtils.getError(e))832 })833}834/**835 * 获取玩家已发邮件836 * @param msg837 * @param session838 * @param next839 */840pro.getSendMails = function(msg, session, next){841 var fromIndex = msg.fromIndex842 var e = null843 if(!_.isNumber(fromIndex) || fromIndex % 1 !== 0 || fromIndex < 0){844 e = new Error("fromIndex 不合法")845 next(e, ErrorUtils.getError(e))846 return847 }848 this.request(session, 'getSendMails', [session.uid, fromIndex]).then(function(mails){849 next(null, {code:200, mails:mails})850 }).catch(function(e){851 next(null, ErrorUtils.getError(e))852 })853}854/**855 * 获取玩家已存邮件856 * @param msg857 * @param session858 * @param next859 */860pro.getSavedMails = function(msg, session, next){861 var fromIndex = msg.fromIndex862 var e = null863 if(!_.isNumber(fromIndex) || fromIndex % 10 !== 0 || fromIndex < 0){864 e = new Error("fromIndex 不合法")865 next(e, ErrorUtils.getError(e))866 return867 }868 this.request(session, 'getSavedMails', [session.uid, fromIndex]).then(function(mails){869 next(null, {code:200, mails:mails})870 }).catch(function(e){871 next(null, ErrorUtils.getError(e))872 })873}874/**875 * 删除邮件876 * @param msg877 * @param session878 * @param next879 */880pro.deleteMails = function(msg, session, next){881 var mailIds = msg.mailIds882 var e = null883 if(!_.isArray(mailIds) || mailIds.length == 0){884 e = new Error("mailIds 不合法")885 next(e, ErrorUtils.getError(e))886 return887 }888 for(var i = 0; i < mailIds.length; i++){889 if(!ShortId.isValid(mailIds[i])){890 e = new Error("mailIds 不合法")891 next(e, ErrorUtils.getError(e))892 return893 }894 }895 this.request(session, 'deleteMails', [session.uid, mailIds]).then(function(playerData){896 next(null, {code:200, playerData:playerData})897 }).catch(function(e){898 next(null, ErrorUtils.getError(e))899 })900}901/**902 * 删除已发邮件903 * @param msg904 * @param session905 * @param next906 */907pro.deleteSendMails = function(msg, session, next){908 var mailIds = msg.mailIds909 var e = null910 if(!_.isArray(mailIds) || mailIds.length == 0){911 e = new Error("mailIds 不合法")912 next(e, ErrorUtils.getError(e))913 return914 }915 for(var i = 0; i < mailIds.length; i++){916 if(!ShortId.isValid(mailIds[i])){917 e = new Error("mailIds 不合法")918 next(e, ErrorUtils.getError(e))919 return920 }921 }922 this.request(session, 'deleteSendMails', [session.uid, mailIds]).then(function(playerData){923 next(null, {code:200, playerData:playerData})924 }).catch(function(e){925 next(null, ErrorUtils.getError(e))926 })927}928/**929 * 从邮件获取奖励930 * @param msg931 * @param session932 * @param next933 */934pro.getMailRewards = function(msg, session, next){935 var mailId = msg.mailId936 var e = null937 if(!ShortId.isValid(mailId)){938 e = new Error("mailId 不合法")939 next(e, ErrorUtils.getError(e))940 return941 }942 this.request(session, 'getMailRewards', [session.uid, mailId]).then(function(playerData){943 next(null, {code:200, playerData:playerData})944 }).catch(function(e){945 next(null, ErrorUtils.getError(e))946 })947}948/**949 * 阅读战报950 * @param msg951 * @param session952 * @param next953 */954pro.readReports = function(msg, session, next){955 var reportIds = msg.reportIds956 var e = null957 if(!_.isArray(reportIds) || reportIds.length == 0){958 e = new Error("reportIds 不合法")959 next(e, ErrorUtils.getError(e))960 return961 }962 for(var i = 0; i < reportIds.length; i++){963 if(!ShortId.isValid(reportIds[i])){964 e = new Error("reportIds 不合法")965 next(e, ErrorUtils.getError(e))966 return967 }968 }969 this.request(session, 'readReports', [session.uid, reportIds]).then(function(playerData){970 next(null, {code:200, playerData:playerData})971 }).catch(function(e){972 next(null, ErrorUtils.getError(e))973 })974}975/**976 * 收藏战报977 * @param msg978 * @param session979 * @param next980 */981pro.saveReport = function(msg, session, next){982 var reportId = msg.reportId983 var e = null984 if(!_.isString(reportId) || !ShortId.isValid(reportId)){985 e = new Error("reportId 不合法")986 next(e, ErrorUtils.getError(e))987 return988 }989 this.request(session, 'saveReport', [session.uid, reportId]).then(function(playerData){990 next(null, {code:200, playerData:playerData})991 }).catch(function(e){992 next(null, ErrorUtils.getError(e))993 })994}995/**996 * 取消收藏战报997 * @param msg998 * @param session999 * @param next1000 */1001pro.unSaveReport = function(msg, session, next){1002 var reportId = msg.reportId1003 var e = null1004 if(!_.isString(reportId) || !ShortId.isValid(reportId)){1005 e = new Error("reportId 不合法")1006 next(e, ErrorUtils.getError(e))1007 return1008 }1009 this.request(session, 'unSaveReport', [session.uid, reportId]).then(function(playerData){1010 next(null, {code:200, playerData:playerData})1011 }).catch(function(e){1012 next(null, ErrorUtils.getError(e))1013 })1014}1015/**1016 * 获取玩家战报1017 * @param msg1018 * @param session1019 * @param next1020 */1021pro.getReports = function(msg, session, next){1022 var fromIndex = msg.fromIndex1023 var e = null1024 if(!_.isNumber(fromIndex) || fromIndex % 1 !== 0 || fromIndex < 0){1025 e = new Error("fromIndex 不合法")1026 next(e, ErrorUtils.getError(e))1027 return1028 }1029 this.request(session, 'getReports', [session.uid, fromIndex]).then(function(reports){1030 next(null, {code:200, reports:reports})1031 }).catch(function(e){1032 next(null, ErrorUtils.getError(e))1033 })1034}1035/**1036 * 获取玩家已存战报1037 * @param msg1038 * @param session1039 * @param next1040 */1041pro.getSavedReports = function(msg, session, next){1042 var fromIndex = msg.fromIndex1043 var e = null1044 if(!_.isNumber(fromIndex) || fromIndex % 1 !== 0 || fromIndex < 0){1045 e = new Error("fromIndex 不合法")1046 next(e, ErrorUtils.getError(e))1047 return1048 }1049 this.request(session, 'getSavedReports', [session.uid, fromIndex]).then(function(reports){1050 next(null, {code:200, reports:reports})1051 }).catch(function(e){1052 next(null, ErrorUtils.getError(e))1053 })1054}1055/**1056 * 删除战报1057 * @param msg1058 * @param session1059 * @param next1060 */1061pro.deleteReports = function(msg, session, next){1062 var reportIds = msg.reportIds1063 var e = null1064 if(!_.isArray(reportIds) || reportIds.length == 0){1065 e = new Error("reportIds 不合法")1066 next(e, ErrorUtils.getError(e))1067 return1068 }1069 for(var i = 0; i < reportIds.length; i++){1070 if(!ShortId.isValid(reportIds[i])){1071 e = new Error("reportIds 不合法")1072 next(e, ErrorUtils.getError(e))1073 return1074 }1075 }1076 this.request(session, 'deleteReports', [session.uid, reportIds]).then(function(playerData){1077 next(null, {code:200, playerData:playerData})1078 }).catch(function(e){1079 next(null, ErrorUtils.getError(e))1080 })1081}1082/**1083 * 获取玩家可视化数据数据1084 * @param msg1085 * @param session1086 * @param next1087 */1088pro.getPlayerViewData = function(msg, session, next){1089 var targetPlayerId = msg.targetPlayerId1090 var e = null1091 if(!_.isString(targetPlayerId) || !ShortId.isValid(targetPlayerId)){1092 e = new Error("targetPlayerId 不合法")1093 next(e, ErrorUtils.getError(e))1094 return1095 }1096 this.request(session, 'getPlayerViewData', [session.uid, targetPlayerId]).then(function(playerViewData){1097 next(null, {code:200, playerViewData:playerViewData})1098 }).catch(function(e){1099 next(null, ErrorUtils.getError(e))1100 })1101}1102/**1103 * 设置驻防使用的部队1104 * @param msg1105 * @param session1106 * @param next1107 */1108pro.setDefenceTroop = function(msg, session, next){1109 var dragonType = msg.dragonType;1110 var soldiers = msg.soldiers;1111 var e = null1112 if(!DataUtils.isDragonTypeExist(dragonType)){1113 e = new Error("dragonType 不合法")1114 next(e, ErrorUtils.getError(e))1115 return1116 }1117 if(!_.isArray(soldiers)){1118 e = new Error("soldiers 不合法")1119 next(e, ErrorUtils.getError(e))1120 return1121 }1122 this.request(session, 'setDefenceTroop', [session.uid, dragonType, soldiers]).then(function(playerData){1123 next(null, {code:200, playerData:playerData})1124 }).catch(function(e){1125 next(null, ErrorUtils.getError(e))1126 })1127}1128/**1129 * 取消驻防1130 * @param msg1131 * @param session1132 * @param next1133 */1134pro.cancelDefenceTroop = function(msg, session, next){1135 this.request(session, 'cancelDefenceTroop', [session.uid]).then(function(playerData){1136 next(null, {code:200, playerData:playerData})1137 }).catch(function(e){1138 next(null, ErrorUtils.getError(e))1139 })1140}1141/**1142 * 出售商品1143 * @param msg1144 * @param session1145 * @param next1146 */1147pro.sellItem = function(msg, session, next){1148 var type = msg.type1149 var name = msg.name1150 var count = msg.count1151 var price = msg.price1152 var e = null1153 if(!_.contains(_.values(_.keys(Consts.ResourcesCanDeal)), type)){1154 e = new Error("type 不合法")1155 next(e, ErrorUtils.getError(e))1156 return1157 }1158 if(!_.contains(Consts.ResourcesCanDeal[type], name)){1159 e = new Error("name 不合法")1160 next(e, ErrorUtils.getError(e))1161 return1162 }1163 if(!_.isString(name)){1164 e = new Error("name 不合法")1165 next(e, ErrorUtils.getError(e))1166 return1167 }1168 if(!_.isNumber(count) || count % 1 !== 0 || count <= 0){1169 e = new Error("count 不合法")1170 next(e, ErrorUtils.getError(e))1171 return1172 }1173 if(!_.isNumber(price) || price % 1 !== 0 || price <= 0){1174 e = new Error("price 不合法")1175 next(e, ErrorUtils.getError(e))1176 return1177 }1178 this.request(session, 'sellItem', [session.uid, type, name, count, price]).then(function(playerData){1179 next(null, {code:200, playerData:playerData})1180 }).catch(function(e){1181 next(null, ErrorUtils.getError(e))1182 })1183}1184/**1185 * 获取商品列表1186 * @param msg1187 * @param session1188 * @param next1189 */1190pro.getSellItems = function(msg, session, next){1191 var type = msg.type1192 var name = msg.name1193 var e = null1194 if(!_.contains(_.values(_.keys(Consts.ResourcesCanDeal)), type)){1195 e = new Error("type 不合法")1196 next(e, ErrorUtils.getError(e))1197 return1198 }1199 if(!_.contains(Consts.ResourcesCanDeal[type], name)){1200 e = new Error("name 不合法")1201 next(e, ErrorUtils.getError(e))1202 return1203 }1204 if(!_.isString(name)){1205 e = new Error("name 不合法")1206 next(e, ErrorUtils.getError(e))1207 return1208 }1209 this.request(session, 'getSellItems', [session.uid, type, name]).then(function(itemDocs){1210 next(null, {code:200, itemDocs:itemDocs})1211 }).catch(function(e){1212 next(null, ErrorUtils.getError(e))1213 })1214}1215/**1216 * 购买出售的商品1217 * @param msg1218 * @param session1219 * @param next1220 */1221pro.buySellItem = function(msg, session, next){1222 var itemId = msg.itemId1223 var e = null1224 if(!_.isString(itemId) || !ShortId.isValid(itemId)){1225 e = new Error("itemId 不合法")1226 next(e, ErrorUtils.getError(e))1227 return1228 }1229 this.request(session, 'buySellItem', [session.uid, itemId]).then(function(playerData){1230 next(null, {code:200, playerData:playerData})1231 }).catch(function(e){1232 next(null, ErrorUtils.getError(e))1233 })1234}1235/**1236 * 获取出售后赚取的银币1237 * @param msg1238 * @param session1239 * @param next1240 */1241pro.getMyItemSoldMoney = function(msg, session, next){1242 var itemId = msg.itemId1243 var e = null1244 if(!_.isString(itemId) || !ShortId.isValid(itemId)){1245 e = new Error("itemId 不合法")1246 next(e, ErrorUtils.getError(e))1247 return1248 }1249 this.request(session, 'getMyItemSoldMoney', [session.uid, itemId]).then(function(playerData){1250 next(null, {code:200, playerData:playerData})1251 }).catch(function(e){1252 next(null, ErrorUtils.getError(e))1253 })1254}1255/**1256 * 下架商品1257 * @param msg1258 * @param session1259 * @param next1260 */1261pro.removeMySellItem = function(msg, session, next){1262 var itemId = msg.itemId1263 var e = null1264 if(!_.isString(itemId) || !ShortId.isValid(itemId)){1265 e = new Error("itemId 不合法")1266 next(e, ErrorUtils.getError(e))1267 return1268 }1269 this.request(session, 'removeMySellItem', [session.uid, itemId]).then(function(playerData){1270 next(null, {code:200, playerData:playerData})1271 }).catch(function(e){1272 next(null, ErrorUtils.getError(e))1273 })1274}1275/**1276 * 设置玩家Push Notification Id1277 * @param msg1278 * @param session1279 * @param next1280 */1281pro.setPushId = function(msg, session, next){1282 var pushId = msg.pushId1283 var e = null1284 if(!_.isString(pushId)){1285 e = new Error("pushId 不合法")1286 next(e, ErrorUtils.getError(e))1287 return1288 }1289 this.request(session, 'setPushId', [session.uid, pushId]).then(function(playerData){1290 next(null, {code:200, playerData:playerData})1291 }).catch(function(e){1292 next(null, ErrorUtils.getError(e))1293 })1294}1295/**1296 * 升级生产科技1297 * @param msg1298 * @param session1299 * @param next1300 */1301pro.upgradeProductionTech = function(msg, session, next){1302 var techName = msg.techName1303 var finishNow = msg.finishNow1304 var e = null1305 if(!DataUtils.isProductionTechNameLegal(techName)){1306 e = new Error("techName 不合法")1307 next(e, ErrorUtils.getError(e))1308 return1309 }1310 if(!_.isBoolean(finishNow)){1311 e = new Error("finishNow 不合法")1312 next(e, ErrorUtils.getError(e))1313 return1314 }1315 this.request(session, 'upgradeProductionTech', [session.uid, techName, finishNow]).then(function(playerData){1316 next(null, {code:200, playerData:playerData})1317 }).catch(function(e){1318 next(null, ErrorUtils.getError(e))1319 })1320}1321/**1322 * 升级军事科技1323 * @param msg1324 * @param session1325 * @param next1326 */1327pro.upgradeMilitaryTech = function(msg, session, next){1328 var techName = msg.techName1329 var finishNow = msg.finishNow1330 var e = null1331 if(!DataUtils.isMilitaryTechNameLegal(techName)){1332 e = new Error("techName 不合法")1333 next(e, ErrorUtils.getError(e))1334 return1335 }1336 if(!_.isBoolean(finishNow)){1337 e = new Error("finishNow 不合法")1338 next(e, ErrorUtils.getError(e))1339 return1340 }1341 this.request(session, 'upgradeMilitaryTech', [session.uid, techName, finishNow]).then(function(playerData){1342 next(null, {code:200, playerData:playerData})1343 }).catch(function(e){1344 next(null, ErrorUtils.getError(e))1345 })1346}1347/**1348 * 升级士兵星级1349 * @param msg1350 * @param session1351 * @param next1352 */1353pro.upgradeSoldierStar = function(msg, session, next){1354 var soldierName = msg.soldierName1355 var finishNow = msg.finishNow1356 var e = null1357 if(!DataUtils.isNormalSoldier(soldierName)){1358 e = new Error("soldierName 不合法")1359 next(e, ErrorUtils.getError(e))1360 return1361 }1362 if(!_.isBoolean(finishNow)){1363 e = new Error("finishNow 不合法")1364 next(e, ErrorUtils.getError(e))1365 return1366 }1367 this.request(session, 'upgradeSoldierStar', [session.uid, soldierName, finishNow]).then(function(playerData){1368 next(null, {code:200, playerData:playerData})1369 }).catch(function(e){1370 next(null, ErrorUtils.getError(e))1371 })1372}1373/**1374 * 设置玩家地形1375 * @param msg1376 * @param session1377 * @param next1378 */1379pro.setTerrain = function(msg, session, next){1380 var terrain = msg.terrain1381 var e = null1382 if(!_.contains(_.values(Consts.AllianceTerrain), terrain)){1383 e = new Error("terrain 不合法")1384 next(e, ErrorUtils.getError(e))1385 return1386 }1387 this.request(session, 'setTerrain', [session.uid, terrain]).then(function(playerData){1388 next(null, {code:200, playerData:playerData})1389 }).catch(function(e){1390 next(null, ErrorUtils.getError(e))1391 })1392}1393/**1394 * 购买道具1395 * @param msg1396 * @param session1397 * @param next1398 */1399pro.buyItem = function(msg, session, next){1400 var itemName = msg.itemName1401 var count = msg.count1402 var e = null1403 if(!DataUtils.isItemNameExist(itemName)){1404 e = new Error("itemName 不合法")1405 next(e, ErrorUtils.getError(e))1406 return1407 }1408 if(!_.isNumber(count) || count % 1 !== 0 || count <= 0){1409 e = new Error("count 不合法")1410 next(e, ErrorUtils.getError(e))1411 return1412 }1413 this.request(session, 'buyItem', [session.uid, itemName, count]).then(function(playerData){1414 next(null, {code:200, playerData:playerData})1415 }).catch(function(e){1416 next(null, ErrorUtils.getError(e))1417 })1418}1419/**1420 * 使用道具1421 * @param msg1422 * @param session1423 * @param next1424 */1425pro.useItem = function(msg, session, next){1426 var itemName = msg.itemName1427 var params = msg.params1428 var e = null1429 if(!DataUtils.isItemNameExist(itemName)){1430 e = new Error("itemName 不合法")1431 next(e, ErrorUtils.getError(e))1432 return1433 }1434 if(!_.isObject(params) || !ItemUtils.isParamsLegal(itemName, params)){1435 e = new Error("params 不合法")1436 next(e, ErrorUtils.getError(e))1437 return1438 }1439 this.request(session, 'useItem', [session.uid, itemName, params]).then(function(playerData){1440 next(null, {code:200, playerData:playerData})1441 }).catch(function(e){1442 next(null, ErrorUtils.getError(e))1443 })1444}1445/**1446 * 购买并使用道具1447 * @param msg1448 * @param session1449 * @param next1450 */1451pro.buyAndUseItem = function(msg, session, next){1452 var itemName = msg.itemName1453 var params = msg.params1454 var e = null1455 if(!DataUtils.isItemNameExist(itemName)){1456 e = new Error("itemName 不合法")1457 next(e, ErrorUtils.getError(e))1458 return1459 }1460 if(!_.isObject(params) || !ItemUtils.isParamsLegal(itemName, params)){1461 e = new Error("params 不合法")1462 next(e, ErrorUtils.getError(e))1463 return1464 }1465 this.request(session, 'buyAndUseItem', [session.uid, itemName, params]).then(function(playerData){1466 next(null, {code:200, playerData:playerData})1467 }).catch(function(e){1468 next(null, ErrorUtils.getError(e))1469 })1470}1471/**1472 * gacha1473 * @param msg1474 * @param session1475 * @param next1476 */1477pro.gacha = function(msg, session, next){1478 var type = msg.type1479 var e = null1480 if(!_.contains(_.values(Consts.GachaType), type)){1481 e = new Error("type 不合法")1482 next(e, ErrorUtils.getError(e))1483 return1484 }1485 this.request(session, 'gacha', [session.uid, type]).then(function(playerData){1486 next(null, {code:200, playerData:playerData})1487 }).catch(function(e){1488 next(null, ErrorUtils.getError(e))1489 })1490}1491/**1492 * 设置GameCenter Id1493 * @param msg1494 * @param session1495 * @param next1496 */1497pro.bindGc = function(msg, session, next){1498 var type = msg.type;1499 var gcId = msg.gcId;1500 var gcName = msg.gcName;1501 var e = null1502 if(!_.isString(gcId)){1503 e = new Error("gcId 不合法")1504 return next(e, ErrorUtils.getError(e))1505 }1506 if(!_.contains(Consts.GcTypes, type)){1507 e = new Error("type 不合法")1508 return next(e, ErrorUtils.getError(e))1509 }1510 if(!_.isString(gcName)){1511 e = new Error("gcName 不合法")1512 return next(e, ErrorUtils.getError(e))1513 }1514 this.request(session, 'bindGc', [session.uid, type, gcId, gcName]).then(function(playerData){1515 next(null, {code:200, playerData:playerData})1516 }).catch(function(e){1517 next(null, ErrorUtils.getError(e))1518 })1519}1520/**1521 * 更新GcName1522 * @param msg1523 * @param session1524 * @param next1525 */1526pro.updateGcName = function(msg, session, next){1527 var gcName = msg.gcName;1528 var e = null1529 if(!_.isString(gcName)){1530 e = new Error("gcName 不合法")1531 return next(e, ErrorUtils.getError(e))1532 }1533 this.request(session, 'updateGcName', [session.uid, gcName]).then(function(playerData){1534 next(null, {code:200, playerData:playerData})1535 }).catch(function(e){1536 next(null, ErrorUtils.getError(e))1537 })1538}1539/**1540 * 切换GameCenter账号1541 * @param msg1542 * @param session1543 * @param next1544 */1545pro.switchGc = function(msg, session, next){1546 var gcId = msg.gcId1547 var e = null1548 if(!_.isString(gcId)){1549 e = new Error("gcId 不合法")1550 next(e, ErrorUtils.getError(e))1551 return1552 }1553 this.request(session, 'switchGc', [session.uid, session.get("deviceId"), gcId]).then(function(){1554 next(null, {code:200})1555 }).catch(function(e){1556 next(null, ErrorUtils.getError(e))1557 })1558}1559/**1560 * 获取每日登陆奖励1561 * @param msg1562 * @param session1563 * @param next1564 */1565pro.getDay60Reward = function(msg, session, next){1566 this.request(session, 'getDay60Reward', [session.uid]).then(function(playerData){1567 next(null, {code:200, playerData:playerData})1568 }).catch(function(e){1569 next(null, ErrorUtils.getError(e))1570 })1571}1572/**1573 * 获取每日在线奖励1574 * @param msg1575 * @param session1576 * @param next1577 */1578pro.getOnlineReward = function(msg, session, next){1579 var timePoint = msg.timePoint1580 var e = null1581 if(!DataUtils.isOnLineTimePointExist(timePoint)){1582 e = new Error("timePoint 不合法")1583 next(e, ErrorUtils.getError(e))1584 }1585 this.request(session, 'getOnlineReward', [session.uid, timePoint]).then(function(playerData){1586 next(null, {code:200, playerData:playerData})1587 }).catch(function(e){1588 next(null, ErrorUtils.getError(e))1589 })1590}1591/**1592 * 获取14日登陆奖励1593 * @param msg1594 * @param session1595 * @param next1596 */1597pro.getDay14Reward = function(msg, session, next){1598 this.request(session, 'getDay14Reward', [session.uid]).then(function(playerData){1599 next(null, {code:200, playerData:playerData})1600 }).catch(function(e){1601 next(null, ErrorUtils.getError(e))1602 })1603}1604/**1605 * 获取新玩家冲级奖励1606 * @param msg1607 * @param session1608 * @param next1609 */1610pro.getLevelupReward = function(msg, session, next){1611 var levelupIndex = msg.levelupIndex1612 var e = null1613 if(!DataUtils.isLevelupIndexExist(levelupIndex)){1614 e = new Error("levelupIndex 不合法")1615 next(e, ErrorUtils.getError(e))1616 return1617 }1618 this.request(session, 'getLevelupReward', [session.uid, levelupIndex]).then(function(playerData){1619 next(null, {code:200, playerData:playerData})1620 }).catch(function(e){1621 next(null, ErrorUtils.getError(e))1622 })1623}1624/**1625 * 上传IosIAP信息1626 * @param msg1627 * @param session1628 * @param next1629 */1630pro.addIosPlayerBillingData = function(msg, session, next){1631 var receiptData = msg.receiptData1632 var e = null1633 if(!_.isString(receiptData) || _.isEmpty(receiptData.trim())){1634 e = new Error("receiptData 不合法")1635 next(e, ErrorUtils.getError(e))1636 return1637 }1638 var jsonString = new Buffer(receiptData, 'base64').toString();1639 var productIdMathResult = jsonString.match(/"product-id" = "(.*)";/)1640 var transactionIdMathResult = jsonString.match(/"transaction-id" = "(.*)";/)1641 if(!_.isArray(productIdMathResult) || productIdMathResult.length < 2){1642 e = new Error("receiptData 不合法")1643 next(e, ErrorUtils.getError(e))1644 return1645 }1646 if(!_.isArray(transactionIdMathResult) || transactionIdMathResult.length < 2){1647 e = new Error("receiptData 不合法")1648 next(e, ErrorUtils.getError(e))1649 return1650 }1651 var productId = productIdMathResult[1];1652 var transactionId = transactionIdMathResult[1];1653 this.request(session, 'addIosPlayerBillingData', [session.uid, productId, transactionId, receiptData]).then(function(playerData){1654 next(null, {code:200, playerData:playerData, transactionId:transactionId})1655 }).catch(function(e){1656 next(null, ErrorUtils.getError(e))1657 })1658}1659/**1660 * 上传Wp官方IAP信息1661 * @param msg1662 * @param session1663 * @param next1664 */1665pro.addWpOfficialPlayerBillingData = function(msg, session, next){1666 var receiptData = msg.receiptData1667 var e = null1668 if(!_.isString(receiptData) || _.isEmpty(receiptData.trim())){1669 e = new Error("receiptData 不合法")1670 next(e, ErrorUtils.getError(e))1671 return1672 }1673 var doc = new DOMParser().parseFromString(receiptData);1674 if(!doc){1675 e = new Error("receiptData 不合法")1676 return next(e, ErrorUtils.getError(e))1677 }1678 var receipt = doc.getElementsByTagName('Receipt')[0];1679 if(!receipt){1680 e = new Error("receiptData 不合法")1681 return next(e, ErrorUtils.getError(e))1682 }1683 var productReceipt = receipt.getElementsByTagName('ProductReceipt')[0];1684 if(!productReceipt){1685 e = new Error("receiptData 不合法")1686 return next(e, ErrorUtils.getError(e))1687 }1688 var productId = productReceipt.getAttribute('ProductId');1689 if(!productId){1690 e = new Error("receiptData 不合法")1691 return next(e, ErrorUtils.getError(e))1692 }1693 var transactionId = productReceipt.getAttribute('Id');1694 if(!transactionId){1695 e = new Error("receiptData 不合法")1696 return next(e, ErrorUtils.getError(e))1697 }1698 this.request(session, 'addWpOfficialPlayerBillingData', [session.uid, productId, transactionId, receiptData]).then(function(playerData){1699 next(null, {code:200, playerData:playerData, productId:productId, transactionId:transactionId})1700 }).catch(function(e){1701 next(null, ErrorUtils.getError(e))1702 })1703}1704/**1705 * 上传Wp Adeasygo IAP信息1706 * @param msg1707 * @param session1708 * @param next1709 */1710pro.addWpAdeasygoPlayerBillingData = function(msg, session, next){1711 var uid = msg.uid;1712 var transactionId = msg.transactionId;1713 var e = null1714 if(!_.isString(uid) || _.isEmpty(uid.trim())){1715 e = new Error("uid 不合法")1716 return next(e, ErrorUtils.getError(e))1717 }1718 if(!_.isString(transactionId) || _.isEmpty(transactionId.trim())){1719 e = new Error("transactionId 不合法")1720 return next(e, ErrorUtils.getError(e))1721 }1722 this.request(session, 'addWpAdeasygoPlayerBillingData', [session.uid, uid, transactionId]).spread(function(playerData, productId){1723 next(null, {code:200, playerData:playerData, productId:productId})1724 }).catch(function(e){1725 next(null, ErrorUtils.getError(e))1726 })1727}1728/**1729 * 上传Android官方IAP信息1730 * @param msg1731 * @param session1732 * @param next1733 */1734pro.addAndroidOfficialPlayerBillingData = function(msg, session, next){1735 var receiptData = msg.receiptData1736 var receiptSignature = msg.receiptSignature1737 var e = null1738 if(!_.isString(receiptSignature) || _.isEmpty(receiptSignature.trim())){1739 e = new Error("receiptSignature 不合法")1740 next(e, ErrorUtils.getError(e))1741 return1742 }1743 if(!_.isString(receiptData) || _.isEmpty(receiptData.trim())){1744 e = new Error("receiptData 不合法")1745 next(e, ErrorUtils.getError(e))1746 return1747 }1748 var receiptObj = null;1749 try{1750 receiptObj = JSON.parse(receiptData);1751 }catch(e){1752 e = new Error("receiptData 不合法")1753 return next(e, ErrorUtils.getError(e))1754 }1755 var productId = receiptObj.productId1756 if(!productId){1757 e = new Error("receiptData 不合法")1758 return next(e, ErrorUtils.getError(e))1759 }1760 var transactionId = receiptObj.orderId1761 if(!transactionId){1762 e = new Error("receiptData 不合法")1763 return next(e, ErrorUtils.getError(e))1764 }1765 this.request(session, 'addAndroidOfficialPlayerBillingData', [session.uid, productId, transactionId, receiptData, receiptSignature]).then(function(playerData){1766 next(null, {code:200, playerData:playerData, productId:productId, transactionId:transactionId})1767 }).catch(function(e){1768 next(null, ErrorUtils.getError(e))1769 })1770}1771/**1772 * 上传Ios月卡IAP信息1773 * @param msg1774 * @param session1775 * @param next1776 */1777pro.addIosMonthcardBillingData = function(msg, session, next){1778 var receiptData = msg.receiptData1779 var e = null1780 if(!_.isString(receiptData) || _.isEmpty(receiptData.trim())){1781 e = new Error("receiptData 不合法")1782 next(e, ErrorUtils.getError(e))1783 return1784 }1785 var jsonString = new Buffer(receiptData, 'base64').toString();1786 var productIdMathResult = jsonString.match(/"product-id" = "(.*)";/)1787 var transactionIdMathResult = jsonString.match(/"transaction-id" = "(.*)";/)1788 if(!_.isArray(productIdMathResult) || productIdMathResult.length < 2){1789 e = new Error("receiptData 不合法")1790 next(e, ErrorUtils.getError(e))1791 return1792 }1793 if(!_.isArray(transactionIdMathResult) || transactionIdMathResult.length < 2){1794 e = new Error("receiptData 不合法")1795 next(e, ErrorUtils.getError(e))1796 return1797 }1798 var productId = productIdMathResult[1];1799 var transactionId = transactionIdMathResult[1];1800 this.request(session, 'addIosMonthcardBillingData', [session.uid, productId, transactionId, receiptData]).then(function(playerData){1801 next(null, {code:200, playerData:playerData, transactionId:transactionId})1802 }).catch(function(e){1803 next(null, ErrorUtils.getError(e))1804 })1805}1806/**1807 * 上传Wp月卡官方IAP信息1808 * @param msg1809 * @param session1810 * @param next1811 */1812pro.addWpOfficialMonthcardBillingData = function(msg, session, next){1813 var receiptData = msg.receiptData1814 var e = null1815 if(!_.isString(receiptData) || _.isEmpty(receiptData.trim())){1816 e = new Error("receiptData 不合法")1817 next(e, ErrorUtils.getError(e))1818 return1819 }1820 var doc = new DOMParser().parseFromString(receiptData);1821 if(!doc){1822 e = new Error("receiptData 不合法")1823 return next(e, ErrorUtils.getError(e))1824 }1825 var receipt = doc.getElementsByTagName('Receipt')[0];1826 if(!receipt){1827 e = new Error("receiptData 不合法")1828 return next(e, ErrorUtils.getError(e))1829 }1830 var productReceipt = receipt.getElementsByTagName('ProductReceipt')[0];1831 if(!productReceipt){1832 e = new Error("receiptData 不合法")1833 return next(e, ErrorUtils.getError(e))1834 }1835 var productId = productReceipt.getAttribute('ProductId');1836 if(!productId){1837 e = new Error("receiptData 不合法")1838 return next(e, ErrorUtils.getError(e))1839 }1840 var transactionId = productReceipt.getAttribute('Id');1841 if(!transactionId){1842 e = new Error("receiptData 不合法")1843 return next(e, ErrorUtils.getError(e))1844 }1845 this.request(session, 'addWpOfficialMonthcardBillingData', [session.uid, productId, transactionId, receiptData]).then(function(playerData){1846 next(null, {code:200, playerData:playerData, productId:productId, transactionId:transactionId})1847 }).catch(function(e){1848 next(null, ErrorUtils.getError(e))1849 })1850}1851/**1852 * 上传Wp月卡Adeasygo IAP信息1853 * @param msg1854 * @param session1855 * @param next1856 */1857pro.addWpAdeasygoMonthcardBillingData = function(msg, session, next){1858 var uid = msg.uid;1859 var transactionId = msg.transactionId;1860 var e = null1861 if(!_.isString(uid) || _.isEmpty(uid.trim())){1862 e = new Error("uid 不合法")1863 return next(e, ErrorUtils.getError(e))1864 }1865 if(!_.isString(transactionId) || _.isEmpty(transactionId.trim())){1866 e = new Error("transactionId 不合法")1867 return next(e, ErrorUtils.getError(e))1868 }1869 this.request(session, 'addWpAdeasygoMonthcardBillingData', [session.uid, uid, transactionId]).spread(function(playerData, productId){1870 next(null, {code:200, playerData:playerData, productId:productId})1871 }).catch(function(e){1872 next(null, ErrorUtils.getError(e))1873 })1874}1875/**1876 * 上传Android月卡官方IAP信息1877 * @param msg1878 * @param session1879 * @param next1880 */1881pro.addAndroidOfficialMonthcardBillingData = function(msg, session, next){1882 var receiptData = msg.receiptData1883 var receiptSignature = msg.receiptSignature1884 var e = null1885 if(!_.isString(receiptSignature) || _.isEmpty(receiptSignature.trim())){1886 e = new Error("receiptSignature 不合法")1887 next(e, ErrorUtils.getError(e))1888 return1889 }1890 if(!_.isString(receiptData) || _.isEmpty(receiptData.trim())){1891 e = new Error("receiptData 不合法")1892 next(e, ErrorUtils.getError(e))1893 return1894 }1895 var receiptObj = null;1896 try{1897 receiptObj = JSON.parse(receiptData);1898 }catch(e){1899 e = new Error("receiptData 不合法")1900 return next(e, ErrorUtils.getError(e))1901 }1902 var productId = receiptObj.productId1903 if(!productId){1904 e = new Error("receiptData 不合法")1905 return next(e, ErrorUtils.getError(e))1906 }1907 var transactionId = receiptObj.orderId1908 if(!transactionId){1909 e = new Error("receiptData 不合法")1910 return next(e, ErrorUtils.getError(e))1911 }1912 this.request(session, 'addAndroidOfficialMonthcardBillingData', [session.uid, productId, transactionId, receiptData, receiptSignature]).then(function(playerData){1913 next(null, {code:200, playerData:playerData, productId:productId, transactionId:transactionId})1914 }).catch(function(e){1915 next(null, ErrorUtils.getError(e))1916 })1917}1918/**1919 * 获取新玩家冲级奖励1920 * @param msg1921 * @param session1922 * @param next1923 */1924pro.getFirstIAPRewards = function(msg, session, next){1925 this.request(session, 'getFirstIAPRewards', [session.uid]).then(function(playerData){1926 next(null, {code:200, playerData:playerData})1927 }).catch(function(e){1928 next(null, ErrorUtils.getError(e))1929 })1930}1931/**1932 * 领取日常任务奖励1933 * @param msg1934 * @param session1935 * @param next1936 */1937pro.getDailyTaskRewards = function(msg, session, next){1938 this.request(session, 'getDailyTaskRewards', [session.uid]).then(function(playerData){1939 next(null, {code:200, playerData:playerData})1940 }).catch(function(e){1941 next(null, ErrorUtils.getError(e))1942 })1943}1944/**1945 * 领取成就任务奖励1946 * @param msg1947 * @param session1948 * @param next1949 */1950pro.getGrowUpTaskRewards = function(msg, session, next){1951 var taskType = msg.taskType1952 var taskId = msg.taskId1953 var e = null1954 if(!_.contains(Consts.GrowUpTaskTypes, taskType)){1955 e = new Error("taskType 不合法")1956 next(e, ErrorUtils.getError(e))1957 return1958 }1959 if(!_.isNumber(taskId) || taskId % 1 !== 0 || taskId < 0){1960 e = new Error("taskId 不合法")1961 next(e, ErrorUtils.getError(e))1962 return1963 }1964 this.request(session, 'getGrowUpTaskRewards', [session.uid, taskType, taskId]).then(function(playerData){1965 next(null, {code:200, playerData:playerData})1966 }).catch(function(e){1967 next(null, ErrorUtils.getError(e))1968 })1969}1970/**1971 * 获取联盟其他玩家赠送的礼品1972 * @param msg1973 * @param session1974 * @param next1975 */1976pro.getIapGift = function(msg, session, next){1977 var giftId = msg.giftId1978 var e = null1979 if(!_.isString(giftId) || !ShortId.isValid(giftId)){1980 e = new Error("giftId 不合法")1981 next(e, ErrorUtils.getError(e))1982 return1983 }1984 this.request(session, 'getIapGift', [session.uid, giftId]).then(function(playerData){1985 next(null, {code:200, playerData:playerData})1986 }).catch(function(e){1987 next(null, ErrorUtils.getError(e))1988 })1989}1990/**1991 * 获取服务器列表1992 * @param msg1993 * @param session1994 * @param next1995 */1996pro.getServers = function(msg, session, next){1997 this.request(session, 'getServers', [session.uid]).then(function(servers){1998 next(null, {code:200, servers:servers})1999 }).catch(function(e){2000 next(null, ErrorUtils.getError(e))2001 })2002}2003/**2004 * 切换服务器2005 * @param msg2006 * @param session2007 * @param next2008 */2009pro.switchServer = function(msg, session, next){2010 var serverId = msg.serverId2011 var e = null2012 if(!_.isString(serverId)){2013 e = new Error("serverId 不合法")2014 next(e, ErrorUtils.getError(e))2015 return2016 }2017 this.request(session, 'switchServer', [session.uid, serverId]).then(function(){2018 next(null, {code:200})2019 }).catch(function(e){2020 next(null, ErrorUtils.getError(e))2021 })2022}2023/**2024 * 设置玩家头像2025 * @param msg2026 * @param session2027 * @param next2028 */2029pro.setPlayerIcon = function(msg, session, next){2030 var icon = msg.icon2031 var e = null2032 if(!_.isNumber(icon) || icon % 1 !== 0 || icon < 1 || icon > 11){2033 e = new Error("icon 不合法")2034 next(e, ErrorUtils.getError(e))2035 return2036 }2037 this.request(session, 'setPlayerIcon', [session.uid, icon]).then(function(playerData){2038 next(null, {code:200, playerData:playerData})2039 }).catch(function(e){2040 next(null, ErrorUtils.getError(e))2041 })2042}2043/**2044 * 解锁玩家第二条队列2045 * @param msg2046 * @param session2047 * @param next2048 */2049pro.unlockPlayerSecondMarchQueue = function(msg, session, next){2050 this.request(session, 'unlockPlayerSecondMarchQueue', [session.uid]).then(function(playerData){2051 next(null, {code:200, playerData:playerData})2052 }).catch(function(e){2053 next(null, ErrorUtils.getError(e))2054 })2055}2056/**2057 * 初始化玩家数据2058 * @param msg2059 * @param session2060 * @param next2061 */2062pro.initPlayerData = function(msg, session, next){2063 var terrain = msg.terrain2064 var language = msg.language2065 var e = null2066 if(!_.contains(_.values(Consts.AllianceTerrain), terrain)){2067 e = new Error("terrain 不合法")2068 next(e, ErrorUtils.getError(e))2069 return2070 }2071 if(!_.contains(Consts.PlayerLanguage, language)){2072 e = new Error("language 不合法")2073 next(e, ErrorUtils.getError(e))2074 return2075 }2076 this.request(session, 'initPlayerData', [session.uid, terrain, language]).then(function(playerData){2077 next(null, {code:200, playerData:playerData})2078 }).catch(function(e){2079 next(null, ErrorUtils.getError(e))2080 })2081}2082/**2083 * 领取首次加入联盟奖励2084 * @param msg2085 * @param session2086 * @param next2087 */2088pro.getFirstJoinAllianceReward = function(msg, session, next){2089 var allianceId = session.get('allianceId');2090 var e = null2091 if(_.isEmpty(allianceId)){2092 e = ErrorUtils.playerNotJoinAlliance(session.uid)2093 next(e, ErrorUtils.getError(e))2094 return2095 }2096 this.request(session, 'getFirstJoinAllianceReward', [session.uid, allianceId]).then(function(playerData){2097 next(null, {code:200, playerData:playerData})2098 }).catch(function(e){2099 next(null, ErrorUtils.getError(e))2100 })2101}2102/**2103 * 获取玩家城墙血量2104 * @param msg2105 * @param session2106 * @param next2107 */2108pro.getPlayerWallInfo = function(msg, session, next){2109 var memberId = msg.memberId2110 var e = null2111 if(!ShortId.isValid(memberId)){2112 e = new Error("questId 不合法")2113 next(e, ErrorUtils.getError(e))2114 return2115 }2116 this.request(session, 'getPlayerWallInfo', [session.uid, memberId]).then(function(wallInfo){2117 next(null, {code:200, wallInfo:wallInfo})2118 }).catch(function(e){2119 next(null, ErrorUtils.getError(e))2120 })2121}2122/**2123 * 设置远程推送状态2124 * @param msg2125 * @param session2126 * @param next2127 */2128pro.setPushStatus = function(msg, session, next){2129 var type = msg.type2130 var status = msg.status2131 var e = null2132 if(!_.contains(Consts.PushTypes, type)){2133 e = new Error("type 不合法")2134 next(e, ErrorUtils.getError(e))2135 return2136 }2137 if(!_.isBoolean(status)){2138 e = new Error("status 不合法")2139 next(e, ErrorUtils.getError(e))2140 return2141 }2142 this.request(session, 'setPushStatus', [session.uid, type, status]).then(function(playerData){2143 next(null, {code:200, playerData:playerData})2144 }).catch(function(e){2145 next(null, ErrorUtils.getError(e))2146 })2147}2148/**2149 * 进攻PvE关卡2150 * @param msg2151 * @param session2152 * @param next2153 */2154pro.attackPveSection = function(msg, session, next){2155 var sectionName = msg.sectionName;2156 var dragonType = msg.dragonType;2157 var soldiers = msg.soldiers;2158 var e = null2159 if(!DataUtils.isPvESectionExist(sectionName)){2160 e = new Error("sectionName 不合法")2161 next(e, ErrorUtils.getError(e))2162 return2163 }2164 if(!DataUtils.isDragonTypeExist(dragonType)){2165 e = new Error("dragonType 不合法")2166 next(e, ErrorUtils.getError(e))2167 return2168 }2169 if(!_.isArray(soldiers)){2170 e = new Error("soldiers 不合法")2171 next(e, ErrorUtils.getError(e))2172 return2173 }2174 if(soldiers.length > DataUtils.getAllianceIntInit('maxTroopPerDragon')){2175 e = new Error("soldiers 不合法")2176 next(e, ErrorUtils.getError(e))2177 return2178 }2179 this.request(session, 'attackPveSection', [session.uid, sectionName, dragonType, soldiers]).spread(function(playerData, fightReport){2180 next(null, {code:200, playerData:playerData, fightReport:fightReport})2181 }).catch(function(e){2182 next(null, ErrorUtils.getError(e))2183 })2184}2185/**2186 * 获取关卡星级奖励2187 * @param msg2188 * @param session2189 * @param next2190 */2191pro.getPveStageReward = function(msg, session, next){2192 var stageName = msg.stageName;2193 var e = null2194 if(!DataUtils.isPvEStageExist(stageName)){2195 e = new Error("stageName 不合法")2196 next(e, ErrorUtils.getError(e))2197 return2198 }2199 this.request(session, 'getPveStageReward', [session.uid, stageName]).then(function(playerData){2200 next(null, {code:200, playerData:playerData})2201 }).catch(function(e){2202 next(null, ErrorUtils.getError(e))2203 })2204}2205/**2206 * 获取战报详情2207 * @param msg2208 * @param session2209 * @param next2210 */2211pro.getReportDetail = function(msg, session, next){2212 var self = this;2213 var memberId = msg.memberId;2214 var reportId = msg.reportId;2215 var e = null2216 if(!ShortId.isValid(memberId)){2217 e = new Error("memberId 不合法")2218 next(e, ErrorUtils.getError(e))2219 return2220 }2221 if(!ShortId.isValid(reportId)){2222 e = new Error("reportId 不合法")2223 next(e, ErrorUtils.getError(e))2224 return2225 }2226 self.app.get('Player').findById(memberId, 'serverId').then(function(doc){2227 if(!_.isObject(doc)){2228 return Promise.reject(ErrorUtils.playerNotExist(session.uid, memberId));2229 }2230 return self.request(session, 'getReportDetail', [session.uid, memberId, reportId], doc.serverId);2231 }).then(function(report){2232 next(null, {code:200, report:report})2233 }).catch(function(e){2234 next(null, ErrorUtils.getError(e))2235 })2236}2237/**2238 * 根据昵称搜索玩家2239 * @param msg2240 * @param session2241 * @param next2242 */2243pro.searchPlayerByName = function(msg, session, next){2244 var name = msg.name;2245 var fromIndex = msg.fromIndex;2246 var e = null;2247 if(!_.isString(name) || name.trim().length === 0 || name.trim().length > Define.InputLength.PlayerName){2248 e = new Error("name 不合法")2249 next(e, ErrorUtils.getError(e))2250 return2251 }2252 if(!_.isNumber(fromIndex) || fromIndex % 1 !== 0 || fromIndex < 0){2253 e = new Error("fromIndex 不合法")2254 next(e, ErrorUtils.getError(e))2255 return2256 }2257 this.request(session, 'searchPlayerByName', [session.uid, name, fromIndex]).spread(function(limit, playerDatas){2258 next(null, {code:200, limit:limit, playerDatas:playerDatas})2259 }).catch(function(e){2260 next(null, ErrorUtils.getError(e))2261 })2262}2263/**2264 * 获取服务器公告列表2265 * @param msg2266 * @param session2267 * @param next2268 */2269pro.getServerNotices = function(msg, session, next){2270 this.request(session, 'getServerNotices', []).then(function(notices){2271 next(null, {code:200, notices:notices})2272 }).catch(function(e){2273 next(null, ErrorUtils.getError(e))2274 })2275}2276/**2277 * 获取活动信息2278 * @param msg2279 * @param session2280 * @param next2281 */2282pro.getActivities = function(msg, session, next){2283 this.request(session, 'getActivities', []).then(function(activities){2284 next(null, {code:200, activities:activities})2285 }).catch(function(e){2286 next(null, ErrorUtils.getError(e))2287 })2288}2289/**2290 * 获取玩家活动积分奖励2291 * @param msg2292 * @param session2293 * @param next2294 */2295pro.getPlayerActivityScoreRewards = function(msg, session, next){2296 var rankType = msg.rankType;2297 if(!_.contains(DataUtils.getActivityTypes(), rankType)){2298 var e = new Error("rankType 不合法");2299 return next(e, ErrorUtils.getError(e));2300 }2301 this.request(session, 'getPlayerActivityScoreRewards', [session.uid, rankType]).then(function(playerData){2302 next(null, {code:200, playerData:playerData})2303 }).catch(function(e){2304 next(null, ErrorUtils.getError(e))2305 })2306}2307/**2308 * 获取玩家活动排名奖励2309 * @param msg2310 * @param session2311 * @param next2312 */2313pro.getPlayerActivityRankRewards = function(msg, session, next){2314 var rankType = msg.rankType;2315 if(!_.contains(DataUtils.getActivityTypes(), rankType)){2316 var e = new Error("rankType 不合法");2317 return next(e, ErrorUtils.getError(e));2318 }2319 this.request(session, 'getPlayerActivityRankRewards', [session.uid, rankType]).then(function(playerData){2320 next(null, {code:200, playerData:playerData})2321 }).catch(function(e){2322 next(null, ErrorUtils.getError(e))2323 })2324}2325/**2326 * 获取我的墨子信息2327 * @param msg2328 * @param session2329 * @param next2330 * @returns {*}2331 */2332pro.getMyModData = function(msg, session, next){2333 this.request(session, 'getMyModData', [session.uid]).then(function(modData){2334 next(null, {code:200, modData:modData})2335 }).catch(function(e){2336 next(null, ErrorUtils.getError(e))2337 })2338}2339/**2340 * 获取被禁言列表2341 * @param msg2342 * @param session2343 * @param next2344 * @returns {*}2345 */2346pro.getMutedPlayerList = function(msg, session, next){2347 this.request(session, 'getMutedPlayerList', [session.uid]).then(function(docs){2348 next(null, {code:200, datas:docs})2349 }).catch(function(e){2350 next(null, ErrorUtils.getError(e))2351 })2352}2353/**2354 * 禁言玩家2355 * @param msg2356 * @param session2357 * @param next2358 * @returns {*}2359 */2360pro.mutePlayer = function(msg, session, next){2361 var self = this;2362 var targetPlayerId = msg.targetPlayerId;2363 var muteMinutes = msg.muteMinutes;2364 var muteReason = msg.muteReason;2365 var e = null2366 if(!_.isString(targetPlayerId) || !ShortId.isValid(targetPlayerId)){2367 e = new Error("targetPlayerId 不合法")2368 return next(e, ErrorUtils.getError(e))2369 }2370 if(!_.isNumber(muteMinutes) || muteMinutes % 1 !== 0 || muteMinutes < 5 || muteMinutes > (60 * 6)){2371 e = new Error("muteMinutes 不合法")2372 return next(e, ErrorUtils.getError(e))2373 }2374 if(!_.isString(muteReason) || muteReason.trim().length === 0){2375 e = new Error("muteReason 不合法")2376 return next(e, ErrorUtils.getError(e))2377 }2378 self.app.get('Player').findById(targetPlayerId, 'serverId').then(function(doc){2379 if(!_.isObject(doc)){2380 return Promise.reject(ErrorUtils.playerNotExist(session.uid, targetPlayerId));2381 }2382 return self.request(session, 'mutePlayer', [session.uid, targetPlayerId, muteMinutes, muteReason], doc.serverId);2383 }).then(function(){2384 next(null, {code:200});2385 }).catch(function(e){2386 next(null, ErrorUtils.getError(e))2387 })2388}2389/**2390 * 提前解禁玩家2391 * @param msg2392 * @param session2393 * @param next2394 * @returns {*}2395 */2396pro.unMutePlayer = function(msg, session, next){2397 var self = this;2398 var targetPlayerId = msg.targetPlayerId;2399 var e = null2400 if(!_.isString(targetPlayerId) || !ShortId.isValid(targetPlayerId)){2401 e = new Error("targetPlayerId 不合法")2402 return next(e, ErrorUtils.getError(e))2403 }2404 self.app.get('Player').findById(targetPlayerId, 'serverId').then(function(doc){2405 if(!_.isObject(doc)){2406 return Promise.reject(ErrorUtils.playerNotExist(session.uid, targetPlayerId));2407 }2408 return self.request(session, 'unMutePlayer', [session.uid, targetPlayerId], doc.serverId);2409 }).then(function(){2410 next(null, {code:200})2411 }).catch(function(e){2412 next(null, ErrorUtils.getError(e))2413 })2414}2415/**2416 * 添加黑名单2417 * @param msg2418 * @param session2419 * @param next2420 * @returns {*}2421 */2422pro.addBlocked = function(msg, session, next){2423 var memberId = msg.memberId;2424 var memberName = msg.memberName;2425 var memberIcon = msg.memberIcon;2426 var e = null2427 if(!_.isString(memberId) || !ShortId.isValid(memberId)){2428 e = new Error("memberId 不合法")2429 return next(e, ErrorUtils.getError(e))2430 }2431 if(!_.isString(memberName) || memberName.trim().length === 0){2432 e = new Error("memberName 不合法")2433 return next(e, ErrorUtils.getError(e))2434 }2435 if(!_.isNumber(memberIcon) || memberIcon % 1 !== 0 || memberIcon < 1 || memberIcon > 11){2436 e = new Error("icon 不合法")2437 next(e, ErrorUtils.getError(e))2438 return2439 }2440 this.request(session, 'addBlocked', [session.uid, memberId, memberName, memberIcon]).then(function(playerData){2441 next(null, {code:200, playerData:playerData});2442 }).catch(function(e){2443 next(null, ErrorUtils.getError(e))2444 })2445}2446/**2447 * 禁言玩家2448 * @param msg2449 * @param session2450 * @param next2451 * @returns {*}2452 */2453pro.removeBlocked = function(msg, session, next){2454 var memberId = msg.memberId;2455 var e = null2456 if(!_.isString(memberId) || !ShortId.isValid(memberId)){2457 e = new Error("memberId 不合法")2458 return next(e, ErrorUtils.getError(e))2459 }2460 this.request(session, 'removeBlocked', [session.uid, memberId]).then(function(playerData){2461 next(null, {code:200, playerData:playerData});2462 }).catch(function(e){2463 next(null, ErrorUtils.getError(e))2464 })2465}2466/**2467 * 获取游戏状态信息2468 * @param msg2469 * @param session2470 * @param next2471 */2472pro.getGameInfo = function(msg, session, next){2473 this.request(session, 'getGameInfo', [session.uid]).then(function(serverInfo){2474 next(null, {code:200, serverInfo:serverInfo});2475 }).catch(function(e){2476 next(null, ErrorUtils.getError(e))2477 })2478}2479/**2480 * 获取累计充值奖励2481 * @param msg2482 * @param session2483 * @param next2484 */2485pro.getTotalIAPRewards = function(msg, session, next){2486 this.request(session, 'getTotalIAPRewards', [session.uid]).then(function(playerData){2487 next(null, {code:200, playerData:playerData});2488 }).catch(function(e){2489 next(null, ErrorUtils.getError(e))2490 })2491}2492/**2493 * 领取月卡每日奖励2494 * @param msg2495 * @param session2496 * @param next2497 */2498pro.getMothcardRewards = function(msg, session, next){2499 this.request(session, 'getMothcardRewards', [session.uid]).then(function(playerData){2500 next(null, {code:200, playerData:playerData});2501 }).catch(function(e){2502 next(null, ErrorUtils.getError(e))2503 })...

Full Screen

Full Screen

allianceHandler.js

Source:allianceHandler.js Github

copy

Full Screen

...34 var flag = msg.flag35 var e = null36 if(!_.isString(name) || name.trim().length === 0 || name.trim().length > Define.InputLength.AllianceName){37 e = new Error("name 不合法")38 next(e, ErrorUtils.getError(e))39 return40 }41 if(!_.isString(tag) || tag.trim().length === 0 || tag.trim().length > Define.InputLength.AllianceTag){42 e = new Error("tag 不合法")43 next(e, ErrorUtils.getError(e))44 return45 }46 if(!_.contains(Consts.AllianceCountry, country)){47 e = new Error("country 不合法")48 next(e, ErrorUtils.getError(e))49 return50 }51 if(!_.contains(Consts.AllianceTerrain, terrain)){52 e = new Error("terrain 不合法")53 next(e, ErrorUtils.getError(e))54 return55 }56 if(!_.isString(flag)){57 e = new Error("flag 不合法")58 next(e, ErrorUtils.getError(e))59 return60 }61 this.request(session, 'createAlliance', [session.uid, name, tag, country, terrain, flag]).spread(function(playerData, allianceData, mapData, mapIndexData){62 next(null, {code:200, playerData:playerData, allianceData:allianceData, mapData:mapData, mapIndexData:mapIndexData})63 }).catch(function(e){64 next(null, ErrorUtils.getError(e))65 })66}67/**68 * 发送联盟邮件69 * @param msg70 * @param session71 * @param next72 */73pro.sendAllianceMail = function(msg, session, next){74 var allianceId = session.get('allianceId');75 var title = msg.title76 var content = msg.content77 var e = null78 if(_.isEmpty(allianceId)){79 e = ErrorUtils.playerNotJoinAlliance(session.uid)80 next(e, ErrorUtils.getError(e))81 return82 }83 if(!_.isString(title)){84 e = new Error("title 不合法")85 next(e, ErrorUtils.getError(e))86 return87 }88 if(!_.isString(content)){89 e = new Error("content 不合法")90 next(e, ErrorUtils.getError(e))91 return92 }93 this.request(session, 'sendAllianceMail', [session.uid, allianceId, title, content]).then(function(){94 next(null, {code:200})95 }).catch(function(e){96 next(null, ErrorUtils.getError(e))97 })98}99/**100 * 主动获取玩家联盟的信息101 * @param msg102 * @param session103 * @param next104 */105pro.getMyAllianceData = function(msg, session, next){106 var allianceId = session.get('allianceId');107 var e = null108 if(_.isEmpty(allianceId)){109 e = ErrorUtils.playerNotJoinAlliance(session.uid)110 next(e, ErrorUtils.getError(e))111 return112 }113 this.request(session, 'getMyAllianceData', [session.uid, allianceId]).then(function(allianceData){114 next(null, {code:200, allianceData:allianceData})115 }).catch(function(e){116 next(null, ErrorUtils.getError(e))117 })118}119/**120 * 根据Tag搜索联盟121 * @param msg122 * @param session123 * @param next124 */125pro.getCanDirectJoinAlliances = function(msg, session, next){126 var fromIndex = msg.fromIndex127 var e = null128 if(!_.isNumber(fromIndex) || fromIndex < 0 || fromIndex % 10 != 0){129 e = new Error("fromIndex 不合法")130 next(e, ErrorUtils.getError(e))131 return132 }133 this.request(session, 'getCanDirectJoinAlliances', [session.uid, fromIndex]).then(function(allianceDatas){134 next(null, {code:200, allianceDatas:allianceDatas})135 }).catch(function(e){136 next(null, ErrorUtils.getError(e))137 })138}139/**140 * 根据Tag搜索联盟141 * @param msg142 * @param session143 * @param next144 */145pro.searchAllianceByTag = function(msg, session, next){146 var tag = msg.tag147 var e = null148 if(!_.isString(tag) || tag.trim().length === 0 || tag.trim().length > Define.InputLength.AllianceTag){149 e = new Error("tag 不合法")150 next(e, ErrorUtils.getError(e))151 return152 }153 this.request(session, 'searchAllianceByTag', [session.uid, tag]).then(function(allianceDatas){154 next(null, {code:200, allianceDatas:allianceDatas})155 }).catch(function(e){156 next(null, ErrorUtils.getError(e))157 })158}159/**160 * 编辑联盟基础信息161 * @param msg162 * @param session163 * @param next164 */165pro.editAllianceBasicInfo = function(msg, session, next){166 var allianceId = session.get('allianceId');167 var name = msg.name168 var tag = msg.tag169 var country = msg.country170 var flag = msg.flag171 var e = null172 if(_.isEmpty(allianceId)){173 e = ErrorUtils.playerNotJoinAlliance(session.uid)174 next(e, ErrorUtils.getError(e))175 return176 }177 if(!_.isString(name) || name.trim().length === 0 || name.trim().length > Define.InputLength.AllianceName){178 e = new Error("name 不合法")179 next(e, ErrorUtils.getError(e))180 return181 }182 if(!_.isString(tag) || tag.trim().length === 0 || tag.trim().length > Define.InputLength.AllianceTag){183 e = new Error("tag 不合法")184 next(e, ErrorUtils.getError(e))185 return186 }187 if(!_.contains(Consts.AllianceCountry, country)){188 e = new Error("country 不合法")189 next(e, ErrorUtils.getError(e))190 return191 }192 if(!_.isString(flag) || flag.trim().length === 0 || flag.trim().length > Define.InputLength.AllianceFlag){193 e = new Error("flag 不合法")194 next(e, ErrorUtils.getError(e))195 return196 }197 this.request(session, 'editAllianceBasicInfo', [session.uid, allianceId, name, tag, country, flag]).then(function(playerData){198 next(null, {code:200, playerData:playerData})199 }).catch(function(e){200 next(null, ErrorUtils.getError(e))201 })202}203/**204 * 编辑联盟地形205 * @param msg206 * @param session207 * @param next208 */209pro.editAllianceTerrian = function(msg, session, next){210 var allianceId = session.get('allianceId');211 var playerName = session.get("name")212 var terrain = msg.terrain213 var e = null214 if(_.isEmpty(allianceId)){215 e = ErrorUtils.playerNotJoinAlliance(session.uid)216 next(e, ErrorUtils.getError(e))217 return218 }219 if(!_.contains(Consts.AllianceTerrain, terrain)){220 e = new Error("terrain 不合法")221 next(e, ErrorUtils.getError(e))222 return223 }224 this.request(session, 'editAllianceTerrian', [session.uid, playerName, allianceId, terrain]).then(function(){225 next(null, {code:200})226 }).catch(function(e){227 next(null, ErrorUtils.getError(e))228 })229}230/**231 * 编辑联盟公告232 * @param msg233 * @param session234 * @param next235 */236pro.editAllianceNotice = function(msg, session, next){237 var allianceId = session.get('allianceId');238 var playerName = session.get("name")239 var notice = msg.notice240 var e = null241 if(_.isEmpty(allianceId)){242 e = ErrorUtils.playerNotJoinAlliance(session.uid)243 next(e, ErrorUtils.getError(e))244 return245 }246 if(!_.isString(notice) || notice.trim().length > Define.InputLength.AllianceNotice){247 e = new Error("notice 不合法")248 next(e, ErrorUtils.getError(e))249 return250 }251 this.request(session, 'editAllianceNotice', [session.uid, playerName, allianceId, notice]).then(function(){252 next(null, {code:200})253 }).catch(function(e){254 next(null, ErrorUtils.getError(e))255 })256}257/**258 * 编辑联盟描述259 * @param msg260 * @param session261 * @param next262 */263pro.editAllianceDescription = function(msg, session, next){264 var allianceId = session.get('allianceId');265 var playerName = session.get('name')266 var description = msg.description267 var e = null268 if(_.isEmpty(allianceId)){269 e = ErrorUtils.playerNotJoinAlliance(session.uid)270 next(e, ErrorUtils.getError(e))271 return272 }273 if(!_.isString(description) || description.trim().length > Define.InputLength.AllianceDesc){274 e = new Error("description 不合法")275 next(e, ErrorUtils.getError(e))276 return277 }278 this.request(session, 'editAllianceDescription', [session.uid, playerName, allianceId, description]).then(function(){279 next(null, {code:200})280 }).catch(function(e){281 next(null, ErrorUtils.getError(e))282 })283}284/**285 * 编辑联盟加入方式286 * @param msg287 * @param session288 * @param next289 */290pro.editAllianceJoinType = function(msg, session, next){291 var allianceId = session.get('allianceId');292 var joinType = msg.joinType293 var e = null294 if(_.isEmpty(allianceId)){295 e = ErrorUtils.playerNotJoinAlliance(session.uid)296 next(e, ErrorUtils.getError(e))297 return298 }299 if(!_.contains(Consts.AllianceJoinType, joinType)){300 e = new Error("joinType 不合法")301 next(e, ErrorUtils.getError(e))302 return303 }304 this.request(session, 'editAllianceJoinType', [session.uid, allianceId, joinType]).then(function(){305 next(null, {code:200})306 }).catch(function(e){307 next(null, ErrorUtils.getError(e))308 })309}310/**311 * 修改联盟某个玩家的职位312 * @param msg313 * @param session314 * @param next315 */316pro.editAllianceMemberTitle = function(msg, session, next){317 var allianceId = session.get('allianceId');318 var memberId = msg.memberId319 var title = msg.title320 var e = null321 if(_.isEmpty(allianceId)){322 e = ErrorUtils.playerNotJoinAlliance(session.uid)323 next(e, ErrorUtils.getError(e))324 return325 }326 if(!_.isString(memberId) || !ShortId.isValid(memberId)){327 e = new Error("memberId 不合法")328 next(e, ErrorUtils.getError(e))329 return330 }331 if(!_.contains(Consts.AllianceTitle, title)){332 e = new Error("title 不合法")333 next(e, ErrorUtils.getError(e))334 return335 }336 if(_.isEqual(session.uid, memberId)){337 e = new Error("不能修改玩家自己的职位")338 next(e, ErrorUtils.getError(e))339 return340 }341 this.request(session, 'editAllianceMemberTitle', [session.uid, allianceId, memberId, title]).then(function(){342 next(null, {code:200})343 }).catch(function(e){344 next(null, ErrorUtils.getError(e))345 })346}347/**348 * 将玩家踢出联盟349 * @param msg350 * @param session351 * @param next352 */353pro.kickAllianceMemberOff = function(msg, session, next){354 var allianceId = session.get('allianceId');355 var memberId = msg.memberId356 var e = null357 if(_.isEmpty(allianceId)){358 e = ErrorUtils.playerNotJoinAlliance(session.uid)359 next(e, ErrorUtils.getError(e))360 return361 }362 if(!_.isString(memberId) || !ShortId.isValid(memberId)){363 e = new Error("memberId 不合法")364 next(e, ErrorUtils.getError(e))365 return366 }367 if(_.isEqual(session.uid, memberId)){368 e = new Error("不能将自己踢出联盟")369 next(e, ErrorUtils.getError(e))370 return371 }372 this.request(session, 'kickAllianceMemberOff', [session.uid, allianceId, memberId]).then(function(){373 next(null, {code:200})374 }).catch(function(e){375 next(null, ErrorUtils.getError(e))376 })377}378/**379 * 移交盟主职位380 * @param msg381 * @param session382 * @param next383 */384pro.handOverAllianceArchon = function(msg, session, next){385 var allianceId = session.get('allianceId');386 var memberId = msg.memberId387 var e = null388 if(_.isEmpty(allianceId)){389 e = ErrorUtils.playerNotJoinAlliance(session.uid)390 next(e, ErrorUtils.getError(e))391 return392 }393 if(!_.isString(memberId) || !ShortId.isValid(memberId)){394 e = new Error("memberId 不合法")395 next(e, ErrorUtils.getError(e))396 return397 }398 if(_.isEqual(session.uid, memberId)){399 e = new Error("不能将盟主职位移交给自己")400 next(e, ErrorUtils.getError(e))401 return402 }403 this.request(session, 'handOverAllianceArchon', [session.uid, allianceId, memberId]).then(function(){404 next(null, {code:200})405 }).catch(function(e){406 next(null, ErrorUtils.getError(e))407 })408}409/**410 * 退出联盟411 * @param msg412 * @param session413 * @param next414 */415pro.quitAlliance = function(msg, session, next){416 var allianceId = session.get('allianceId');417 var e = null418 if(_.isEmpty(allianceId)){419 e = ErrorUtils.playerNotJoinAlliance(session.uid)420 next(e, ErrorUtils.getError(e))421 return422 }423 this.request(session, 'quitAlliance', [session.uid, allianceId]).then(function(playerData){424 next(null, {code:200, playerData:playerData})425 }).catch(function(e){426 next(null, ErrorUtils.getError(e))427 })428}429/**430 * 直接加入某联盟431 * @param msg432 * @param session433 * @param next434 */435pro.joinAllianceDirectly = function(msg, session, next){436 var allianceId = msg.allianceId437 var e = null438 if(!_.isString(allianceId) || !ShortId.isValid(allianceId)){439 e = new Error("allianceId 不合法")440 next(e, ErrorUtils.getError(e))441 return442 }443 this.request(session, 'joinAllianceDirectly', [session.uid, allianceId]).spread(function(playerData, allianceData, mapData, mapIndexData){444 next(null, {code:200, playerData:playerData, allianceData:allianceData, mapData:mapData, mapIndexData:mapIndexData})445 }).catch(function(e){446 next(null, ErrorUtils.getError(e))447 })448}449/**450 * 申请加入联盟451 * @param msg452 * @param session453 * @param next454 */455pro.requestToJoinAlliance = function(msg, session, next){456 var allianceId = msg.allianceId457 var e = null458 if(!_.isString(allianceId) || !ShortId.isValid(allianceId)){459 e = new Error("allianceId 不合法")460 next(e, ErrorUtils.getError(e))461 return462 }463 this.request(session, 'requestToJoinAlliance', [session.uid, allianceId]).then(function(playerData){464 next(null, {code:200, playerData:playerData})465 }).catch(function(e){466 next(null, ErrorUtils.getError(e))467 })468}469/**470 * 取消对某联盟的申请471 * @param msg472 * @param session473 * @param next474 */475pro.cancelJoinAllianceRequest = function(msg, session, next){476 var allianceId = msg.allianceId477 var e = null478 if(!_.isString(allianceId) || !ShortId.isValid(allianceId)){479 e = new Error("allianceId 不合法")480 next(e, ErrorUtils.getError(e))481 return482 }483 this.request(session, 'cancelJoinAllianceRequest', [session.uid, allianceId]).then(function(playerData){484 next(null, {code:200, playerData:playerData})485 }).catch(function(e){486 next(null, ErrorUtils.getError(e))487 })488}489/**490 * 同意加入联盟申请491 * @param msg492 * @param session493 * @param next494 */495pro.approveJoinAllianceRequest = function(msg, session, next){496 var allianceId = session.get('allianceId');497 var requestEventId = msg.requestEventId498 var e = null499 if(_.isEmpty(allianceId)){500 e = ErrorUtils.playerNotJoinAlliance(session.uid)501 next(e, ErrorUtils.getError(e))502 return503 }504 if(!_.isString(requestEventId) || !ShortId.isValid(requestEventId)){505 e = new Error("requestEventId 不合法")506 next(e, ErrorUtils.getError(e))507 return508 }509 this.request(session, 'approveJoinAllianceRequest', [session.uid, allianceId, requestEventId]).then(function(){510 next(null, {code:200})511 }).catch(function(e){512 next(null, ErrorUtils.getError(e))513 })514}515/**516 * 删除加入联盟申请事件517 * @param msg518 * @param session519 * @param next520 */521pro.removeJoinAllianceReqeusts = function(msg, session, next){522 var allianceId = session.get('allianceId');523 var requestEventIds = msg.requestEventIds524 var e = null525 if(_.isEmpty(allianceId)){526 e = ErrorUtils.playerNotJoinAlliance(session.uid)527 next(e, ErrorUtils.getError(e))528 return529 }530 if(!_.isArray(requestEventIds) || requestEventIds.length == 0){531 e = new Error("requestEventIds 不合法")532 next(e, ErrorUtils.getError(e))533 return534 }535 for(var i = 0; i < requestEventIds; i++){536 if(!ShortId.isValid(requestEventIds[i])){537 e = new Error("requestEventIds 不合法")538 next(e, ErrorUtils.getError(e))539 return540 }541 }542 this.request(session, 'removeJoinAllianceReqeusts', [session.uid, allianceId, requestEventIds]).then(function(){543 next(null, {code:200})544 }).catch(function(e){545 next(null, ErrorUtils.getError(e))546 })547}548/**549 * 邀请玩家加入联盟550 * @param msg551 * @param session552 * @param next553 */554pro.inviteToJoinAlliance = function(msg, session, next){555 var allianceId = session.get('allianceId');556 var memberId = msg.memberId557 var e = null558 if(_.isEmpty(allianceId)){559 e = ErrorUtils.playerNotJoinAlliance(session.uid)560 next(e, ErrorUtils.getError(e))561 return562 }563 if(!_.isString(memberId) || !ShortId.isValid(memberId)){564 e = new Error("memberId 不合法")565 next(e, ErrorUtils.getError(e))566 return567 }568 if(_.isEqual(session.uid, memberId)){569 e = new Error("不能邀请自己加入联盟")570 next(e, ErrorUtils.getError(e))571 return572 }573 this.request(session, 'inviteToJoinAlliance', [session.uid, allianceId, memberId]).then(function(){574 next(null, {code:200})575 }).catch(function(e){576 next(null, ErrorUtils.getError(e))577 })578}579/**580 * 处理加入联盟邀请581 * @param msg582 * @param session583 * @param next584 */585pro.handleJoinAllianceInvite = function(msg, session, next){586 var allianceId = msg.allianceId587 var agree = msg.agree588 var e = null589 if(!_.isString(allianceId) || !ShortId.isValid(allianceId)){590 e = new Error("allianceId 不合法")591 next(e, ErrorUtils.getError(e))592 return593 }594 if(!_.isBoolean(agree)){595 e = new Error("agree 不合法")596 next(e, ErrorUtils.getError(e))597 return598 }599 this.request(session, 'handleJoinAllianceInvite', [session.uid, allianceId, agree]).spread(function(playerData, allianceData, mapData, mapIndexData){600 next(null, {code:200, playerData:playerData, allianceData:allianceData, mapData:mapData, mapIndexData:mapIndexData})601 }).catch(function(e){602 next(null, ErrorUtils.getError(e))603 })604}605/**606 * 购买联盟盟主职位607 * @param msg608 * @param session609 * @param next610 */611pro.buyAllianceArchon = function(msg, session, next){612 var allianceId = session.get('allianceId');613 var e = null614 if(_.isEmpty(allianceId)){615 e = ErrorUtils.playerNotJoinAlliance(session.uid)616 next(e, ErrorUtils.getError(e))617 return618 }619 this.request(session, 'buyAllianceArchon', [session.uid, allianceId]).then(function(playerData){620 next(null, {code:200, playerData:playerData})621 }).catch(function(e){622 next(null, ErrorUtils.getError(e))623 })624}625/**626 * 请求加速627 * @param msg628 * @param session629 * @param next630 */631pro.requestAllianceToSpeedUp = function(msg, session, next){632 var allianceId = session.get('allianceId');633 var eventType = msg.eventType634 var eventId = msg.eventId635 var e = null636 if(_.isEmpty(allianceId)){637 e = ErrorUtils.playerNotJoinAlliance(session.uid)638 next(e, ErrorUtils.getError(e))639 return640 }641 if(!_.contains(Consts.AllianceHelpEventType, eventType)){642 e = new Error("eventType 不合法")643 next(e, ErrorUtils.getError(e))644 return645 }646 if(!_.isString(eventId) || !ShortId.isValid(eventId)){647 e = new Error("eventId 不合法")648 next(e, ErrorUtils.getError(e))649 return650 }651 this.request(session, 'requestAllianceToSpeedUp', [session.uid, allianceId, eventType, eventId]).spread(function(playerData, allianceData){652 next(null, {code:200, playerData:playerData, allianceData:allianceData})653 }).catch(function(e){654 next(null, ErrorUtils.getError(e))655 })656}657/**658 * 协助玩家加速659 * @param msg660 * @param session661 * @param next662 */663pro.helpAllianceMemberSpeedUp = function(msg, session, next){664 var allianceId = session.get('allianceId');665 var eventId = msg.eventId666 var e = null667 if(_.isEmpty(allianceId)){668 e = ErrorUtils.playerNotJoinAlliance(session.uid)669 next(e, ErrorUtils.getError(e))670 return671 }672 if(!_.isString(eventId) || !ShortId.isValid(eventId)){673 e = new Error("eventId 不合法")674 next(e, ErrorUtils.getError(e))675 return676 }677 this.request(session, 'helpAllianceMemberSpeedUp', [session.uid, allianceId, eventId]).spread(function(playerData, allianceData){678 next(null, {code:200, playerData:playerData, allianceData:allianceData})679 }).catch(function(e){680 next(null, ErrorUtils.getError(e))681 })682}683/**684 * 协助所有玩家加速685 * @param msg686 * @param session687 * @param next688 */689pro.helpAllAllianceMemberSpeedUp = function(msg, session, next){690 var allianceId = session.get('allianceId');691 var e = null692 if(_.isEmpty(allianceId)){693 e = ErrorUtils.playerNotJoinAlliance(session.uid)694 next(e, ErrorUtils.getError(e))695 return696 }697 this.request(session, 'helpAllAllianceMemberSpeedUp', [session.uid, allianceId]).spread(function(playerData, allianceData){698 next(null, {code:200, playerData:playerData, allianceData:allianceData})699 }).catch(function(e){700 next(null, ErrorUtils.getError(e))701 })702}703/**704 * 联盟捐赠705 * @param msg706 * @param session707 * @param next708 */709pro.donateToAlliance = function(msg, session, next){710 var allianceId = session.get('allianceId');711 var donateType = msg.donateType712 var e = null713 if(_.isEmpty(allianceId)){714 e = ErrorUtils.playerNotJoinAlliance(session.uid)715 next(e, ErrorUtils.getError(e))716 return717 }718 if(!DataUtils.hasAllianceDonateType(donateType)){719 e = new Error("donateType 不合法")720 next(e, ErrorUtils.getError(e))721 return722 }723 this.request(session, 'donateToAlliance', [session.uid, allianceId, donateType]).then(function(playerData){724 next(null, {code:200, playerData:playerData})725 }).catch(function(e){726 next(null, ErrorUtils.getError(e))727 })728}729/**730 * 升级联盟建筑731 * @param msg732 * @param session733 * @param next734 */735pro.upgradeAllianceBuilding = function(msg, session, next){736 var allianceId = session.get('allianceId');737 var buildingName = msg.buildingName738 var e = null739 if(_.isEmpty(allianceId)){740 e = ErrorUtils.playerNotJoinAlliance(session.uid)741 next(e, ErrorUtils.getError(e))742 return743 }744 if(!_.contains(Consts.AllianceBuildingNames, buildingName)){745 e = new Error("buildingName 不合法")746 next(e, ErrorUtils.getError(e))747 return748 }749 this.request(session, 'upgradeAllianceBuilding', [session.uid, allianceId, buildingName]).then(function(){750 next(null, {code:200})751 }).catch(function(e){752 next(null, ErrorUtils.getError(e))753 })754}755/**756 * 升级联盟村落757 * @param msg758 * @param session759 * @param next760 */761pro.upgradeAllianceVillage = function(msg, session, next){762 var allianceId = session.get('allianceId');763 var villageType = msg.villageType764 var e = null765 if(_.isEmpty(allianceId)){766 e = ErrorUtils.playerNotJoinAlliance(session.uid)767 next(e, ErrorUtils.getError(e))768 return769 }770 if(!DataUtils.isAllianceVillageTypeLegal(villageType)){771 e = new Error("villageType 不合法")772 next(e, ErrorUtils.getError(e))773 return774 }775 this.request(session, 'upgradeAllianceVillage', [session.uid, allianceId, villageType]).then(function(){776 next(null, {code:200})777 }).catch(function(e){778 next(null, ErrorUtils.getError(e))779 })780}781/**782 * 激活联盟圣地事件783 * @param msg784 * @param session785 * @param next786 */787pro.activateAllianceShrineStage = function(msg, session, next){788 var allianceId = session.get('allianceId');789 var stageName = msg.stageName790 var e = null791 if(_.isEmpty(allianceId)){792 e = ErrorUtils.playerNotJoinAlliance(session.uid)793 next(e, ErrorUtils.getError(e))794 return795 }796 if(!DataUtils.isAllianceShrineStageNameLegal(stageName)){797 e = new Error("stageName 不合法")798 next(e, ErrorUtils.getError(e))799 return800 }801 this.request(session, 'activateAllianceShrineStage', [session.uid, allianceId, stageName]).then(function(){802 next(null, {code:200})803 }).catch(function(e){804 next(null, ErrorUtils.getError(e))805 })806}807/**808 * 进攻联盟圣地809 * @param msg810 * @param session811 * @param next812 */813pro.attackAllianceShrine = function(msg, session, next){814 var allianceId = session.get('allianceId');815 var shrineEventId = msg.shrineEventId816 var dragonType = msg.dragonType817 var soldiers = msg.soldiers818 var e = null819 if(_.isEmpty(allianceId)){820 e = ErrorUtils.playerNotJoinAlliance(session.uid)821 next(e, ErrorUtils.getError(e))822 return823 }824 if(!_.isString(shrineEventId)){825 e = new Error("shrineEventId 不合法")826 next(e, ErrorUtils.getError(e))827 return828 }829 if(!DataUtils.isDragonTypeExist(dragonType)){830 e = new Error("dragonType 不合法")831 next(e, ErrorUtils.getError(e))832 return833 }834 if(!_.isArray(soldiers)){835 e = new Error("soldiers 不合法")836 next(e, ErrorUtils.getError(e))837 return838 }839 this.request(session, 'attackAllianceShrine', [session.uid, allianceId, shrineEventId, dragonType, soldiers]).then(function(playerData){840 next(null, {code:200, playerData:playerData})841 }).catch(function(e){842 next(null, ErrorUtils.getError(e))843 })844}845/**846 * 查找合适的联盟进行战斗847 * @param msg848 * @param session849 * @param next850 */851pro.attackAlliance = function(msg, session, next){852 var allianceId = session.get('allianceId');853 var targetAllianceId = msg.targetAllianceId;854 var e = null855 if(_.isEmpty(allianceId)){856 e = ErrorUtils.playerNotJoinAlliance(session.uid)857 next(e, ErrorUtils.getError(e))858 return859 }860 if(!_.isString(targetAllianceId) || !ShortId.isValid(targetAllianceId) || allianceId === targetAllianceId){861 e = new Error("targetAllianceId 不合法")862 next(e, ErrorUtils.getError(e))863 return864 }865 this.request(session, 'attackAlliance', [session.uid, allianceId, targetAllianceId]).then(function(){866 next(null, {code:200})867 }).catch(function(e){868 next(null, ErrorUtils.getError(e))869 })870}871/**872 * 获取联盟可视化数据873 * @param msg874 * @param session875 * @param next876 */877pro.getAllianceViewData = function(msg, session, next){878 var targetAllianceId = msg.targetAllianceId879 var e = null880 if(!_.isString(targetAllianceId)){881 e = new Error("targetAllianceId 不合法")882 next(e, ErrorUtils.getError(e))883 return884 }885 this.request(session, 'getAllianceViewData', [session.uid, targetAllianceId]).then(function(allianceViewData){886 next(null, {code:200, allianceViewData:allianceViewData})887 }).catch(function(e){888 next(null, ErrorUtils.getError(e))889 })890}891/**892 * 根据Tag搜索联盟战斗数据893 * @param msg894 * @param session895 * @param next896 */897pro.searchAllianceInfoByTag = function(msg, session, next){898 var tag = msg.tag899 var e = null900 if(!_.isString(tag)){901 e = new Error("tag 不合法")902 next(e, ErrorUtils.getError(e))903 return904 }905 this.request(session, 'searchAllianceInfoByTag', [session.uid, tag]).then(function(allianceInfos){906 next(null, {code:200, allianceInfos:allianceInfos})907 }).catch(function(e){908 next(null, ErrorUtils.getError(e))909 })910}911/**912 * 协助联盟其他玩家防御913 * @param msg914 * @param session915 * @param next916 */917pro.helpAllianceMemberDefence = function(msg, session, next){918 var allianceId = session.get('allianceId');919 var dragonType = msg.dragonType920 var soldiers = msg.soldiers921 var targetPlayerId = msg.targetPlayerId922 var e = null923 if(_.isEmpty(allianceId)){924 e = ErrorUtils.playerNotJoinAlliance(session.uid)925 next(e, ErrorUtils.getError(e))926 return927 }928 if(!DataUtils.isDragonTypeExist(dragonType)){929 e = new Error("dragonType 不合法")930 next(e, ErrorUtils.getError(e))931 return932 }933 if(!_.isArray(soldiers)){934 e = new Error("soldiers 不合法")935 next(e, ErrorUtils.getError(e))936 return937 }938 if(!_.isString(targetPlayerId) || !ShortId.isValid(targetPlayerId)){939 e = new Error("targetPlayerId 不合法")940 next(e, ErrorUtils.getError(e))941 return942 }943 if(_.isEqual(session.uid, targetPlayerId)){944 e = new Error("不能对自己协防")945 next(e, ErrorUtils.getError(e))946 return947 }948 this.request(session, 'helpAllianceMemberDefence', [session.uid, allianceId, dragonType, soldiers, targetPlayerId]).then(function(playerData){949 next(null, {code:200, playerData:playerData})950 }).catch(function(e){951 next(null, ErrorUtils.getError(e))952 })953}954/**955 * 从被协防的联盟成员城市撤兵956 * @param msg957 * @param session958 * @param next959 */960pro.retreatFromBeHelpedAllianceMember = function(msg, session, next){961 var allianceId = session.get('allianceId');962 var beHelpedPlayerId = msg.beHelpedPlayerId963 var e = null964 if(_.isEmpty(allianceId)){965 e = ErrorUtils.playerNotJoinAlliance(session.uid)966 next(e, ErrorUtils.getError(e))967 return968 }969 if(!_.isString(beHelpedPlayerId) || !ShortId.isValid(beHelpedPlayerId)){970 e = new Error("beHelpedPlayerId 不合法")971 next(e, ErrorUtils.getError(e))972 return973 }974 if(_.isEqual(session.uid, beHelpedPlayerId)){975 e = new Error("不能从自己的城市撤销协防部队")976 next(e, ErrorUtils.getError(e))977 return978 }979 this.request(session, 'retreatFromBeHelpedAllianceMember', [session.uid, allianceId, beHelpedPlayerId]).then(function(playerData){980 next(null, {code:200, playerData:playerData})981 }).catch(function(e){982 next(null, ErrorUtils.getError(e))983 })984}985/**986 * 突袭玩家城市987 * @param msg988 * @param session989 * @param next990 */991pro.strikePlayerCity = function(msg, session, next){992 var allianceId = session.get('allianceId');993 var dragonType = msg.dragonType994 var defenceAllianceId = msg.defenceAllianceId;995 var defencePlayerId = msg.defencePlayerId;996 var e = null997 if(_.isEmpty(allianceId)){998 e = ErrorUtils.playerNotJoinAlliance(session.uid)999 next(e, ErrorUtils.getError(e))1000 return1001 }1002 if(!DataUtils.isDragonTypeExist(dragonType)){1003 e = new Error("dragonType 不合法")1004 next(e, ErrorUtils.getError(e))1005 return1006 }1007 if(!_.isString(defenceAllianceId) || !ShortId.isValid(defenceAllianceId)){1008 e = new Error("defenceAllianceId 不合法")1009 next(e, ErrorUtils.getError(e))1010 return1011 }1012 if(!_.isString(defencePlayerId) || !ShortId.isValid(defencePlayerId)){1013 e = new Error("defencePlayerId 不合法")1014 next(e, ErrorUtils.getError(e))1015 return1016 }1017 this.request(session, 'strikePlayerCity', [session.uid, allianceId, dragonType, defenceAllianceId, defencePlayerId]).then(function(playerData){1018 next(null, {code:200, playerData:playerData})1019 }).catch(function(e){1020 next(null, ErrorUtils.getError(e))1021 })1022}1023/**1024 * 进攻玩家城市1025 * @param msg1026 * @param session1027 * @param next1028 */1029pro.attackPlayerCity = function(msg, session, next){1030 var allianceId = session.get('allianceId');1031 var dragonType = msg.dragonType1032 var soldiers = msg.soldiers1033 var defenceAllianceId = msg.defenceAllianceId;1034 var defencePlayerId = msg.defencePlayerId;1035 var e = null1036 if(_.isEmpty(allianceId)){1037 e = ErrorUtils.playerNotJoinAlliance(session.uid)1038 next(e, ErrorUtils.getError(e))1039 return1040 }1041 if(!DataUtils.isDragonTypeExist(dragonType)){1042 e = new Error("dragonType 不合法")1043 next(e, ErrorUtils.getError(e))1044 return1045 }1046 if(!_.isArray(soldiers)){1047 e = new Error("soldiers 不合法")1048 next(e, ErrorUtils.getError(e))1049 return1050 }1051 if(!_.isString(defenceAllianceId) || !ShortId.isValid(defenceAllianceId)){1052 e = new Error("defenceAllianceId 不合法")1053 next(e, ErrorUtils.getError(e))1054 return1055 }1056 if(!_.isString(defencePlayerId) || !ShortId.isValid(defencePlayerId)){1057 e = new Error("defencePlayerId 不合法")1058 next(e, ErrorUtils.getError(e))1059 return1060 }1061 this.request(session, 'attackPlayerCity', [session.uid, allianceId, dragonType, soldiers, defenceAllianceId, defencePlayerId]).then(function(playerData){1062 next(null, {code:200, playerData:playerData})1063 }).catch(function(e){1064 next(null, ErrorUtils.getError(e))1065 })1066}1067/**1068 * 进攻村落1069 * @param msg1070 * @param session1071 * @param next1072 */1073pro.attackVillage = function(msg, session, next){1074 var allianceId = session.get('allianceId');1075 var dragonType = msg.dragonType1076 var soldiers = msg.soldiers1077 var defenceAllianceId = msg.defenceAllianceId1078 var defenceVillageId = msg.defenceVillageId1079 var e = null1080 if(_.isEmpty(allianceId)){1081 e = ErrorUtils.playerNotJoinAlliance(session.uid)1082 next(e, ErrorUtils.getError(e))1083 return1084 }1085 if(!DataUtils.isDragonTypeExist(dragonType)){1086 e = new Error("dragonType 不合法")1087 next(e, ErrorUtils.getError(e))1088 return1089 }1090 if(!_.isArray(soldiers)){1091 e = new Error("soldiers 不合法")1092 next(e, ErrorUtils.getError(e))1093 return1094 }1095 if(!_.isString(defenceAllianceId) || !ShortId.isValid(defenceAllianceId)){1096 e = new Error("defenceAllianceId 不合法")1097 next(e, ErrorUtils.getError(e))1098 return1099 }1100 if(!_.isString(defenceVillageId) || !ShortId.isValid(defenceVillageId)){1101 e = new Error("defenceVillageId 不合法")1102 next(e, ErrorUtils.getError(e))1103 return1104 }1105 this.request(session, 'attackVillage', [session.uid, allianceId, dragonType, soldiers, defenceAllianceId, defenceVillageId]).then(function(playerData){1106 next(null, {code:200, playerData:playerData})1107 }).catch(function(e){1108 next(null, ErrorUtils.getError(e))1109 })1110}1111/**1112 * 进攻野怪1113 * @param msg1114 * @param session1115 * @param next1116 */1117pro.attackMonster = function(msg, session, next){1118 var allianceId = session.get('allianceId');1119 var dragonType = msg.dragonType1120 var soldiers = msg.soldiers1121 var defenceAllianceId = msg.defenceAllianceId1122 var defenceMonsterId = msg.defenceMonsterId1123 var e = null1124 if(_.isEmpty(allianceId)){1125 e = ErrorUtils.playerNotJoinAlliance(session.uid)1126 next(e, ErrorUtils.getError(e))1127 return1128 }1129 if(!DataUtils.isDragonTypeExist(dragonType)){1130 e = new Error("dragonType 不合法")1131 next(e, ErrorUtils.getError(e))1132 return1133 }1134 if(!_.isArray(soldiers)){1135 e = new Error("soldiers 不合法")1136 next(e, ErrorUtils.getError(e))1137 return1138 }1139 if(!_.isString(defenceAllianceId) || !ShortId.isValid(defenceAllianceId)){1140 e = new Error("defenceAllianceId 不合法")1141 next(e, ErrorUtils.getError(e))1142 return1143 }1144 if(!_.isString(defenceMonsterId) || !ShortId.isValid(defenceMonsterId)){1145 e = new Error("defenceMonsterId 不合法")1146 next(e, ErrorUtils.getError(e))1147 return1148 }1149 this.request(session, 'attackMonster', [session.uid, allianceId, dragonType, soldiers, defenceAllianceId, defenceMonsterId]).then(function(playerData){1150 next(null, {code:200, playerData:playerData})1151 }).catch(function(e){1152 next(null, ErrorUtils.getError(e))1153 })1154}1155/**1156 * 从村落撤兵1157 * @param msg1158 * @param session1159 * @param next1160 */1161pro.retreatFromVillage = function(msg, session, next){1162 var allianceId = session.get('allianceId');1163 var villageEventId = msg.villageEventId1164 var e = null1165 if(_.isEmpty(allianceId)){1166 e = ErrorUtils.playerNotJoinAlliance(session.uid)1167 next(e, ErrorUtils.getError(e))1168 return1169 }1170 if(!_.isString(villageEventId) || !ShortId.isValid(villageEventId)){1171 e = new Error("villageEventId 不合法")1172 next(e, ErrorUtils.getError(e))1173 return1174 }1175 this.request(session, 'retreatFromVillage', [session.uid, allianceId, villageEventId]).then(function(playerData){1176 next(null, {code:200, playerData:playerData})1177 }).catch(function(e){1178 next(null, ErrorUtils.getError(e))1179 })1180}1181/**1182 * 突袭村落1183 * @param msg1184 * @param session1185 * @param next1186 */1187pro.strikeVillage = function(msg, session, next){1188 var allianceId = session.get('allianceId');1189 var dragonType = msg.dragonType1190 var defenceAllianceId = msg.defenceAllianceId1191 var defenceVillageId = msg.defenceVillageId1192 var e = null1193 if(_.isEmpty(allianceId)){1194 e = ErrorUtils.playerNotJoinAlliance(session.uid)1195 next(e, ErrorUtils.getError(e))1196 return1197 }1198 if(!DataUtils.isDragonTypeExist(dragonType)){1199 e = new Error("dragonType 不合法")1200 next(e, ErrorUtils.getError(e))1201 return1202 }1203 if(!_.isString(defenceAllianceId) || !ShortId.isValid(defenceAllianceId)){1204 e = new Error("defenceAllianceId 不合法")1205 next(e, ErrorUtils.getError(e))1206 return1207 }1208 if(!_.isString(defenceVillageId) || !ShortId.isValid(defenceVillageId)){1209 e = new Error("defenceVillageId 不合法")1210 next(e, ErrorUtils.getError(e))1211 return1212 }1213 this.request(session, 'strikeVillage', [session.uid, allianceId, dragonType, defenceAllianceId, defenceVillageId]).then(function(playerData){1214 next(null, {code:200, playerData:playerData})1215 }).catch(function(e){1216 next(null, ErrorUtils.getError(e))1217 })1218}1219/**1220 * 查看敌方进攻行军事件详细信息1221 * @param msg1222 * @param session1223 * @param next1224 */1225pro.getAttackMarchEventDetail = function(msg, session, next){1226 var allianceId = session.get('allianceId');1227 var targetAllianceId = msg.targetAllianceId1228 var eventId = msg.eventId1229 var e = null1230 if(_.isEmpty(allianceId)){1231 e = ErrorUtils.playerNotJoinAlliance(session.uid)1232 next(e, ErrorUtils.getError(e))1233 return1234 }1235 if(!_.isString(targetAllianceId) || !ShortId.isValid(targetAllianceId)){1236 e = new Error("targetAllianceId 不合法")1237 next(e, ErrorUtils.getError(e))1238 return1239 }1240 if(!_.isString(eventId) || !ShortId.isValid(eventId)){1241 e = new Error("eventId 不合法")1242 next(e, ErrorUtils.getError(e))1243 return1244 }1245 this.request(session, 'getAttackMarchEventDetail', [session.uid, allianceId, targetAllianceId, eventId]).then(function(eventDetail){1246 next(null, {code:200, eventDetail:eventDetail})1247 }).catch(function(e){1248 next(null, ErrorUtils.getError(e))1249 })1250}1251/**1252 * 查看敌方突袭行军事件详细信息1253 * @param msg1254 * @param session1255 * @param next1256 */1257pro.getStrikeMarchEventDetail = function(msg, session, next){1258 var allianceId = session.get('allianceId');1259 var targetAllianceId = msg.targetAllianceId1260 var eventId = msg.eventId1261 var e = null1262 if(_.isEmpty(allianceId)){1263 e = ErrorUtils.playerNotJoinAlliance(session.uid)1264 next(e, ErrorUtils.getError(e))1265 return1266 }1267 if(!_.isString(targetAllianceId) || !ShortId.isValid(targetAllianceId)){1268 e = new Error("targetAllianceId 不合法")1269 next(e, ErrorUtils.getError(e))1270 return1271 }1272 if(!_.isString(eventId) || !ShortId.isValid(eventId)){1273 e = new Error("eventId 不合法")1274 next(e, ErrorUtils.getError(e))1275 return1276 }1277 this.request(session, 'getStrikeMarchEventDetail', [session.uid, allianceId, targetAllianceId, eventId]).then(function(eventDetail){1278 next(null, {code:200, eventDetail:eventDetail})1279 }).catch(function(e){1280 next(null, ErrorUtils.getError(e))1281 })1282}1283/**1284 * 查看协助部队行军事件详细信息1285 * @param msg1286 * @param session1287 * @param next1288 */1289pro.getHelpDefenceMarchEventDetail = function(msg, session, next){1290 var allianceId = session.get('allianceId');1291 var eventId = msg.eventId1292 var e = null1293 if(_.isEmpty(allianceId)){1294 e = ErrorUtils.playerNotJoinAlliance(session.uid)1295 next(e, ErrorUtils.getError(e))1296 return1297 }1298 if(!_.isString(allianceId) || !ShortId.isValid(allianceId)){1299 e = new Error("allianceId 不合法")1300 next(e, ErrorUtils.getError(e))1301 return1302 }1303 if(!_.isString(eventId) || !ShortId.isValid(eventId)){1304 e = new Error("eventId 不合法")1305 next(e, ErrorUtils.getError(e))1306 return1307 }1308 this.request(session, 'getHelpDefenceMarchEventDetail', [session.uid, allianceId, eventId]).then(function(eventDetail){1309 next(null, {code:200, eventDetail:eventDetail})1310 }).catch(function(e){1311 next(null, ErrorUtils.getError(e))1312 })1313}1314/**1315 * 查看协防部队详细信息1316 * @param msg1317 * @param session1318 * @param next1319 */1320pro.getHelpDefenceTroopDetail = function(msg, session, next){1321 var allianceId = session.get('allianceId');1322 var playerId = msg.playerId1323 var e = null1324 if(_.isEmpty(allianceId)){1325 e = ErrorUtils.playerNotJoinAlliance(session.uid)1326 next(e, ErrorUtils.getError(e))1327 return1328 }1329 this.request(session, 'getHelpDefenceTroopDetail', [session.uid, allianceId, playerId]).then(function(troopDetail){1330 next(null, {code:200, troopDetail:troopDetail})1331 }).catch(function(e){1332 next(null, ErrorUtils.getError(e))1333 })1334}1335/**1336 * 联盟商店补充道具1337 * @param msg1338 * @param session1339 * @param next1340 */1341pro.addShopItem = function(msg, session, next){1342 var allianceId = session.get('allianceId');1343 var playerName = session.get('name')1344 var itemName = msg.itemName1345 var count = msg.count1346 var e = null1347 if(_.isEmpty(allianceId)){1348 e = ErrorUtils.playerNotJoinAlliance(session.uid)1349 next(e, ErrorUtils.getError(e))1350 return1351 }1352 if(!DataUtils.isItemNameExist(itemName)){1353 e = new Error("itemName 不合法")1354 next(e, ErrorUtils.getError(e))1355 return1356 }1357 if(!_.isNumber(count) || count % 1 !== 0 || count <= 0){1358 e = new Error("count 不合法")1359 next(e, ErrorUtils.getError(e))1360 return1361 }1362 this.request(session, 'addShopItem', [session.uid, playerName, allianceId, itemName, count]).then(function(){1363 next(null, {code:200})1364 }).catch(function(e){1365 next(null, ErrorUtils.getError(e))1366 })1367}1368/**1369 * 购买联盟商店的道具1370 * @param msg1371 * @param session1372 * @param next1373 */1374pro.buyShopItem = function(msg, session, next){1375 var allianceId = session.get('allianceId');1376 var itemName = msg.itemName1377 var count = msg.count1378 var e = null1379 if(_.isEmpty(allianceId)){1380 e = ErrorUtils.playerNotJoinAlliance(session.uid)1381 next(e, ErrorUtils.getError(e))1382 return1383 }1384 if(!DataUtils.isItemNameExist(itemName)){1385 e = new Error("itemName 不合法")1386 next(e, ErrorUtils.getError(e))1387 return1388 }1389 if(!_.isNumber(count) || count % 1 !== 0 || count <= 0){1390 e = new Error("count 不合法")1391 next(e, ErrorUtils.getError(e))1392 return1393 }1394 this.request(session, 'buyShopItem', [session.uid, allianceId, itemName, count]).then(function(playerData){1395 next(null, {code:200, playerData:playerData})1396 }).catch(function(e){1397 next(null, ErrorUtils.getError(e))1398 })1399}1400//1401///**1402// * 为联盟成员添加荣耀值1403// * @param msg1404// * @param session1405// * @param next1406// */1407//pro.giveLoyaltyToAllianceMember = function(msg, session, next){1408// var allianceId = session.get('allianceId');1409// var memberId = msg.memberId1410// var count = msg.count1411// var e = null1412// if(_.isEmpty(allianceId)){1413// e = ErrorUtils.playerNotJoinAlliance(session.uid)1414// next(e, ErrorUtils.getError(e))1415// return1416// }1417// if(!_.isString(memberId) || !ShortId.isValid(memberId)){1418// e = new Error("memberId 不合法")1419// next(e, ErrorUtils.getError(e))1420// return1421// }1422// if(!_.isNumber(count) || count % 1 !== 0 || count <= 0){1423// e = new Error("count 不合法")1424// next(e, ErrorUtils.getError(e))1425// return1426// }1427//1428// this.request(session, 'giveLoyaltyToAllianceMember', [session.uid, allianceId, memberId, count]).then(function(){1429// next(null, {code:200})1430// }).catch(function(e){1431// next(null, ErrorUtils.getError(e))1432// })1433//}1434/**1435 * 查看联盟信息1436 * @param msg1437 * @param session1438 * @param next1439 */1440pro.getAllianceInfo = function(msg, session, next){1441 var allianceId = msg.allianceId;1442 var serverId = msg.serverId;1443 var e = null1444 if(!_.isString(allianceId) || !ShortId.isValid(allianceId)){1445 e = new Error("allianceId 不合法")1446 next(e, ErrorUtils.getError(e))1447 return1448 }1449 if(!_.contains(this.app.get('cacheServerIds'), serverId)){1450 e = new Error("serverId 不合法")1451 next(e, ErrorUtils.getError(e))1452 return1453 }1454 this.request(session, 'getAllianceInfo', [session.uid, allianceId], serverId).then(function(allianceData){1455 next(null, {code:200, allianceData:allianceData})1456 }).catch(function(e){1457 next(null, ErrorUtils.getError(e))1458 })1459}1460/**1461 * 查看联盟基础信息1462 * @param msg1463 * @param session1464 * @param next1465 */1466pro.getAllianceBasicInfo = function(msg, session, next){1467 var allianceId = msg.allianceId;1468 var serverId = msg.serverId;1469 var e = null1470 if(!_.isString(allianceId) || !ShortId.isValid(allianceId)){1471 e = new Error("allianceId 不合法")1472 next(e, ErrorUtils.getError(e))1473 return1474 }1475 if(!_.contains(this.app.get('cacheServerIds'), serverId)){1476 e = new Error("serverId 不合法")1477 next(e, ErrorUtils.getError(e))1478 return1479 }1480 this.request(session, 'getAllianceBasicInfo', [session.uid, allianceId], serverId).then(function(allianceData){1481 next(null, {code:200, allianceData:allianceData})1482 }).catch(function(e){1483 next(null, ErrorUtils.getError(e))1484 })1485}1486/**1487 * 获取联盟圣地战历史记录1488 * @param msg1489 * @param session1490 * @param next1491 */1492pro.getShrineReports = function(msg, session, next){1493 var allianceId = session.get('allianceId');1494 var e = null1495 if(_.isEmpty(allianceId)){1496 e = ErrorUtils.playerNotJoinAlliance(session.uid)1497 next(e, ErrorUtils.getError(e))1498 return1499 }1500 this.request(session, 'getShrineReports', [session.uid, allianceId]).then(function(shrineReports){1501 next(null, {code:200, shrineReports:shrineReports})1502 }).catch(function(e){1503 next(null, ErrorUtils.getError(e))1504 })1505}1506/**1507 * 获取联盟战历史记录1508 * @param msg1509 * @param session1510 * @param next1511 */1512pro.getAllianceFightReports = function(msg, session, next){1513 var allianceId = session.get('allianceId');1514 var e = null1515 if(_.isEmpty(allianceId)){1516 e = ErrorUtils.playerNotJoinAlliance(session.uid)1517 next(e, ErrorUtils.getError(e))1518 return1519 }1520 this.request(session, 'getAllianceFightReports', [session.uid, allianceId]).then(function(allianceFightReports){1521 next(null, {code:200, allianceFightReports:allianceFightReports})1522 }).catch(function(e){1523 next(null, ErrorUtils.getError(e))1524 })1525}1526/**1527 * 获取联盟商店买入卖出记录1528 * @param msg1529 * @param session1530 * @param next1531 */1532pro.getItemLogs = function(msg, session, next){1533 var allianceId = session.get('allianceId');1534 var e = null1535 if(_.isEmpty(allianceId)){1536 e = ErrorUtils.playerNotJoinAlliance(session.uid)1537 next(e, ErrorUtils.getError(e))1538 return1539 }1540 this.request(session, 'getItemLogs', [session.uid, allianceId]).then(function(itemLogs){1541 next(null, {code:200, itemLogs:itemLogs})1542 }).catch(function(e){1543 next(null, ErrorUtils.getError(e))1544 })1545}1546/**1547 * 移动联盟1548 * @param msg1549 * @param session1550 * @param next1551 */1552pro.moveAlliance = function(msg, session, next){1553 var allianceId = session.get('allianceId');1554 var targetMapIndex = msg.targetMapIndex;1555 var e = null1556 if(_.isEmpty(allianceId)){1557 e = ErrorUtils.playerNotJoinAlliance(session.uid)1558 return next(e, ErrorUtils.getError(e))1559 }1560 if(!_.isNumber(targetMapIndex) || targetMapIndex < 0 || targetMapIndex > Math.pow(this.bigMapLength, 2) - 1){1561 e = new Error('targetMapIndex 不合法');1562 return next(e, ErrorUtils.getError(e))1563 }1564 this.request(session, 'moveAlliance', [session.uid, allianceId, targetMapIndex]).then(function(){1565 next(null, {code:200})1566 }).catch(function(e){1567 next(null, ErrorUtils.getError(e))1568 })1569}1570/**1571 * 进入被观察地块1572 * @param msg1573 * @param session1574 * @param next1575 */1576pro.enterMapIndex = function(msg, session, next){1577 var allianceId = session.get('allianceId');1578 var logicServerId = session.get('logicServerId');1579 var mapIndex = msg.mapIndex;1580 var e = null1581 if(_.isEmpty(allianceId)){1582 e = ErrorUtils.playerNotJoinAlliance(session.uid)1583 return next(e, ErrorUtils.getError(e))1584 }1585 if(!_.isNumber(mapIndex) || mapIndex < 0 || mapIndex > Math.pow(this.bigMapLength, 2) - 1){1586 e = new Error('mapIndex 不合法');1587 return next(e, ErrorUtils.getError(e))1588 }1589 this.request(session, 'enterMapIndex', [logicServerId, session.uid, allianceId, mapIndex]).spread(function(allianceData, mapData){1590 next(null, {code:200, allianceData:allianceData, mapData:mapData})1591 }).catch(function(e){1592 next(null, ErrorUtils.getError(e))1593 })1594}1595/**1596 * 玩家离开被观察的地块1597 * @param msg1598 * @param session1599 * @param next1600 */1601pro.leaveMapIndex = function(msg, session, next){1602 var allianceId = session.get('allianceId');1603 var logicServerId = session.get('logicServerId');1604 var e = null1605 if(_.isEmpty(allianceId)){1606 e = ErrorUtils.playerNotJoinAlliance(session.uid)1607 return next(e, ErrorUtils.getError(e))1608 }1609 this.request(session, 'leaveMapIndex', [logicServerId, session.uid]).then(function(){1610 next(null, {code:200})1611 }).catch(function(e){1612 next(null, ErrorUtils.getError(e))1613 })1614}1615/**1616 * 在大地图中获取联盟基础信息1617 * @param msg1618 * @param session1619 * @param next1620 * @returns {*}1621 */1622pro.getMapAllianceDatas = function(msg, session, next){1623 var self = this;1624 var mapIndexs = msg.mapIndexs;1625 var e = null1626 if(!_.isArray(mapIndexs)){1627 e = new Error('mapIndexs 不合法');1628 return next(e, ErrorUtils.getError(e))1629 }1630 var hasError = _.some(mapIndexs, function(mapIndex){1631 return !_.isNumber(mapIndex) || mapIndex < 0 || mapIndex > Math.pow(self.bigMapLength, 2) - 1;1632 })1633 if(hasError){1634 e = new Error('mapIndexs 不合法');1635 return next(e, ErrorUtils.getError(e))1636 }1637 this.request(session, 'getMapAllianceDatas', [session.uid, mapIndexs]).then(function(datas){1638 next(null, {code:200, datas:datas})1639 }).catch(function(e){1640 next(null, ErrorUtils.getError(e))1641 })1642}1643/**1644 * 获取联盟活动信息1645 * @param msg1646 * @param session1647 * @param next1648 */1649pro.getAllianceActivities = function(msg, session, next){1650 var allianceId = session.get('allianceId');1651 this.request(session, 'getAllianceActivities', []).then(function(activities){1652 next(null, {code:200, activities:activities})1653 }).catch(function(e){1654 next(null, ErrorUtils.getError(e))1655 })1656}1657/**1658 * 获取联盟活动积分奖励1659 * @param msg1660 * @param session1661 * @param next1662 */1663pro.getAllianceActivityScoreRewards = function(msg, session, next){1664 var rankType = msg.rankType;1665 var allianceId = session.get('allianceId');1666 var e = null;1667 if(_.isEmpty(allianceId)){1668 e = ErrorUtils.playerNotJoinAlliance(session.uid)1669 return next(e, ErrorUtils.getError(e))1670 }1671 if(!_.contains(DataUtils.getAllianceActivityTypes(), rankType)){1672 e = new Error("rankType 不合法");1673 return next(e, ErrorUtils.getError(e));1674 }1675 this.request(session, 'getAllianceActivityScoreRewards', [session.uid, allianceId, rankType]).then(function(playerData){1676 next(null, {code:200, playerData:playerData})1677 }).catch(function(e){1678 next(null, ErrorUtils.getError(e))1679 })1680}1681/**1682 * 获取联盟活动排名奖励1683 * @param msg1684 * @param session1685 * @param next1686 */1687pro.getAllianceActivityRankRewards = function(msg, session, next){1688 var rankType = msg.rankType;1689 var allianceId = session.get('allianceId');1690 var e = null;1691 if(_.isEmpty(allianceId)){1692 e = ErrorUtils.playerNotJoinAlliance(session.uid)1693 return next(e, ErrorUtils.getError(e))1694 }1695 if(!_.contains(DataUtils.getAllianceActivityTypes(), rankType)){1696 e = new Error("rankType 不合法");1697 return next(e, ErrorUtils.getError(e));1698 }1699 this.request(session, 'getAllianceActivityRankRewards', [session.uid, allianceId, rankType]).then(function(playerData){1700 next(null, {code:200, playerData:playerData})1701 }).catch(function(e){1702 next(null, ErrorUtils.getError(e))1703 })...

Full Screen

Full Screen

event.js

Source:event.js Github

copy

Full Screen

...149 POSTING: {150 state: states.POSTINGS_ID,151 method: function(targetIds, targets) {152 return function(callback, error, apiError) {153 pyPosting.posting(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.POSTING]);154 };155 },156 view: partials.POSTING157 },158 COMMENT: {159 state: states.COMMENTS_ID,160 method: function(targetIds, targets) {161 return function(callback, error, apiError) {162 pyComment.comment(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.COMMENT]);163 };164 },165 view: partials.COMMENT166 },167 COMMENT_SUB: {168 state: states.COMMENTS_ID,169 method: function(targetIds, targets) {170 return function(callback, error, apiError) {171 pyComment.comment(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.COMMENT]);172 };173 },174 view: partials.COMMENT175 },176 MESSAGE: {177 state: states.CONVERSATION178 },179 APPRECIATION_POSTING: {180 state: states.POSTINGS_ID,181 method: function(targetIds, targets) {182 return function(callback, error, apiError) {183 pyPosting.posting(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.POSTING]);184 };185 },186 view: partials.POSTING187 },188 APPRECIATION_COMMENT: {189 state: states.COMMENTS_ID,190 method: function(targetIds, targets) {191 return function(callback, error, apiError) {192 pyComment.comment(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.COMMENT]);193 };194 },195 view: partials.COMMENT196 },197 APPRECIATION_ATTEMPT: {198 state: states.SETTINGS199 },200 PROMOTION_POSTING: {201 state: states.POSTINGS_ID,202 method: function(targetIds, targets) {203 return function(callback, error, apiError) {204 pyPosting.posting(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.POSTING]);205 };206 },207 view: partials.POSTING208 },209 PROMOTION_COMMENT: {210 state: states.COMMENTS_ID,211 method: function(targetIds, targets) {212 return function(callback, error, apiError) {213 pyComment.comment(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.COMMENT]);214 };215 },216 view: partials.COMMENT217 },218 OFFER: {219 state: states.OFFERS220 },221 OFFER_ACCEPT: {222 state: states.USERS_ID223 },224 OFFER_WITHDRAW: {225 state: states.USERS_ID226 },227 OFFER_DENY: {228 state: states.USERS_ID229 },230 BACKING_CANCEL: {231 state: states.USERS_ID232 },233 BACKING_WITHDRAW: {234 state: states.USERS_ID235 },236 FOLLOW_ADD: {237 state: states.USERS_ID,238 /*239 method: function(targetIds, targets) {240 return function(callback, error, apiError) {241 pyUser.user(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.TARGET]);242 };243 },*/244 getData: function(targetIds, targets) {245 return User.user($scope, targetIds[pathVars.TARGET], getSuccess, getError, getError);246 },247 view: partials.USER248 },249 FOLLOW_REMOVE: {250 state: states.USERS_ID,251 /*252 method: function(targetIds, targets) {253 return function(callback, error, apiError) {254 pyUser.user(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.TARGET]);255 };256 },*/257 getData: function(targetIds, targets) {258 return User.user($scope, targetIds[pathVars.TARGET], getSuccess, getError, getError);259 },260 view: partials.USER261 },262 POSTING_INFRINGEMENT: {263 state: states.POSTINGS_ID264 },265 COMMENT_INFRINGEMENT: {266 state: states.COMMENTS_ID267 }268 };269 270 var updated = function(s) {271 if(ng.isDefined(s) && ng.isDefined(s.getSingleMain())) {272 $scope.single = s;273 $scope.event = s.getSingleMain();274 $scope.subData = {};275 if(!ng.isDefined($scope.event.type)) {276 return;277 }278 i18n(function(t) {279 $scope.targets = $scope.event.targets;280 281 if($scope.targets.type === 'POSTING') {282 $scope.targets.typeRenamed = t('shared:typeRenamed.posting');283 } else if($scope.targets.type === 'USER') {284 $scope.targets.typeRenamed = t('shared:typeRenamed.user');285 } else if($scope.targets.type === 'TAG') {286 $scope.targets.typeRenamed = t('shared:typeRenamed.tag');287 }288 289 $scope.targetIds = $scope.event.targetIds;290 if(typeof($scope.targetIds[pathVars.USER]) === 'undefined') {291 $scope.targetIds[pathVars.USER] = $scope.targetIds[pathVars.TARGET];292 }293 $scope.title = t('shared:activityTypes.' + $scope.event.type, $scope.targets);294 $scope.timeSince = utils.getTimeSince($scope.event.occurred);295 $scope.calendar = utils.getCalendarDate($scope.event.occurred);296 297 var activity = activities[$scope.event.type];298 $scope.click = undefined;299 if(ng.isDefined(activity)) {300 $scope.link = $state.href(activity.state, $scope.targetIds);301 if((ng.isDefined(activity.method) || ng.isDefined(activity.getData)) && ng.isDefined(activity.view)) {302 $scope.click = getData(activity);303 if($scope.single.autoLoad) {304 var timeout = 0;305 var index = $scope.$parent[scopeVars.INDEX];306 if(ng.isDefined(index) && index > 0) {307 timeout = index * values.AUTOLOAD_TIMEOUT_MULTIPLIER;308 }309 $timeout(function() {310 $scope.click();311 }, timeout);312 }313 }314 } else {315 $scope.link = $state.href(states.INDEX, $scope.targetIds);316 }317 318 });319 }320 };321 updated($scope.single);322 323 $scope.$watch('$parent.' + $scope.$parent[scopeVars.SINGLE] + '.' + chainedKeys.DATA + '.' + chainedKeys.SINGLE, function(newValue, oldValue) {324 if(newValue !== oldValue) {325 updated($parse($scope.$parent[scopeVars.SINGLE])($scope.$parent));326 }327 });328 329 }330 ]);331 controller.controller('NotificationController', ['$scope', '$state', '$parse', '$timeout', 'ApiData', 'pyPosting', 'pyComment', 'User',332 function($scope, $state, $parse, $timeout, ApiData, pyPosting, pyComment, User) {333 $scope.single = $parse($scope.$parent[scopeVars.SINGLE])($scope.$parent);334 $scope[scopeVars.SINGLE] = 'subData.single';335 336 var getSuccess = function(callback) {337 return function(code, dto, p) {338 $scope.loadingSubSingle = false;339 return callback(code, dto, p);340 };341 };342 343 var getError = function(error, a) {344 return function(code, dto) {345 i18n(function(t) {346 $scope.loadingSubSingle = false;347 $scope.subSingleAlert = t('alerts:pageableErrors.sub');348 if(ng.isDefined(a)) {349 $scope.subSingleAlert = t(a);350 }351 });352 $scope.subData = {};353 error(code, dto);354 };355 };356 357 var getData = function(activity) {358 if(ng.isDefined(activity) && ng.isDefined(activity.view) && (ng.isDefined(activity.method) || ng.isDefined(activity.getData))) {359 return function() {360 $scope.subSingleAlert = undefined;361 if(ng.isDefined($scope.subData) && ng.isDefined($scope.subData.single)) {362 $scope.subData = {};363 } else {364 $scope.loadingSubSingle = true;365 if(ng.isDefined(activity.getData)) {366 $scope.subData = activity.getData($scope.targetIds, $scope.targets);367 } else {368 $scope.subData = ApiData.getData({369 scope: $scope,370 view: activity.view,371 method: activity.method($scope.targetIds, $scope.targets)372 });373 }374 }375 };376 } else {377 return function() {};378 }379 };380 381 var activities = {382 ANY: {383 state: states.INDEX,384 },385 POSTING: {386 state: states.POSTINGS_ID,387 method: function(targetIds, targets) {388 return function(callback, error, apiError) {389 pyPosting.posting(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.POSTING]);390 };391 },392 view: partials.POSTING393 },394 COMMENT: {395 state: states.COMMENTS_ID,396 method: function(targetIds, targets) {397 return function(callback, error, apiError) {398 pyComment.comment(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.COMMENT]);399 };400 },401 view: partials.COMMENT402 },403 COMMENT_SUB: {404 state: states.COMMENTS_ID,405 method: function(targetIds, targets) {406 return function(callback, error, apiError) {407 pyComment.comment(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.COMMENT]);408 };409 },410 view: partials.COMMENT411 },412 MESSAGE: {413 state: states.CONVERSATION414 },415 APPRECIATION_POSTING: {416 state: states.POSTINGS_ID,417 getData: function(targetIds, targets) {418 return User.user($scope, targetIds[pathVars.USER], getSuccess, getError, getError);419 },420 view: partials.USER421 /*422 method: function(targetIds, targets) {423 return function(callback, error, apiError) {424 pyPosting.posting(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.POSTING]);425 };426 },427 view: partials.POSTING428 */429 },430 APPRECIATION_COMMENT: {431 state: states.COMMENTS_ID,432 getData: function(targetIds, targets) {433 return User.user($scope, targetIds[pathVars.USER], getSuccess, getError, getError);434 },435 view: partials.USER436 /*437 method: function(targetIds, targets) {438 return function(callback, error, apiError) {439 pyComment.comment(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.COMMENT]);440 };441 },442 view: partials.COMMENT443 */444 },445 APPRECIATION_ATTEMPT: {446 state: states.SETTINGS447 },448 PROMOTION_POSTING: {449 state: states.POSTINGS_ID,450 getData: function(targetIds, targets) {451 return User.user($scope, targetIds[pathVars.USER], getSuccess, getError, getError);452 },453 view: partials.USER454 /*455 method: function(targetIds, targets) {456 return function(callback, error, apiError) {457 pyPosting.posting(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.POSTING]);458 };459 },460 view: partials.POSTING461 */462 },463 PROMOTION_COMMENT: {464 state: states.COMMENTS_ID,465 getData: function(targetIds, targets) {466 return User.user($scope, targetIds[pathVars.USER], getSuccess, getError, getError);467 },468 view: partials.USER469 /*470 method: function(targetIds, targets) {471 return function(callback, error, apiError) {472 pyPosting.posting(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.COMMENT]);473 };474 },475 view: partials.COMMENT476 */477 },478 OFFER: {479 state: states.OFFERS480 },481 OFFER_ACCEPT: {482 state: states.USERS_ID483 },484 OFFER_WITHDRAW: {485 state: states.USERS_ID486 },487 OFFER_DENY: {488 state: states.USERS_ID489 },490 BACKING_CANCEL: {491 state: states.USERS_ID492 },493 BACKING_WITHDRAW: {494 state: states.USERS_ID495 },496 FOLLOW_ADD: {497 state: states.USERS_ID,498 /*499 method: function(targetIds, targets) {500 return function(callback, error, apiError) {501 pyUser.user(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.TARGET]);502 };503 },*/504 getData: function(targetIds, targets) {505 return User.user($scope, targetIds[pathVars.USER], getSuccess, getError, getError);506 },507 view: partials.USER508 },509 FOLLOW_REMOVE: {510 state: states.USERS_ID,511 /*512 method: function(targetIds, targets) {513 return function(callback, error, apiError) {514 pyUser.user(getSuccess(callback), getError(error), getError(apiError), targetIds[pathVars.TARGET]);515 };516 },*/517 getData: function(targetIds, targets) {518 return User.user($scope, targetIds[pathVars.USER], getSuccess, getError, getError);519 },520 view: partials.USER521 },522 POSTING_INFRINGEMENT: {523 state: states.POSTINGS_ID524 },525 COMMENT_INFRINGEMENT: {526 state: states.COMMENTS_ID527 }528 };...

Full Screen

Full Screen

processorErrorFactory.js

Source:processorErrorFactory.js Github

copy

Full Screen

...5export const ProcessorErrorFactory = Object.freeze({6 symbol_not_found_full: (id, sourceInfo) => {7 if(sourceInfo) {8 const context = [id, sourceInfo.line, sourceInfo.column];9 return new SemanticError(LocalizedStrings.getError("symbol_not_found_full", context));10 } else {11 return ProcessorErrorFactory.symbol_not_found(id);12 }13 },14 symbol_not_found: (id) => {15 const context = [id];16 return new SemanticError(LocalizedStrings.getError("symbol_not_found", context));17 },18 function_missing_full: (id, sourceInfo) => {19 if(sourceInfo) {20 const context = [id, sourceInfo.line, sourceInfo.column];21 return new SemanticError(LocalizedStrings.getError("function_missing_full", context));22 } else {23 return ProcessorErrorFactory.function_missing(id);24 }25 },26 function_missing: (id) => {27 const context = [id];28 return new SemanticError(LocalizedStrings.getError("function_missing", context));29 },30 main_missing: () => {31 return new SemanticError(LocalizedStrings.getError("main_missing"));32 }, // TODO: better urgent error message33 array_dimension_not_int_full: (sourceInfo) => {34 if(sourceInfo) {35 const context = [sourceInfo.line];36 return new SemanticError(LocalizedStrings.getError("array_dimension_not_int_full", context));37 } else {38 return ProcessorErrorFactory.array_dimension_not_int();39 }40 },41 array_dimension_not_int: () => {42 return new SemanticError(LocalizedStrings.getError("array_dimension_not_int"));43 },44 unknown_command_full: (sourceInfo)=> {45 if(sourceInfo) {46 const context = [sourceInfo.line];47 return new RuntimeError(LocalizedStrings.getError("unknown_command_full", context));48 } else {49 return ProcessorErrorFactory.unknown_command();50 }51 52 },53 unknown_command: ()=> {54 return new RuntimeError(LocalizedStrings.getError("unknown_command"));55 },56 incompatible_types_full: (type, dim, sourceInfo) => {57 if(sourceInfo) {58 const context = [LocalizedStrings.translateType(type, dim), sourceInfo.line, sourceInfo.column];59 return new SemanticError(LocalizedStrings.getError("incompatible_types_full", context));60 } else {61 return ProcessorErrorFactory.incompatible_types(type, dim);62 }63 },64 incompatible_types: (type, dim) => {65 const context = [LocalizedStrings.translateType(type, dim)];66 return new SemanticError(LocalizedStrings.getError("incompatible_types", context));67 },68 incompatible_types_array_full: (exp, type, dim, sourceInfo) => {69 if(sourceInfo) {70 const context = [exp, LocalizedStrings.translateType(type, dim), sourceInfo.line, sourceInfo.column];71 return new SemanticError(LocalizedStrings.getError("incompatible_types_array_full", context));72 } else {73 return ProcessorErrorFactory.incompatible_types_array(exp, type, dim);74 }75 },76 incompatible_types_array: (exp, type, dim) => {77 const context = [exp, LocalizedStrings.translateType(type, dim)];78 return new SemanticError(LocalizedStrings.getError("incompatible_types_array", context));79 },80 loop_condition_type_full: (exp, sourceInfo) => {81 if(sourceInfo) {82 const context = [sourceInfo.line, sourceInfo.column, exp];83 return new SemanticError(LocalizedStrings.getError("loop_condition_type_full", context));84 } else {85 return ProcessorErrorFactory.loop_condition_type(exp);86 }87 },88 loop_condition_type: (exp) => {89 const context = [exp];90 return new SemanticError(LocalizedStrings.getError("loop_condition_type", context));91 },92 endless_loop_full: (sourceInfo) => {93 if(sourceInfo) {94 const context = [sourceInfo.line];95 return new SemanticError(LocalizedStrings.getError("endless_loop_full", context));96 } else {97 return ProcessorErrorFactory.endless_loop();98 }99 },100 endless_loop: () => {101 return new SemanticError(LocalizedStrings.getError("endless_loop"));102 },103 for_condition_type_full: (exp, sourceInfo) => {104 if(sourceInfo) {105 const context = [sourceInfo.line, sourceInfo.column, exp];106 return new SemanticError(LocalizedStrings.getError("for_condition_type_full", context));107 } else {108 return ProcessorErrorFactory.for_condition_type(exp);109 }110 },111 for_condition_type: (exp) => {112 const context = [exp];113 return new SemanticError(LocalizedStrings.getError("for_condition_type", context));114 },115 if_condition_type_full: (exp, sourceInfo) => {116 if(sourceInfo) {117 const context = [sourceInfo.line, sourceInfo.column, exp];118 return new SemanticError(LocalizedStrings.getError("if_condition_type_full", context));119 } else {120 return ProcessorErrorFactory.if_condition_type(exp);121 }122 },123 if_condition_type: (exp) => {124 const context = [exp];125 return new SemanticError(LocalizedStrings.getError("if_condition_type", context));126 },127 invalid_global_var: () => {128 return new RuntimeError(LocalizedStrings.getError("invalid_global_var"))129 },130 not_implemented: (id) => {131 const context = [id]132 return new RuntimeError(LocalizedStrings.getError("not_implemented", context))133 },134 invalid_case_type_full: (exp, type, dim, sourceInfo) => {135 if(sourceInfo) {136 const context = [exp, LocalizedStrings.translateType(type, dim), sourceInfo.line, sourceInfo.column];137 return new SemanticError(LocalizedStrings.getError("invalid_case_type_full", context));138 } else {139 return ProcessorErrorFactory.invalid_case_type(exp, type, dim);140 }141 },142 invalid_case_type: (exp, type, dim) => {143 const context = [exp, LocalizedStrings.translateType(type, dim)];144 return new SemanticError(LocalizedStrings.getError("invalid_case_type", context));145 },146 void_in_expression_full: (id, sourceInfo) => {147 if(sourceInfo) {148 const context = [sourceInfo.line, sourceInfo.column, id];149 return new SemanticError(LocalizedStrings.getError("void_in_expression_full", context));150 } else {151 return ProcessorErrorFactory.void_in_expression(id);152 }153 },154 void_in_expression: (id) => {155 const context = [id];156 return new SemanticError(LocalizedStrings.getError("void_in_expression", context));157 },158 invalid_array_access_full: (id, sourceInfo) => {159 if(sourceInfo) {160 const context = [id, sourceInfo.line, sourceInfo.column];161 return new SemanticError(LocalizedStrings.getError("invalid_array_access_full", context));162 } else {163 return ProcessorErrorFactory.invalid_array_access(id);164 }165 },166 invalid_array_access: (id) => {167 const context = [id];168 return new SemanticError(LocalizedStrings.getError("invalid_array_access", context));169 },170 invalid_matrix_access_full: (id, sourceInfo) => {171 if(sourceInfo) {172 const context = [id, sourceInfo.line, sourceInfo.column];173 return new SemanticError(LocalizedStrings.getError("invalid_matrix_access_full", context));174 } else {175 return ProcessorErrorFactory.invalid_matrix_access(id);176 }177 },178 invalid_matrix_access: (id) => {179 const context = [id];180 return new SemanticError(LocalizedStrings.getError("invalid_matrix_access", context));181 },182 matrix_column_outbounds_full: (id, value, columns, sourceInfo) => {183 if(sourceInfo) {184 const context = [sourceInfo.line, value, id, columns];185 return new RuntimeError(LocalizedStrings.getError("matrix_column_outbounds_full", context));186 } else {187 return ProcessorErrorFactory.matrix_column_outbounds(id, value, columns);188 }189 },190 matrix_column_outbounds: (id, value, columns) => {191 const context = [value, id, columns];192 return new RuntimeError(LocalizedStrings.getError("matrix_column_outbounds", context));193 },194 matrix_line_outbounds_full: (id, value, lines, sourceInfo) => {195 if(sourceInfo) {196 const context = [sourceInfo.line, value, id, lines];197 return new RuntimeError(LocalizedStrings.getError("matrix_line_outbounds_full", context));198 } else {199 return ProcessorErrorFactory.matrix_line_outbounds(id, value, lines);200 }201 },202 matrix_line_outbounds: (id, value, lines) => {203 const context = [value, id, lines];204 return new RuntimeError(LocalizedStrings.getError("matrix_line_outbounds", context));205 },206 vector_line_outbounds_full: (id, value, lines, sourceInfo) => {207 if(sourceInfo) {208 const context = [sourceInfo.line, value, id, lines];209 return new RuntimeError(LocalizedStrings.getError("vector_line_outbounds_full", context));210 } else {211 return ProcessorErrorFactory.vector_line_outbounds(id, value, lines);212 }213 },214 vector_line_outbounds: (id, value, lines) => {215 const context = [value, id, lines];216 return new RuntimeError(LocalizedStrings.getError("vector_line_outbounds", context));217 },218 vector_not_matrix_full: (id, sourceInfo) => {219 if(sourceInfo) {220 const context = [sourceInfo.line, id];221 return new RuntimeError(LocalizedStrings.getError("vector_not_matrix_full", context));222 } else {223 return ProcessorErrorFactory.vector_not_matrix(id);224 }225 },226 vector_not_matrix: (id) => {227 const context = [id];228 return new RuntimeError(LocalizedStrings.getError("vector_not_matrix", context));229 },230 function_no_return: (id) => {231 const context = [id];232 return new SemanticError(LocalizedStrings.getError("function_no_return", context));233 },234 invalid_void_return_full: (id, type, dim, sourceInfo) => {235 if(sourceInfo) {236 const context = [sourceInfo.line, id, LocalizedStrings.translateType(type, dim)];237 return new SemanticError(LocalizedStrings.getError("invalid_void_return_full", context));238 } else {239 return ProcessorErrorFactory.invalid_void_return(id, type, dim);240 }241 },242 invalid_void_return: (id, type, dim) => {243 const context = [id, LocalizedStrings.translateType(type, dim)];244 return new SemanticError(LocalizedStrings.getError("invalid_void_return_full", context));245 },246 invalid_return_type_full: (id, type, dim, sourceInfo) => {247 if(sourceInfo) {248 const context = [sourceInfo.line, id, LocalizedStrings.translateType(type, dim)];249 return new SemanticError(LocalizedStrings.getError("invalid_return_type_full", context));250 } else {251 return ProcessorErrorFactory.invalid_return_type(id, type, dim);252 }253 },254 invalid_return_type: (id, type, dim) => {255 const context = [id, LocalizedStrings.translateType(type, dim)];256 return new SemanticError(LocalizedStrings.getError("invalid_return_type", context));257 },258 invalid_parameters_size_full: (id, expected, actual, sourceInfo) => {259 if(sourceInfo) {260 const context = [sourceInfo.line, id, expected, actual];261 return new SemanticError(LocalizedStrings.getError("invalid_parameters_size_full", context));262 } else {263 return ProcessorErrorFactory.invalid_parameters_size(id, expected, actual);264 }265 },266 invalid_parameters_size: (id, expected, actual) => {267 const context = [id, expected, actual];268 return new SemanticError(LocalizedStrings.getError("invalid_parameters_size", context));269 },270 invalid_parameter_type_full: (id, exp, sourceInfo) => {271 if(sourceInfo) {272 const context = [exp, id, sourceInfo.line];273 return new SemanticError(LocalizedStrings.getError("invalid_parameter_type_full", context));274 } else {275 return ProcessorErrorFactory.invalid_parameter_type(id, exp);276 }277 },278 invalid_parameter_type: (id, exp) => {279 const context = [exp, id];280 return new SemanticError(LocalizedStrings.getError("invalid_parameter_type_full", context));281 },282 invalid_ref_full: (id, exp, sourceInfo) => {283 if(sourceInfo) {284 const context = [exp, id , sourceInfo.line];285 return new SemanticError(LocalizedStrings.getError("invalid_ref_full", context));286 } else {287 return ProcessorErrorFactory.invalid_ref(id, exp);288 }289 },290 invalid_ref: (id, exp) => {291 const context = [exp, id];292 return new SemanticError(LocalizedStrings.getError("invalid_ref", context));293 },294 unexpected_break_command_full: (sourceInfo) => {295 if(sourceInfo) {296 const context = [sourceInfo.line];297 return new RuntimeError(LocalizedStrings.getError("unexpected_break_command_full", context));298 } else {299 return ProcessorErrorFactory.unexpected_break_command();300 }301 },302 unexpected_break_command: () => {303 return new RuntimeError(LocalizedStrings.getError("unexpected_break_command"));304 },305 invalid_array_literal_type_full: (exp, sourceInfo) => {306 if(sourceInfo) {307 const context = [sourceInfo.line, exp];308 return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_type_full", context));309 } else {310 return ProcessorErrorFactory.invalid_array_literal_type(exp);311 }312 },313 invalid_array_literal_type: (exp) => {314 const context = [exp];315 return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_type", context));316 },317 invalid_array_literal_line_full: (expected, actual, sourceInfo) => {318 if(sourceInfo) {319 const context = [sourceInfo.line, expected, actual];320 return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_line_full", context));321 } else {322 return ProcessorErrorFactory.invalid_array_literal_type(expected, actual);323 }324 },325 invalid_array_literal_line: (expected, actual) => {326 const context = [expected, actual];327 return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_line", context));328 },329 invalid_array_literal_column_full: (expected, actual, sourceInfo) => {330 if(sourceInfo) {331 const context = [sourceInfo.line, expected, actual];332 return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_column_full", context));333 } else {334 return ProcessorErrorFactory.invalid_array_literal_column(expected, actual);335 }336 },337 invalid_array_literal_column: (expected, actual) => {338 const context = [expected, actual];339 return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_column", context));340 },341 invalid_unary_op_full: (expString, opName, type, dim, sourceInfo) => {342 if(sourceInfo) {343 const context = [sourceInfo.line, expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];344 return new RuntimeError(LocalizedStrings.getError("invalid_unary_op_full", context));345 } else {346 return ProcessorErrorFactory.invalid_unary_op(opName, type, dim);347 }348 },349 invalid_unary_op: (expString, opName, type, dim) => {350 const context = [expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];351 return new RuntimeError(LocalizedStrings.getError("invalid_unary_op", context));352 },353 invalid_infix_op_full: (expString, opName, typeLeft, dimLeft, typeRight, dimRight, sourceInfo) => {354 if(sourceInfo) {355 const context = [sourceInfo.line, expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];356 return new RuntimeError(LocalizedStrings.getError("invalid_infix_op_full", context));357 } else {358 return ProcessorErrorFactory.invalid_infix_op(opName, typeLeft, dimLeft, typeRight, dimRight);359 }360 },361 invalid_infix_op: (expString, opName, typeLeft, dimLeft, typeRight, dimRight) => {362 const context = [expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];363 return new RuntimeError(LocalizedStrings.getError("invalid_infix_op", context));364 },365 array_dimension_not_positive_full: (sourceInfo) => {366 if(sourceInfo) {367 const context = [sourceInfo.line];368 return new SemanticError(LocalizedStrings.getError("array_dimension_not_positive_full", context));369 } else {370 return ProcessorErrorFactory.array_dimension_not_positive();371 }372 },373 array_dimension_not_positive: () => {374 return new SemanticError(LocalizedStrings.getError("array_dimension_not_positive"));375 },376 invalid_type_conversion: (value, type, dim) => {377 const context = [value, LocalizedStrings.translateType(type, dim)];378 return new RuntimeError(LocalizedStrings.getError("invalid_type_conversion", context));379 },380 invalid_read_type: (exp, type, dim, name) => {381 const context = [exp, LocalizedStrings.translateType(type, dim), name];382 return new RuntimeError(LocalizedStrings.getError("invalid_read_type", context))383 },384 invalid_read_type_array: (exp, typePos, dimPos, name, typeArray, dimArray) => {385 const context = [exp, LocalizedStrings.translateType(typePos, dimPos), name,LocalizedStrings.translateType(typeArray, dimArray)];386 return new RuntimeError(LocalizedStrings.getError("invalid_read_type_array", context))387 }...

Full Screen

Full Screen

apply-to-nulls.js

Source:apply-to-nulls.js Github

copy

Full Screen

...44 listChildJsx = formData.listChild.map((lc, index) => {45 return (46 <div key={index}>47 <TextField48 error={!!getError(`listChild{${index}}`)}49 helperText={getError(`listChild{${index}}`) || ' '}50 label="unique"51 type="text"52 value={getValue(`listChild[${index}]`) || ''}53 onChange={(e) => setPathValue(`listChild[${index}]`, e.target.value)}54 />55 <Button className="myDeleteButton" variant="contained" onClick={() => handleDeleteElement(index)}>56 <span className="myShinkableButtonSpan">Delete Element</span>57 <DeleteIcon className="myShinkableButtonIcon" />58 </Button>59 </div>60 );61 });62 }63 return (64 <ExampleUsageWrapper header="applyToNulls" codeUrl="pages/customizations/apply-to-nulls.js">65 <p className="infoParagraph">66 By default <b>react-validatable-form</b> interprets <b>undefined</b>, <b>null</b>, <b>empty string</b>{' '}67 or <b>empty array</b> values as valid values. If you want any rule to be applied to these values,{' '}68 <b>applyToNulls</b> parameter should be used.69 </p>70 <div>71 <TextField72 error={!!getError('val1')}73 helperText={getError('val1') || ' '}74 label="requiredApplyToNulls"75 type="text"76 value={getValue('val1') || ''}77 onChange={(e) => setPathValue('val1', e.target.value)}78 />79 </div>80 <div>81 <TextField82 error={!!getError('val2')}83 helperText={getError('val2') || ' '}84 label="numberApplyToNulls"85 type="number"86 value={getValue('val2') || ''}87 onChange={(e) => setPathValue('val2', e.target.value)}88 />89 </div>90 <div>91 <TextField92 error={!!getError('val3')}93 helperText={getError('val3') || ' '}94 label="lengthApplyToNulls"95 type="text"96 value={getValue('val3') || ''}97 onChange={(e) => setPathValue('val3', e.target.value)}98 />99 </div>100 <div>101 <Autocomplete102 multiple103 value={getValue('val4') || []}104 onChange={(event, newValue) => {105 setPathValue('val4', newValue);106 }}107 options={options}108 renderInput={(params) => (109 <TextField110 {...params}111 error={!!getError('val4')}112 helperText={getError('val4') || ' '}113 label="listSizeApplyToNulls"114 />115 )}116 />117 </div>118 <div>119 <DesktopDatePicker120 label="dateApplyToNulls"121 inputFormat="MM/dd/yyyy"122 value={getValue('val5') || null}123 onChange={(val) => setPathValue('val5', val)}124 renderInput={(params) => (125 <TextField {...params} error={!!getError('val5')} helperText={getError('val5') || ' '} />126 )}127 />128 </div>129 <div>130 <TextField131 error={!!getError('val6')}132 helperText={getError('val6') || ' '}133 label="emailApplyToNulls"134 type="text"135 value={getValue('val6') || ''}136 onChange={(e) => setPathValue('val6', e.target.value)}137 />138 </div>139 <div>140 <TextField141 error={!!getError('val7')}142 helperText={getError('val7') || ' '}143 label="urlApplyToNulls"144 type="text"145 value={getValue('val7') || ''}146 onChange={(e) => setPathValue('val7', e.target.value)}147 />148 </div>149 <div>150 <TextField151 error={!!getError('val8')}152 helperText={getError('val8') || ' '}153 label="ibanApplyToNulls"154 type="text"155 value={getValue('val8') || ''}156 onChange={(e) => setPathValue('val8', e.target.value)}157 />158 </div>159 <div>160 <TextField161 error={!!getError('val9')}162 helperText={getError('val9') || ' '}163 label="equalityApplyToNulls"164 type="text"165 value={getValue('val9') || ''}166 onChange={(e) => setPathValue('val9', e.target.value)}167 />168 </div>169 <div>170 <TextField171 error={!!getError('val10')}172 helperText={getError('val10') || ' '}173 label="regexApplyToNulls"174 type="text"175 value={getValue('val10') || ''}176 onChange={(e) => setPathValue('val10', e.target.value)}177 />178 </div>179 <div>180 <Button className="myAddButton" variant="contained" onClick={handleAddElement}>181 <span className="myShinkableButtonSpan">Add New Element</span>182 <AddIcon className="myShinkableButtonIcon" />183 </Button>184 </div>185 <div className={'formListField'}>{listChildJsx}</div>186 <div className={'errorInfoText'}>{getError('listChild')}</div>187 <ValidationResult isValid={isValid} />188 <CurrentRulesInfo currentRules={rules} />189 </ExampleUsageWrapper>190 );191};...

Full Screen

Full Screen

syntaxErrorFactory.js

Source:syntaxErrorFactory.js Github

copy

Full Screen

1import * as LocalizedStringsService from './../../services/localizedStringsService';2import { SyntaxError } from './syntaxError';3const LocalizedStrings = LocalizedStringsService.getInstance();4export const SyntaxErrorFactory = Object.freeze({5 extra_lines: () => new SyntaxError(LocalizedStrings.getError("extra_lines")),6 token_missing_one: (expected, token) => {7 const context = [expected, token.text, token.line, token.column];8 return new SyntaxError(LocalizedStrings.getError("token_missing_one", context));9 },10 token_missing_list: (expectedList, token) => {11 const line = expectedList.join(LocalizedStrings.getOR());12 return SyntaxErrorFactory.token_missing_one(line, token);13 },14 id_missing: (token) => {15 const context = [token.text, token.line, token.column];16 return new SyntaxError(LocalizedStrings.getError("id_missing", context));17 },18 eos_missing: (token) => {19 const context = [token.line, token.column];20 return new SyntaxError(LocalizedStrings.getError("eos_missing", context));21 },22 invalid_array_dimension: (typeName, token) => {23 const context = [token.line, token.column, typeName];24 return new SyntaxError(LocalizedStrings.getError("invalid_array_dimension", context));25 },26 invalid_array_size: (token) => {27 const context = [token.line];28 return new SyntaxError(LocalizedStrings.getError("invalid_array_size", context));29 },30 invalid_main_return: (name, typeName, token) => {31 const context = [name, typeName, token.line];32 return new SyntaxError(LocalizedStrings.getError("invalid_main_return", context));33 },34 invalid_var_declaration: (token) => {35 const context = [token.line];36 return new SyntaxError(LocalizedStrings.getError("invalid_var_declaration", context));37 },38 invalid_break_command: (cmdName, token) => {39 const context = [token.line, cmdName];40 return new SyntaxError(LocalizedStrings.getError("invalid_break_command", context));41 },42 invalid_terminal: (token) => {43 const context = [token.text, token.line, token.column];44 return new SyntaxError(LocalizedStrings.getError('invalid_terminal', context));45 },46 invalid_type: (list, token) => {47 const line = list.join(LocalizedStrings.getOR());48 const context = [token.text, token.line, token.column, line]49 return new SyntaxError(LocalizedStrings.getError("invalid_type", context));50 },51 const_not_init: (token) => {52 const context = [token.line, token.column];53 return new SyntaxError(LocalizedStrings.getError("const_not_init", context));54 },55 invalid_id_format: (token) => {56 const context = [token.text, token.line, token.column];57 return new SyntaxError(LocalizedStrings.getError("invalid_id_format", context));58 },59 duplicate_function: (token) => {60 const context = [token.text, token.line, token.column];61 return new SyntaxError(LocalizedStrings.getError("duplicate_function", context));62 },63 main_parameters: () => {64 return new SyntaxError(LocalizedStrings.getError("main_parameters"));65 },66 duplicate_variable: (token) => {67 const context = [token.text, token.line, token.column];68 return new SyntaxError(LocalizedStrings.getError("duplicate_variable", context));69 }...

Full Screen

Full Screen

state.spec.js

Source:state.spec.js Github

copy

Full Screen

...5afterEach(() => createCompiler.teardown());6it('should have correct state before and after a successful run', async () => {7 const compiler = createCompiler(configBasic);8 expect(compiler.isCompiling()).toBe(false);9 expect(compiler.getError()).toBe(null);10 expect(compiler.getCompilation()).toBe(null);11 const compilation = await compiler.run();12 expect(compilation).toBeDefined();13 expect(compiler.isCompiling()).toBe(false);14 expect(compiler.getError()).toBe(null);15 expect(compiler.getCompilation()).toBe(compilation);16});17it('should have correct state before and after a failed run', async () => {18 const compiler = createCompiler(configSyntaxError);19 expect.assertions(7);20 expect(compiler.isCompiling()).toBe(false);21 expect(compiler.getError()).toBe(null);22 expect(compiler.getCompilation()).toBe(null);23 try {24 await compiler.run();25 } catch (err) {26 expect(err).toBeDefined();27 expect(compiler.isCompiling()).toBe(false);28 expect(compiler.getError()).toBe(err);29 expect(compiler.getCompilation()).toBe(null);30 }31});32it('should have correct state before and after a successful watch run', (done) => {33 const compiler = createCompiler(configBasic);34 expect(compiler.isCompiling()).toBe(false);35 expect(compiler.getError()).toBe(null);36 expect(compiler.getCompilation()).toBe(null);37 compiler.watch((err, compilation) => {38 expect(err).toBe(null);39 expect(compilation).toBeDefined();40 expect(compiler.isCompiling()).toBe(false);41 expect(compiler.getError()).toBe(err);42 expect(compiler.getCompilation()).toBe(compilation);43 done();44 });45 expect(compiler.isCompiling()).toBe(true); // Takes some time to start compiling46 expect(compiler.getError()).toBe(null);47 expect(compiler.getCompilation()).toBe(null);48});49it('should have correct state before and after a failed watch run', (done) => {50 const compiler = createCompiler(configSyntaxError);51 expect(compiler.isCompiling()).toBe(false);52 expect(compiler.getError()).toBe(null);53 expect(compiler.getCompilation()).toBe(null);54 compiler.watch((err, compilation) => {55 expect(err).toBeDefined();56 expect(compilation).toBe(null);57 expect(compiler.isCompiling()).toBe(false);58 expect(compiler.getError()).toBe(err);59 expect(compiler.getCompilation()).toBe(null);60 done();61 });62 expect(compiler.isCompiling()).toBe(true); // Takes some time to start compiling63 expect(compiler.getError()).toBe(null);64 expect(compiler.getCompilation()).toBe(null);...

Full Screen

Full Screen

z_entity.get.js

Source:z_entity.get.js Github

copy

Full Screen

1// Load libraries2var _ = require( 'underscore' );3var util = require( 'util' );4var CS = require( '../core' );5// Use a child logger6var log = CS.log.child( { component: 'Get API' } );7// Generate custom error `GetError` that inherits8// from `APIError`9var APIError = require( './error' );10var GetError = function( id, message, status ) {11 /* jshint camelcase: false */12 GetError.super_.call( this, id, message, status );13};14util.inherits( GetError, APIError );15GetError.prototype.name = 'GetError';16// Custom error IDs17GetError.BAD_ID = 'BAD_ID';18GetError.BAD_ENTITY_NAME = 'BAD_ENTITY_NAME';19GetError.BAD_ENTITY_PROPERTY = 'BAD_ENTITY_PROPERTY';20GetError.OBJECT_NOT_FOUND = 'OBJECT_NOT_FOUND';21// API object returned by the file22// -----23var API = {24 // The API endpoint. The final endpoint will be:25 // /api/**endpointUrl**26 url: ':entity/:property?',27 // The API method to implement.28 method: 'GET'29};30// API core function logic. If this function is executed then each check is passed.31API.logic = function getApi( req, res, next ) {32 var entity = req.params.entity;33 entity = entity==='performer'? 'user' : entity;34 var property = req.params.property;35 log.trace( 'Getting %s for %s ', property || 'all properties', entity );36 // Get the model based on the `entity` parameter.37 var model = CS.models[ entity ];38 if( _.isUndefined( model ) )39 return next( new GetError( GetError.BAD_ENTITY_NAME, 'Unable to retrieve the entity "'+entity+'"', APIError.BAD_REQUEST ) );40 if( !_.isUndefined( property ) ) {41 var pathInfo = model.schema.path( property );42 var pathType = model.schema.pathType( property );43 if( _.isUndefined( pathInfo ) && pathType!=='nested' )44 return next( new GetError( GetError.BAD_ENTITY_PROPERTY, 'The entity "'+entity+'" has no "'+property+'" property', APIError.BAD_REQUEST ) );45 }46 var entityId = req.query[ entity ];47 if( _.isUndefined( entityId ) )48 return next( new GetError( GetError.BAD_ID, 'You must specify a "'+entity+'" query parameter', APIError.BAD_REQUEST ) );49 var query = model.findById( entityId );50 if( property )51 query.select( property );52 req.queryObject = query;53 return next();54};55// Export the API object...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const available = require('available');2const domainName = 'google.com';3available.getError(domainName, function (err, res) {4 console.log(err);5 console.log(res);6});7const available = require('available');8const domainName = 'google.com';9available.getError(domainName).then(function (res) {10 console.log(res);11}).catch(function (err) {12 console.log(err);13});14const available = require('available');15const domainName = 'google.com';16available.getError(domainName, function (err, res) {17 console.log(err);18 console.log(res);19});20const available = require('available');21const domainName = 'google.com';22available.getError(domainName).then(function (res) {23 console.log(res);24}).catch(function (err) {25 console.log(err);26});27const available = require('available');28const domainName = 'google.com';29available.getError(domainName, function (err, res) {30 console.log(err);31 console.log(res);32});33const available = require('available');34const domainName = 'google.com';35available.getError(domainName).then(function (res) {36 console.log(res);37}).catch(function (err) {38 console.log(err);39});40const available = require('available');41const domainName = 'google.com';42available.getError(domainName, function (err, res) {43 console.log(err);44 console.log(res);45});46const available = require('available');47const domainName = 'google.com';48available.getError(domainName).then(function (res) {49 console.log(res);50}).catch(function (err) {51 console.log(err);52});53const available = require('available');54const domainName = 'google.com';55available.getError(domainName, function (err, res) {56 console.log(err);57 console.log(res);58});59const available = require('available');60const domainName = 'google.com';61available.getError(domainName).then(function (res) {62 console.log(res);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { availableErrorCodes } = require('error-code-generator');2const err = availableErrorCodes.getError('ERR-001');3console.log(err);4const { availableErrorCodes } = require('error-code-generator');5const err = availableErrorCodes.getError('ERR-001');6console.log(err);7const { availableErrorCodes } = require('error-code-generator');8const err = availableErrorCodes.getError('ERR-001');9console.log(err);10const { availableErrorCodes } = require('error-code-generator');11const err = availableErrorCodes.getError('ERR-001');12console.log(err);13const { availableErrorCodes } = require('error-code-generator');14const err = availableErrorCodes.getError('ERR-001');15console.log(err);16const { availableErrorCodes } = require('error-code-generator');17const err = availableErrorCodes.getError('ERR-001');18console.log(err);19const { availableErrorCodes } = require('error-code-generator');20const err = availableErrorCodes.getError('ERR-001');21console.log(err);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { InvalidArgumentError } = require('./errors');2const err = new InvalidArgumentError('Invalid argument', 'argument');3console.log(err.getError());4const { CustomError } = require('./errors');5const err = new CustomError('Custom Error', 'custom');6console.log(err.getError());7const { CustomError } = require('./errors');8const { CustomError2 } = require('./errors');9const err = new CustomError2('Custom Error2', 'custom2');10console.log(err.getError());11const { CustomError } = require('./errors');12const { CustomError2 } = require('./errors');13const { CustomError3 } = require('./errors');14const err = new CustomError3('Custom Error3', 'custom3');15console.log(err.getError());16class InvalidArgumentError extends Error {17 constructor(message, argument) {18 super(message);19 this.name = 'InvalidArgumentError';20 this.argument = argument;21 }22 getError() {23 return {24 };25 }26}27class CustomError extends Error {28 constructor(message, argument) {29 super(message);30 this.name = 'CustomError';31 this.argument = argument;32 }33 getError() {34 return {35 };36 }37}38class CustomError2 extends Error {39 constructor(message, argument) {40 super(message);41 this.name = 'CustomError2';42 this.argument = argument;43 }44 getError() {45 return {46 };47 }48}49class CustomError3 extends Error {50 constructor(message, argument) {51 super(message);52 this.name = 'CustomError3';53 this.argument = argument;54 }55 getError() {56 return {57 };58 }59}60module.exports = {61};

Full Screen

Using AI Code Generation

copy

Full Screen

1var availableError = require('./availableError');2var error = new availableError();3var errorObject = error.getError('ERR001');4console.log(errorObject);5function availableError() {6}7availableError.prototype.getError = function (errorCode) {8 var errors = {9 ERR001: {10 },11 ERR002: {12 }13 }14 return errors[errorCode];15}16module.exports = availableError;

Full Screen

Using AI Code Generation

copy

Full Screen

1const availableErrors = require('available-errors');2const { getError } = availableErrors;3const error = getError('NOT_FOUND', { message: 'user not found' });4throw error;5const availableErrors = require('available-errors');6const { errorMiddleware } = availableErrors;7app.use(errorMiddleware);8const availableErrors = require('available-errors');9const { CustomError } = availableErrors;10throw new CustomError('NOT_FOUND', { message: 'user not found' });11throw new BadRequestError('BAD_REQUEST', { message: 'bad request' });12throw new UnauthorizedError('UNAUTHORIZED', { message: 'unauthorized' });13throw new ForbiddenError('FORBIDDEN', { message: 'forbidden' });14throw new NotFoundError('NOT_FOUND', { message: 'not found' });15throw new ConflictError('CONFLICT', { message: 'conflict' });16throw new InternalServerError('INTERNAL_SERVER_ERROR', { message: 'internal server error' });

Full Screen

Using AI Code Generation

copy

Full Screen

1var available = require('./available.js');2var getError = available.getError;3var error = getError(1);4console.log(error);5{ code: 1, message: 'Resource not found' }6exports.getError = function (code) {7 return { code: code, message: 'Resource not found' };8};9exports.getSuccess = function (code) {10 return { code: code, message: 'Success' };11};12var multiple = require('./multiple.js');13var getError = multiple.getError;14var getSuccess = multiple.getSuccess;15var error = getError(1);16var success = getSuccess(2);17console.log(error);18console.log(success);19{ code: 1, message: 'Resource not found' }20{ code: 2, message: 'Success' }

Full Screen

Using AI Code Generation

copy

Full Screen

1{2 {3 "error": {4 "properties": {5 },6 }7 },8 {9 "error": {10 "properties": {11 },12 }13 }14}15MIT © [Kushagra Pandey](

Full Screen

Using AI Code Generation

copy

Full Screen

1const availableErrorTypes = require('./errorTypes.js');2const errorObject = availableErrorTypes.getError('E001');3console.log(errorObject.errorMessage);4console.log(errorObject.errorCode);5console.log(errorObject.errorDescription);6console.log(errorObject.errorType);7console.log(errorObject.errorType);8console.log(errorObject.errorType);9| getError(errorCode) | Returns the error object based on the error code |10| getError(errorCode) | Returns the error object based on the error code |

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ava automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful