自用游戏HTML5 sdk技术设计手册

 

1、概述

         1.1. 目的

              指导合作伙伴的HTML5工程师开发集成sgt平台开放能力。

 

2、准备

         2.1. 技术架构

                   通讯协议是jsonrpc2.0,https://github.com/Textalk/jquery.jsonrpcclient.js

                   使用jQuery库

 

       2.2. 引用jQueryjsonrpc2.0

          
<script type="text/javascript" src="js/jquery.1.9.1.js"></script>

<script type="text/javascript" src="js/jquery.jsonrpcclient.js"></script>

 

 

       2.2. 定义变量

   var sgth5={

      Appid:null,//zsd_sgp 应用标识

      Appgateway:‘http://…………/route‘,//网关

      Approutedata:null,//节点node

      channelId:null,//标识

      username:null,//用户

      userpassword:null,//用户密码

      userdata:null,//用户信息

      playserverdata:null,//player服务器信息

   };

 

         用户使用前先填写Appid、Appgateway、channelId信息

       2.2. 定义对象

Player对象

var player=function(){

      this.customId=null,//String 自定义ID

      this.equip=null,//String 装备

      this.id=0,//String 主键

      this.lastLoginTime=sgth5.userdata.lastLoginTime,

      this.level=null,//int 等级

      this.name=null,//String 名字

      this.serverId=sgth5.playserverdata.id,

      this.type=null,//String 类型

      this.userId=sgth5.userdata.userid,

      this.vip=null;//int VIP 等级

   };

 

mail对象

 var mail=function(){

      this.attachment=null,//String 附件

      this.content=null,//String 内容

      this.fromId=null,//String 发送者ID

      this.fromName=null,//String 发送者名称

      this.id=null,//主键

      this.sendTime=(new Date()).getTime(),//发送时间

      this.status=0,//状态

      this.title=null,//String 标题

      this.toId=null,//String 接收者ID

      this.toName=null,//String 接收者名称

      this.type=0;//类型

};

 

 

ticke对象

 

var Ticke=function(){

   this.content=null,//反馈给后台的内容

   this.createTime=(new Date()).getTime(),//提交时间

   this.feedbackInfo=null,//处理完返回给提交者的信息

   this.id=0,//主键

   this.senderPlayerId=null,//提交者ID

   this.status=1,//状态

   this.targetPlayerId=null,//目标角色ID

   this.title=null,//标题

   this.type=1;//类型

};

 

3、接入流程

         3.1. url解释

  Var backClient=new $.JsonRpcClient({ajaxUrl: ${host}+‘/‘+ ${appid}+‘/${appServer}.do‘ });

 

         3.2 API设计

   

sgth5.GetPlayerInfo=sgth5.Class.extend({
        url:null,
        playerId:null,
        userData:null,
        playerData:null,//当前角色信息
        init:function(){
            if(sgth5.GetServer.userData==null){
                console.log(‘There was an error:‘, ‘没有取得用户数据!‘);
                return false;
            }
            if(sgth5.GetServer.playServerData==null){
                console.log(‘There was an error:‘, ‘没获取角色服务器信息!‘);
                return false;
            }
            this.userData=sgth5.GetServer.userData;
            this.url=sgth5.GetServer.playServerData.address+‘/‘+sgt.AppId+‘/sgpplayer.do‘;
            return true;
        },
        /**创建角色
         * playerinfo palyer对象
         * 
         * obj  回调函数
         */
        creatPlayer:function(playerinfo,obj){
            playerinfo.lastLoginTime=this.userData.lastLoginTime;
            playerinfo.serverId=sgth5.GetServer.playServerData.id;
            playerinfo.userId=this.userData.userid;
            
            var backClient = new $.JsonRpcClient({ ajaxUrl: this.url });
            backClient.call(
              ‘create‘,
              [playerinfo],
              function(result){
                  obj(true,result);
              },
              function(error){
                  console.log(‘There was an error:‘, error);
                  obj(false,error.message);
              }
            );
        }
    ……
        
});
sgth5.GetPlayerInfo.create=function(playerId){
    var ret = new sgth5.GetPlayerInfo();
    if(playerId!=null){
        ret.playerId=playerId;
    }
    if (ret && ret.init())
        return ret;
    return null;
};

 

 

4API定义

/**

 * 获取获取注册或登录的服务器api

 */

sgth5.getnode={

   /**

    * 获取user节点

    * type String 类型

    * obj  回调函数

    */

   getRegisterServer:function(type,obj){

   ……

   },

   /**

    * 玩家注册

    *

    * obj  回调函数

    */

   register:function(obj){

   ……

   },

   /**

    * 玩家登录

    *

    * obj  回调函数

    */

   login:function(obj){

   ……

   },

   /**

    * 获取player服务器信息

    *

    * obj  回调函数

    */

   getplayserver:function(obj){

   ……

   }

};

 

/**

 * 玩家角色API

 */

 

sgth5.getplayerinfo={

      /**创建角色

       * playerinfo palyer对象

       *

       * obj  回调函数

       */

      creatplayer:function(playerinfo,obj){

   ……

      },

……

……

};

sgth5.GetPlayerInfo.create=function(playerId){
var ret = new sgth5.GetPlayerInfo();
if(playerId!=null){
ret.playerId=playerId;
}
if (ret && ret.init())
return ret;
return null;
};

 

 

/**

 * 公告API

 */

sgth5.announcementinfo=sgth5.Class.extend({

……

……

});

 


sgth5.announcementinfo.create=function(playerId){
……
};

/**

 * 签到API

 */

sgth5.Checkininfo=sgth5.Class.extend({

……

……

});

 

 

 

/**

 * 排行榜API

 */

sgth5.LeaderBoardinfo=sgth5.Class.extend({

……

……

});

 

 

/**

 * 邮件API

 */

 

sgth5.Mailinfo=sgth5.Class.extend({

……

……

});

 

/**

 * 活动业务接口

 */

sgth5.Campaigninfo=sgth5.Class.extend({

……

……

});

 

 

/**

 * BOSS业务接口

 */

sgth5.Bossinfo=sgth5.Class.extend({

……

……

});

 

 

 

/**

 * 抽奖业务接口

 */

sgth5.GachaBoxinfo=sgth5.Class.extend({

 

……

……

});

 

 

/**

 * 黑名单业务接口

 */

sgth5.Blacklistinfo=sgth5.Class.extend({

 

……

……

});

/**

 * 好友业务接口

 */

sgth5.Friendshipinfo=sgth5.Class.extend({

 

……

……

});

/**

 * 反馈举报 业务接口

 */

sgth5.Tickeinfo=sgth5.Class.extend({

 

……

……

});

 

 第一次开发设计SDK可能有很多不合理的地方,有大神可以指点一下!

 

自用游戏HTML5 sdk技术设计手册,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。