social_server
简介
以pkg形式发布的社交服务器
组件接口
common.gs
社交服主模块的入口文件
提供主模块的初始化和关闭接口
| 函数原型 | 函数作用 | 
|---|---|
| string get_native_path() | 获取本地扩展的路径 | 
| string get_native_boot_file() | 获取本地扩展的启动文件 | 
| void boot() | 主模块的启动接口 | 
| void shutdown() | 主模块的关闭接口 | 
AccountD.gs
账号模块
| 函数原型 | 函数作用 | 
|---|---|
| object assure_connection() | 获取和账号数据库的客户端连接对象 | 
| map read_account(string account) | 获取账号基础资料 | 
| bool create_account(string account, map dbase) | 创建账号基础资料 | 
| bool update_account_field(string account, string field, mixed value) | 更新账号基础资料字段 | 
| bool destroy_account(string account) | 删除账号基础资料 | 
AuthD.gs
账号认证模块
| 函数原型 | 函数作用 | 
|---|---|
| map auth(string account, map args = ) | 账号认证 | 
| bool internal_auth(string token) | 内部连接认证(只需要验证令牌值) | 
| bool set_auth_agent(string name, map agent_info) | 设置服务器使用的认证代理 | 
| map find_auth_agent(string name) | 查找服务器的认证代理 | 
ChatD.gs
聊天模块
ChatMonitorD.gs
聊天监控功能模块
DelayD.gs
提供延迟执行操作的功能模块
| 函数原型 | 函数作用 | 
|---|---|
| void delay_invoke(float seconds, function fn) | 延迟指定时长执行函数 | 
EtcdClientD.gs
etcd server监听模块,仅在[etcd_server]设置时起效
FriendD.gs
好友功能模块
| 函数原型 | 函数作用 | 
|---|---|
| object assure_connection(string server_id) | 获取指定服务器名称的好友数据库的客户端连接对象 | 
| void set_list_friend_ids(object user, array friend_ids) | 记录已经获取的好友id列表 | 
| void delete_list_friend_ids(object user, array friend_ids) | 删除已经获取的好友id列表 | 
| array get_list_friend_ids(object user) | 获取已经获取的好友id列表 | 
| void set_list_blacklist(object user, array blacklist) | 记录已经获取的黑名单id列表 | 
| void delete_list_blacklist(object user, array blacklist) | 删除已经获取的黑名单id列表 | 
| array get_list_blacklist(object user) | 获取已经获取的黑名单id列表 | 
| void set_list_reqs(object user, array reqs) | 记录已经获取的好友请求列表 | 
| void delete_list_reqs(object user, array reqs) | 删除已经获取的好友请求列表 | 
| array get_list_reqs(object user) | 获取已经获取的好友请求列表 | 
InternalD.gs
社交服之间互联功能模块
etcd server模式下:
社交服之间不互连,仅通过etcd server进行消息同步
不需要获取其它社交服务器的列表
只支持广播: 通过内部连接给特定的某个社交服发送消息是没有意义的
社交服务器列表的获取:
- 
来自notify_server的推送 
- 
定时更新 
| 函数原型 | 函数作用 | 
|---|---|
| void set_servers(map servers) | 增量设置社交服务器信息列表 | 
| void sync_and_invoke_local(string op, ...) | 本地执行操作并且同步操作给其他社交服务器 | 
| void sync(string op, ...) | 同步操作给其他社交服务器 | 
| void assure_clients(array ids) | 确保和其它社交服务器的连接(连接不存在则创建) | 
| void close_clients(array ids) | 关闭到其它社交服务器的连接 | 
| void create_clients(array ids) | 创建到其它社交服务器的连接 | 
MailD.gs
邮件功能模块
| 函数原型 | 函数作用 | 
|---|---|
| object assure_connection(string server_id) | 获取指定的服务器名称的邮件数据库的客户端连接 | 
| string get_sys_mailbox_id(string server_id) | 获取指定的服务器名称的系统邮箱id | 
| string get_sys_sender() | 获取系统邮件的发送者 | 
| map pull_mail_list(object user, int count = 10) | 拖取邮件列表(从上一次的位置继续拖取) | 
MomentD.gs
朋友圈功能模块
| 函数原型 | 函数作用 | 
|---|---|
| object assure_connection(string server_id) | 获取指定服务器名称的朋友圈数据库的客户端连接 | 
| int get_last_recv_moment_id(object user, string target) | 获取最近一次记录的目标账号的朋友圈id | 
| void set_last_recv_moment_id(object user, string target, int moment_id) | 记录最近一次的目标账号的朋友圈id | 
| int get_last_recv_moment_comment_id(object user, int moment_id) | 获取最近一次记录的朋友圈评论id | 
| void set_last_recv_moment_comment_id(object user, int moment_id, int cmoment_id) | 记录最近一次的朋友圈评论id | 
| map pull_moment_list(object user, string target, int count = 10) | 拖取指定目标账号的朋友圈列表(从上一次拖取的位置继续拖取) | 
| bool upload_photo_buff(object user, int photo_id, buffer photo_part_buff, map para = ) | 上传照片 | 
| map fetch_photo_buff(object user, int photo_id, map para = ) | 获取图片二进制内容 | 
NotifyClientD.gs
作为客户端对接通知服务器的功能模块
| 函数原型 | 函数作用 | 
|---|---|
| bool is_self_notify_enabled() | 是否启动本机消息推送 | 
| map get_all_servers() | 获取通知服务器的所有用户列表 | 
| void notify(string server_id, mixed name_or_names, map args = ) | 向指定服务器id和指定的账户列表发送通知消息 | 
| void push(string event, map info = ) | 向通知服务器发送推送消息 | 
SwordD.gs
敏感词功能模块
一共有四种方式可以屏蔽敏感词,同时只有一种方式起效
方式一:接入最新的雷霆内容安全平台(基于pkt.leiting.sword)
方式二:接入老的雷霆内容安全平台(基于pkt.lt_sword)
方式三:接入敏感词服务器(基于pkg.sword_client)
方式四:接入本地敏感词功能模块(基于pkg.ssword)
可以通过配置[screen_all_sword]配置关闭全部敏感词功能
| 函数原型 | 函数作用 | 
|---|---|
| array filter_content(map msg) | 内容过滤 | 
| void set_game_code_and_key(string game_code, string key) | 设置雷霆内容安全平台游戏码和签名密钥 | 
| map patrol_init(map msg) | 生成一个巡服上报消息实例 | 
| void patrol_set_field(map m, string key, mixed val) | 设置巡服上报键值 | 
| void patrol(map m, function func) | 执行巡服上报 | 
SyncOpD.gs
响应通知服务器的同步操作通知的功能模块
| 函数原型 | 函数作用 | 
|---|---|
| void invoke(string op, ...) | 执行一个同步操作 | 
SystemD.gs
系统功能模块
处理系统启动、关闭
| 函数原型 | 函数作用 | 
|---|---|
| bool is_shut() | 判断系统是否处于关闭状态 | 
| bool is_booting() | 判断系统是否处于启动中状态 | 
| bool is_shutting() | 判断系统是否处于关机中状态 | 
| bool is_running() | 判断系统是否处于正常运行状态 | 
| void boot(function func) | 执行系统启动 | 
| void on_post_boot(function func) | 执行系统启动后处理 | 
| void shutdown(function func = nil) | 执行系统关机 | 
| void on_post_shutdown(function func) | 执行系统关闭后处理 | 
UserD.gs
用户对象管理模块
| 函数原型 | 函数作用 | 
|---|---|
| void add_user(object u) | 添加用户 | 
| void remove_user(object u) | 移除用户 | 
| void walk_all_users(function func) | 遍历所有用户对象 | 
| void walk_server_users(string server_id, function func) | 遍历指定服务器的所有用户对象 | 
| void walk_name_users(mixed name_or_names, function func) | 遍历指定名字的所有用户对象 | 
| void walk_server_name_users(string server_id, mixed name_or_names, function func) | 遍历指定服务器和名字的所有用户对象 | 
| void debug_on(bool on = true) | 调试接口 - 打开/关闭调试 | 
| void dump() | 调试接口 - 输出所有用户对象 | 
UserEventD.gs
玩家事件模块
| 函数原型 | 函数作用 | 
|---|---|
| void listen_event(string user_event, function func) | 监听玩家事件 | 
account_op.gs
账号操作功能模块
账号数据分成两部分,一部分是基础资料(静态数据),轻易不更新
另一部分是账号动态资料(动态数据,也需要序列化),可能经常更新
这样做的目的是基础资料的缓存不必频繁更新
arg_protocol.gs
客户端命令接口参数协议模块
只有在配置表中配置了参数协议时起效
| 函数原型 | 函数作用 | 
|---|---|
| mixed get_cmd_arg_protocol_config(string cmd) | 获取指令的参数协议配置 | 
| void set_cmd_arg_protocol(string cmd, CmdArgProtocol protocol) | 设置指令的参数协议 | 
| mixed get_cmd_arg_protocol(string cmd) | 获取网络指令的参数协议 | 
| bool match_cmd_arg_protocol(string cmd, ...) | 检查网络指令的参数是否匹配 | 
| CmdArgProtocol new_cmd_arg_protocol(mixed value) | 创建一个CmdArgProtocol实例 | 
| void dump(string cmd = nil) | 调试接口 - 输出指令的参数协议 | 
auth_op.gs
验证操作的功能模块
| 函数原型 | 函数作用 | 
|---|---|
| bool set_auth_agent(object conn, string name, map info) | 设置服务器对应的账号验证代理 | 
| map find_auth_agent(object conn, string name) | 获取指定服务器名称对应的账号验证代理 | 
| object assure_auth_agent_cache(string name, object conn) | 获取服务器对应的账号验证代理缓存对象 | 
caches.gs
对象缓存池
为了减少数据库访问频率,将一些经常访问的数据缓存起来
本模块是这些缓存对象的管理器,提供对象的创建和销毁接口
| 函数原型 | 函数作用 | 
|---|---|
| object get_cache(string type, string key) | 获取缓存对象 | 
| object create_cache(string type, string key, ...) | 创建缓存对象 | 
| void close_cache(string type, string key) | 关闭缓存对象 | 
| void close_caches_by_type(string type) | 关闭指定类型的所有缓存对象 | 
| void close_all_caches() | 关闭所有缓存对象 | 
| void dump() | 调试接口 - 输出所有的缓存对象调试信息 | 
chatroom.gs
聊天室相关操作
chat_op.gs
聊天操作功能模块
config.gs
社交服配置模块
社交服的配置可以通过启动参数中添加/D CONFIG 来指定配置文件;如果未指定配置文件,则默认使用/etc/config.json
| 函数原型 | 函数作用 | 
|---|---|
| void init(string config_file) | 读取配置文件初始化 | 
| mixed get(string path) | 获取配置值 | 
| string system_id() | 获取系统id | 
| string ip() | 获取本机ip | 
| int port() | 获取本机端口 | 
friend_op.gs
好友操作功能模块
InternalClient.gs
社交服之间的内部连接会话对象
| 函数原型 | 函数作用 | 
|---|---|
| bool ping() | 测试连接状态 | 
internal_client.gs
提供社交服之间的内部连接的功能模块
| 函数原型 | 函数作用 | 
|---|---|
| object create_client(map para) | 创建一个内部客户端会话对象 | 
mailbox.gs
邮箱相关操作
mail_op.gs
邮件操作功能模块
moment_op.gs
提供朋友圈操作的功能模块
mongo.gs
提供mongo数据库操作功能模块
注意,本对象包含了pkg.mongo_scripts
| 函数原型 | 函数作用 | 
|---|---|
| void start() | 启动mongo数据库服务 | 
| object find_client(string name, string server_id = nil) | 根据数据库名称和服务器id找到mongo客户端连接对象 | 
| array get_mongo_dbs_by_name(string name) | 通过数据库名称获取所有相关的数据库名称列表 | 
| bool contains_db(string name, string server_id) | 判断指定数据库名称和服务器id对应的数据库配置是否存在 | 
netd.gs
社交服的网络功能模块
| 函数原型 | 函数作用 | 
|---|---|
| void start_server(string name, int port, map para = , bool using_websocket = false) | 启动网络服务 | 
| void stop_server(string name) | 停止网络服务 | 
| void dump() | 调试接口 - 输出消息处理器统计信息 | 
| void add_into_scan_list(object ob) | 加入会话防呆扫描队列 | 
Session.gs
会话对象
| 函数原型 | 函数作用 | 
|---|---|
| bool is_session() | 是不是一个会话对象 | 
| void set_running_cmd(bool running_cmd = true) | 设置本会话对象是否正在执行指令标记 | 
| bool is_running_cmd() | 是不是正在执行指令 | 
| void set_port_recv_size(int recv_size) | 设置会话所属连接的接收缓冲区大小 | 
| bool auto_close() | 尝试自动关闭(满足pkg.session_scanner管理提供的接口) | 
| void close_in_seconds(int seconds) | 指定时长时间后自动关闭 | 
| object unbind_connection() | 解除绑定当前网络连接对象 | 
| void bind_connection(object conn) | 绑定网络连接对象 | 
| bool transfer_connection(object to) | 将当前网络连接对象传递给目标会话对象 | 
| bool is_connected() | 判断当前网络连接对象是否已连接 | 
| void send(string cmd, ...) | 发送网络消息 | 
| void send_ping() | 发送ping消息 | 
| string desc() | 获取描述信息 | 
| void dump() | 调试接口 - 输出当前会话统计信息 | 
sword.gs
社交服敏感词功能模块
解释一下,sword是sensitive word的缩写
内置了4种敏感词功能模块,分别对应pkg.leiting.sword/pkg.lt_sword/pkg.sword_client/pkg.ssword
| 函数原型 | 函数作用 | 
|---|---|
| void startup(string name, mixed m) | 启动指定名称的敏感词功能模块 | 
| bool is_manual_patrol_enabled() | 手动巡服上报是否激活 | 
| array filter_content(map msg) | 敏感词过滤 | 
InternalUser.gs
内部用户对象
| 函数原型 | 函数作用 | 
|---|---|
| string get_id() | 获取内部用户ID(一般是社交服系统ID) | 
| void post_auth_success() | 执行内部验证成功以后的处理 | 
User.gs
已验证的用户对象
| 函数原型 | 函数作用 | 
|---|---|
| bool is_user() | 声明我是一个User对象 | 
| string Session.desc() | 获取描述信息 | 
| int get_privilege() | 获取权限值 | 
| string get_server_id() | 获取所属游戏服务器id | 
| string get_name() | 获取名字(社交服账号) | 
| int get_register_time() | 获取注册时间 | 
| string get_channel() | 获取所属渠道 | 
| bool Session.auto_close() | 尝试自动关闭 | 
| mixed get_account_profile_field(string field) | 获取用户账号动态资料的字段值 | 
| bool set_account_profile_field(string field, mixed value) | 设置账号动态资料的字段值 | 
| bool set_account_profile_field_dict(map field_dict) | 设置账号动态资料的一组字段值 | 
| map get_entire_account_profile() | 获取账号动态资料的完整数据 | 
| map get_location() | 获取用户的定位信息 | 
| void send_notify(map args) | 发送社交服通知消息(cmd_social_notify) | 
| void receive_notify(map args) | 处理社交服通知消息 | 
| bool check_and_record_cmd_frequency(string cmd) | 检查并记录指令执行频率 | 
| bool is_out_of_life() | 判断是否超出 了生存周期 | 
| void post_auth_success() | 执行验证成功以后的处理 | 
preimport.gs
预定义文件
| 函数原型 | 函数作用 | 
|---|---|
| void set_embedded_mode(bool flag_embedded) | 设置嵌入模式 | 
| bool is_embedded_mode() | 是不是嵌入模式 | 
social_server.gs
| 函数原型 | 函数作用 | 
|---|---|
| void setup(string config_file) | 嵌入模式下启动社交服 | 
枚举
Privileges
用户权限
| 枚举成员 | 值 | 描述 | 
|---|---|---|
| Normal | 3 | |
| Admin | 7 | |
| Root | 15 | 
类
SessionProperties
会话属性
成员变量
| 变量名 | 类型 | 初始值 | 须初始化 | 描述 | 
|---|---|---|---|---|
| count | int | 0 | 可选 | 已处理消息数量 | 
| total_cost | float | 0 | 可选 | 已花费处理消息总耗时 | 
| min_cost | float | 0 | 可选 | 已处理消息的最小耗时 | 
| max_cost | float | 0 | 可选 | 已处理消息的最大耗时 | 
| running_cmd | bool | false | 可选 | 当前是不是在执行指令 | 
| anonymous_session | bool | false | 可选 | 是否为匿名会话 | 
| auto_close_time | int | 0 | 可选 | 自动关闭时间 | 
成员方法
| 函数原型 | 函数作用 | 
|---|