forked from powerfun/udpservice
feat:客户端断开时更新房间状态
This commit is contained in:
parent
b6ea5934c5
commit
21e4490934
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="Host" value="http://pf.juze.pro/"/>
|
<add key="Host" value="https://wx.powerfun.com.cn/"/>
|
||||||
<add key="Top" value="0"/>
|
<add key="Top" value="0"/>
|
||||||
<add key="ShowVirtualUser" value="true"/>
|
<add key="ShowVirtualUser" value="true"/>
|
||||||
<add key="Port" value="21000"/>
|
<add key="Port" value="11000"/>
|
||||||
<add key="TcpPort" value="21001"/>
|
<add key="TcpPort" value="11001"/>
|
||||||
<!-- DEV -->
|
<!-- DEV -->
|
||||||
<add key="DevHost" value="http://pf.juze.pro/"/>
|
<add key="DevHost" value="http://pf.juze.pro/"/>
|
||||||
<add key="DevTop" value="0"/>
|
<add key="DevTop" value="0"/>
|
||||||
|
|||||||
@ -282,6 +282,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
case 4: BroadCastGameRoomList(); break;
|
case 4: BroadCastGameRoomList(); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendGameRoomMessage(RoomModel gameRoom)
|
private void SendGameRoomMessage(RoomModel gameRoom)
|
||||||
{
|
{
|
||||||
if (gameRoom == null)
|
if (gameRoom == null)
|
||||||
@ -311,6 +312,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
client.Request = "";
|
client.Request = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BroadCastGameRoomList()
|
private void BroadCastGameRoomList()
|
||||||
{
|
{
|
||||||
//广播
|
//广播
|
||||||
@ -332,6 +334,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
item.Service.Send(ddd.GetBytes(isZip), ddd.GetBytes(isZip).Length, item.IPEndPoint);
|
item.Service.Send(ddd.GetBytes(isZip), ddd.GetBytes(isZip).Length, item.IPEndPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//查询房间列表
|
//查询房间列表
|
||||||
private void HandleQueryGameRoomList(ReceiveModel msg)
|
private void HandleQueryGameRoomList(ReceiveModel msg)
|
||||||
{
|
{
|
||||||
@ -383,6 +386,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
bool isZip = needSend.Encoding == "gzip";
|
bool isZip = needSend.Encoding == "gzip";
|
||||||
needSend.Service.Send(ddd.GetBytes(isZip), ddd.GetBytes(isZip).Length, needSend.IPEndPoint);
|
needSend.Service.Send(ddd.GetBytes(isZip), ddd.GetBytes(isZip).Length, needSend.IPEndPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建房间
|
//创建房间
|
||||||
private void HandleCreateGameRoom(ReceiveModel msg)
|
private void HandleCreateGameRoom(ReceiveModel msg)
|
||||||
{
|
{
|
||||||
@ -430,6 +434,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
RoomList.Add(room);
|
RoomList.Add(room);
|
||||||
RoomMaxId = room.RoomId;
|
RoomMaxId = room.RoomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
//先移除当前用户在其他房间的信息(考虑服务器重启的时候没有响应客户端退出命令)
|
//先移除当前用户在其他房间的信息(考虑服务器重启的时候没有响应客户端退出命令)
|
||||||
private void RemoveOtherRoomInfo(int userId, int roomId)
|
private void RemoveOtherRoomInfo(int userId, int roomId)
|
||||||
{
|
{
|
||||||
@ -446,6 +451,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
SendGameRoomMessage(preRoom);
|
SendGameRoomMessage(preRoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理当前用户加入房间
|
//处理当前用户加入房间
|
||||||
private void HandleJoinGameRoom(ReceiveModel msg)
|
private void HandleJoinGameRoom(ReceiveModel msg)
|
||||||
{
|
{
|
||||||
@ -485,6 +491,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
//发送当前房间的信息给当前房间内的人
|
//发送当前房间的信息给当前房间内的人
|
||||||
SendGameRoomMessage(room);
|
SendGameRoomMessage(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理当前用户准备状态
|
//处理当前用户准备状态
|
||||||
private void HandleGameRoomReadyStatus(ReceiveModel msg)
|
private void HandleGameRoomReadyStatus(ReceiveModel msg)
|
||||||
{
|
{
|
||||||
@ -502,6 +509,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
//发送信息给当前房间内的人
|
//发送信息给当前房间内的人
|
||||||
SendGameRoomMessage(room);
|
SendGameRoomMessage(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理当前用户准备状态
|
//处理当前用户准备状态
|
||||||
private void HandleGameRoomStart(ReceiveModel msg)
|
private void HandleGameRoomStart(ReceiveModel msg)
|
||||||
{
|
{
|
||||||
@ -520,6 +528,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
//发送信息给当前房间内的人
|
//发送信息给当前房间内的人
|
||||||
SendGameRoomMessage(room);
|
SendGameRoomMessage(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理房间踢人的操作
|
//处理房间踢人的操作
|
||||||
private void HandleGameRoomKick(ReceiveModel msg)
|
private void HandleGameRoomKick(ReceiveModel msg)
|
||||||
{
|
{
|
||||||
@ -651,7 +660,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
{
|
{
|
||||||
if (item.Expire)
|
if (item.Expire)
|
||||||
{
|
{
|
||||||
Clients.Remove(item);
|
RemoveClient(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -700,7 +709,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
var info = Clients.FirstOrDefault(n => n.MemberId == msgs[i].MemberId);
|
var info = Clients.FirstOrDefault(n => n.MemberId == msgs[i].MemberId);
|
||||||
if (info != null)
|
if (info != null)
|
||||||
{
|
{
|
||||||
Clients.Remove(info);
|
RemoveClient(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -711,7 +720,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
{
|
{
|
||||||
if (item.Expire)
|
if (item.Expire)
|
||||||
{
|
{
|
||||||
Clients.Remove(item);
|
RemoveClient(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -900,7 +909,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
var client = Clients.FirstOrDefault(f => f.IPEndPoint.ToString() == point.ToString());
|
var client = Clients.FirstOrDefault(f => f.IPEndPoint.ToString() == point.ToString());
|
||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
Clients.Remove(client);
|
RemoveClient(client);
|
||||||
GameRoomDisConnectHandler(client);
|
GameRoomDisConnectHandler(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -910,6 +919,44 @@ namespace OnlineUserPool.ViewModels
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RemoveClient(HostModel client)
|
||||||
|
{
|
||||||
|
BeforeRemoved(client);
|
||||||
|
Clients.Remove(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BeforeRemoved(HostModel client)
|
||||||
|
{
|
||||||
|
if(client.RoomId == 0)return;
|
||||||
|
var room = RoomList.ToList().FirstOrDefault(c => c.RoomId == client.RoomId);
|
||||||
|
if(room == null)return;
|
||||||
|
|
||||||
|
var needRemove = room.List.FirstOrDefault(c => c.UserId == client.MemberId);
|
||||||
|
if(needRemove == null)return;
|
||||||
|
|
||||||
|
//从房间中移除,并考虑是否需要删除房间和移交房主
|
||||||
|
room.List.Remove(needRemove);
|
||||||
|
if (room.List.Count == 0)
|
||||||
|
{
|
||||||
|
RoomList.Remove(room);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var host = room.List.FirstOrDefault();
|
||||||
|
if (host != null)
|
||||||
|
{
|
||||||
|
host.IsOwner = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新房间状态
|
||||||
|
var isComplete = room.List.All(c => c.Saved != false);
|
||||||
|
if (room.Status > 0)
|
||||||
|
{
|
||||||
|
room.Status = isComplete ? 2 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Data1
|
public class Data1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user