loginApp是整个bigworld进行用户认证的服务,是用户进入游戏的第一步。本篇主要针对loginApp的认证流程,如何和其他服务进行交互,以及loginApp针对多服务负载的不同做法进行分析。

  1. loginApp用户认证流程

  用户通过loginApp认证,主要是以下几个步骤:

  (1) client发送认证请求(前提是他已经知道loginApp的ip和端口)

  (2) loginApp在其监听端口上,收到这个请求

  (3) 收到请求之后,loginApp将认证信息转发给DBMgr,通过DBMgr来验证登陆认证是否合法

  (4) DBMgr通过查询数据库来进行确认

  (5) 如果认证是合法的,那么DBMgr通知BaseAppMgr去创建一个新的entity(玩家实例)

  (6) BaseAppMgr将创建新entity的需求,转发给当前负载最小的BaseApp

  (7) BaseApp创建一个新的Proxy,Proxy就是BaseApp上代表用户的实例

  (8) 同时可能需要在CellApp中创建一个玩家entity,这个要根据实际的项目需要了。也有可能直到用户选取了角色之后,才在cellApp中创建entity。

  (9) 当上门的事情都做完之后,proxy的UDP端口将结果返回给client(通过BaseAppMgr,DBMgr,最后LoginApp)

  上述流程的示意图是这样的:

  

  2. loginApp认证流程在代码中的体现

  代码只截取认为最重要的部分和关键语句,大部分代码省略,使用//......来代替

  (2)(3)loginApp收到认证请求,并且转发:

  

  
  // 先针对参数有效性进行检查
  // ......   // 判断是不是上一个认证请求还没做完
  // First check whether this is a repeat attempt from a recent pending
// login before attempting to decrypt and log in.
if (this->handleResentPendingAttempt( source, header.replyID ))
{
// ignore this one, it's in progress
loginStats_.incPending();
return;
} // 判断是否是否了加密
#ifdef USE_OPENSSL
Mercury::PublicKeyCipher * pPrivateKey = &privateKey_;
#else
Mercury::PublicKeyCipher * pPrivateKey = NULL;
#endif //.......

  // 判断是否之前有认证cache
// First check whether this is a repeat attempt from a recent
// resolved login before attempting to log in.
if (this->handleResentCachedAttempt( source, pParams, header.replyID ))
{
// ignore this one, we've seen it recently
return;
} // ...... INFO_MSG( "Logging in %s{%s} (%s)\n",
pParams->username().c_str(),
pParams->password().c_str(),
source.c_str() ); // Remember that this attempt is now in progress and discard further
// attempts from that address for some time after it completes.
cachedLoginMap_[ source ].reset();
cachedLoginMap_[ source ].pParams( pParams ); DatabaseReplyHandler * pDBHandler =
new DatabaseReplyHandler( source, header.replyID, pParams );
  
  
  // 发送给DBMgr
Mercury::Bundle & dbBundle = this->dbMgr().bundle();
dbBundle.startRequest( DBInterface::logOn, pDBHandler ); dbBundle << source << false /*off channel*/ << *pParams; this->dbMgr().send();

  

  (9) 认证消息返回给client代码

 void DatabaseReplyHandler::handleMessage(    const Mercury::Address & /*source*/,    Mercury::UnpackedMessageHeader & header,    BinaryIStream & data,

void * /*arg*/ )
{
uint8 status;
data >> status;

  //
检查认证返回码
if (status != LogOnStatus::LOGGED_ON)
{
    //
如果认证失败
    // ......

} LoginReplyRecord lrr;
data >> lrr; // If the client has an external address, send them the firewall
// address instead! if (!LoginApp::instance().netMask().containsAddress( clientAddr_.ip ))
{
INFO_MSG( "DatabaseReplyHandler::handleMessage: "
"Redirecting external client %s to firewall.\n",
clientAddr_.c_str() );
lrr.serverAddr.ip = LoginApp::instance().externalIP();
}
  
  // 返回client认证结果,并且缓存认证结果
  LoginApp::instance().sendAndCacheSuccess( clientAddr_, replyID_, lrr, pParams_ ); gNumLogins++; delete this;
}

  3. loginApp是如何做负载的

  loginApp是bigworld中用来处理用户登录认证的,为了防止单一loginApp存在性能瓶颈,同时防止单点故障,bigworld也是可以运行同时运行多个loginApp。不过我们知道多个baseApp和cellApp是分别有,baseAppMgr和cellAppMgr来做管理和负载的,loginApp我们却没有找到类似的loginAppMgr。

  在bigworld的文档中,是这样写的:

In terms of load, a single LoginApp should be sufficient for most purposes. However, as this is still a potential bottleneck, and single point of failure, BigWorld supports running multiple LoginApps.
The remaining issue then is how to distribute the client login requests across multiple login servers. The standard way to do this is use a DNS solution similar to how popular web sites balance traffic load across multiple machines.

  从上面的介绍来看,bigworld本身确实是没有提供类似的loginAppMgr,而是需要我们使用DNS来做负载,DNS返回不同的loginApp ip,来分担压力。

