当前位置:网站首页>Summary of cases of players' disconnection and reconnection in Huawei online battle service
Summary of cases of players' disconnection and reconnection in Huawei online battle service
2022-07-02 11:01:00 【Huawei Developer Forum】
Huawei online battle service disconnection and reconnection solution
During the game , Abnormal situations such as network fluctuations often occur , Cause players to drop the line , At this time, if the network is restored, you still want players to join the original game , You can reconnect in the following ways . The allowed reconnection time can be AppGallery Connec The console .
Network exceptions lead to offline scenarios
Network anomalies cause the player client to be disconnected from the online battle server , After a certain period, the server will set the player to be offline , If the game allows players to reconnect to the network after the network is restored in a short time, you need to use the drop and reconnect interface to realize this scenario .
Specifically, after the player enters the room , The game passes room.onDisconnect(playerInfo) Method to monitor player dropping events , This method will return player information . Judge if the player drops the line , You need to trigger room.reconnect() Method reconnection , In the process of reconnection, if the network has not been restored, try to reconnect all the time , If the network is restored, deal with it according to the results , You may jump to other game pages if you exceed the allowed reconnection time .
room.onDisconnect((playerInfo) => {
// The current player is disconnected
if(playerInfo.playerId === room.playerId){
// Reconnection logic
reConnect();
}else{
// Other players drop the line
}
}
reConnect() {
// Call the reconnect method to reconnect
room.reconnect().then(() => {
// Reconnection success
}).catch((e) => {
if (!e.code) {
// Network failure, continue to retry
this.reConnect();
return;
}
if (e.code != 0) {
// Exit to other pages after the allowed reconnection time
}
});
}
Closing the client leads to a drop
Players still want to reconnect to the previous game after closing and reopening the client , At this time, you can judge whether the player is still in a valid room in the return of the initialization interface , If it is still in, it means that it is still within the allowable reconnection time , You can use the join room interface to re join . If you don't want to join the last game at this time , You must call the interface to leave the room before you can re create the room .
client.init().then(() => {
// Successful initialization
if(client.lastRoomId){
// The current player is still in the previous room , According to the lastRoomId Rejoin the room
// If you don't want to join the previous room , Must pass client.leaveRoom Leave the room , Otherwise, an error will be reported when creating a new room or matching a room : The player is already in the room
}
}).catch(() => {
// initialization failed
});
边栏推荐
- PCL point cloud to depth image
- 学习open62541 --- [66] UA_String的生成方法
- AppGallery Connect场景化开发实战—图片存储分享
- P1055 [noip2008 popularization group] ISBN number
- 2022-06-17
- 【深入浅出玩转FPGA学习5-----复位设计】
- JSP webshell免殺——JSP的基礎
- [SUCTF2018]followme
- 二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
- (5) Gear control setting of APA scene construction
猜你喜欢

Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application

Read H264 parameters from mediarecord recording

实验电镜距离测量之Matlab处理

二叉树专题--AcWing 1589. 构建二叉搜索树

Leetcode+ 76 - 80 storm search topic

Mysql database remote access permission settings

(五)APA场景搭建之挡位控制设置

LeetCode+ 76 - 80 暴搜专题

《实习报告》Skywalking分布式链路追踪?

Introduction to MySQL 8 DBA foundation tutorial
随机推荐
VSCode工具使用
计算序列之和
【深入浅出玩转FPGA学习5-----复位设计】
Is the account above changtou school safe?
OpenMLDB Meetup No.4 会议纪要
快应用中实现自定义抽屉组件
Luogu p5536 [xr-3] core city (greed + tree DP looking for the center of the tree)
PCL之滤波
(5) Gear control setting of APA scene construction
UVM - configuration mechanism
Hdu1236 ranking (structure Sorting)
最详细MySql安装教程
JSP webshell免殺——JSP的基礎
【AGC】构建服务3-认证服务示例
Uncover the secrets of Huawei application market application statistics
Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)
UVM learning - object attribute of UVM phase
【深入浅出玩转FPGA学习3-----基本语法】
Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)
HDU1234 开门人和关门人(水题)