bigworld源码分析(2)—— loginApp分析的更多相关文章

  1. bigworld源码分析(3)——dbMgr分析

    dbMgr主要是玩家数据的读取和保存的,例如在bigworld源码分析(3)中,玩家在认证的时候,loginApp需要通过dbMgr来验证玩家数据是否合法,这就是针对玩家的账号数据进行查询.本篇中,我 ...

  2. bigworld源码分析(1)—— 研究bigworld的意义和目标

    对于网络游戏服务器开发熟悉的人,基本都知道bigworld引擎,此引擎包括客户端部分和服务器部分,已经有很多知名的网络游戏通过bigworld来构建游戏.我主要关注bigworld的服务器部分,它是一 ...

  3. ArrayList源码和多线程安全问题分析

    1.ArrayList源码和多线程安全问题分析 在分析ArrayList线程安全问题之前,我们线对此类的源码进行分析,找出可能出现线程安全问题的地方,然后代码进行验证和分析. 1.1 数据结构 Arr ...

  4. Okhttp3源码解析(3)-Call分析(整体流程)

    ### 前言 前面我们讲了 [Okhttp的基本用法](https://www.jianshu.com/p/8e404d9c160f) [Okhttp3源码解析(1)-OkHttpClient分析]( ...

  5. Okhttp3源码解析(2)-Request分析

    ### 前言 前面我们讲了 [Okhttp的基本用法](https://www.jianshu.com/p/8e404d9c160f) [Okhttp3源码解析(1)-OkHttpClient分析]( ...

  6. Spring mvc之源码 handlerMapping和handlerAdapter分析

    Spring mvc之源码 handlerMapping和handlerAdapter分析 本篇并不是具体分析Spring mvc,所以好多细节都是一笔带过,主要是带大家梳理一下整个Spring mv ...

  7. HashMap的源码学习以及性能分析

    HashMap的源码学习以及性能分析 一).Map接口的实现类 HashTable.HashMap.LinkedHashMap.TreeMap 二).HashMap和HashTable的区别 1).H ...

  8. ThreadLocal源码及相关问题分析

    前言 在高并发的环境下,当我们使用一个公共的变量时如果不加锁会出现并发问题,例如SimpleDateFormat,但是加锁的话会影响性能,对于这种情况我们可以使用ThreadLocal.ThreadL ...

  9. 物联网防火墙himqtt源码之MQTT协议分析

    物联网防火墙himqtt源码之MQTT协议分析 himqtt是首款完整源码的高性能MQTT物联网防火墙 - MQTT Application FireWall,C语言编写,采用epoll模式支持数十万 ...

  10. Netty 源码学习——客户端流程分析

    Netty 源码学习--客户端流程分析 友情提醒: 需要观看者具备一些 NIO 的知识,否则看起来有的地方可能会不明白. 使用版本依赖 <dependency> <groupId&g ...

随机推荐

  1. 深入对比数据科学工具箱:Python和R之争

    建议:如果只是处理(小)数据的,用R.结果更可靠,速度可以接受,上手方便,多有现成的命令.程序可以用.要自己搞个算法.处理大数据.计算量大的,用python.开发效率高,一切尽在掌握. 概述 在真实的 ...

  2. linux python pip包安装

    python  -m  pip   install    --trusted-host pypi.python.org

  3. 初学者用div+css结构写网页的几个误区

    1.用div+css结构制作静态html网页不等于彻底抛弃古老的table写法.之所以不建议用table来布局网页是因为在网页加载很慢的时候要等table结构加载完成才能看到网页,其次是table的布 ...

  4. Spring4.1.0 整合quartz1.8.2 时 : class not found : org.springframework.scheduling.quartz.JobDetailBean

    最近做一个 Spring4.1.0 集成 quartz1.8.2 定时器功能,一直报 class not found : org.springframework.scheduling.quartz.J ...

  5. Head First 设计模式 --7 适配器模式 外观模式

    适配器模式:将一个类东街口转换成客户期望的另一个接口.适配器让原本接口不兼容的类可以合作无间. 适配器模式有两种,对象适配器和类的适配器.先看一下对象适配器. 还是看最开始鸭子的例子,如果此时鸭子不够 ...

  6. 浅谈HTTP协议(上)

    今天讨论一下HTTP协议.一个做前端的,如果连HTTP协议都不了解,那实在是太不合格了. 首先,什么是HTTP?Hyper Text Transfer Protocol(超文本传输协议),用在浏览器和 ...

  7. NGUI Scroll List

    NGUI Scroll List 1.Add GameObject with Script UI Panel(NGUI -> UI -> NGUI Panel) and Script UI ...

  8. Modify textures at runtime

    动态修改Texture Modify textures at runtime?http://answers.unity3d.com/questions/7906/modify-textures-at- ...

  9. flash透明效果代码分享~~~

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://down ...

  10. BZOJ1996 [Hnoi2010]chorus 合唱队

    很容易想到区间DP 然后发现这个区间只和圆序列的最后一个数有关,而原序列的最后一个数只可能是现在区间的头或者尾 令$f[i][j][0/1]$表示在区间$[i, j]$之间,原序列的最后一个数是当前区 ...