forked from powerfun/udpservice
对战房间
This commit is contained in:
parent
bc0499b9f4
commit
b51bac2abe
14
App.config
14
App.config
@ -1,10 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="Host" value="https://wx.powerfun.com.cn/"/>
|
<add key="Host" value="http://pf.juze.pro/"/>
|
||||||
<add key="Top" value="0"/>
|
<add key="Top" value="0"/>
|
||||||
<add key="ShowVirtualUser" value="false"/>
|
<add key="ShowVirtualUser" value="true"/>
|
||||||
<add key="Port" value="11000"/>
|
<add key="Port" value="21000"/>
|
||||||
<add key="TcpPort" value="11001"/>
|
<add key="TcpPort" value="21001"/>
|
||||||
|
<!-- DEV -->
|
||||||
|
<add key="DevHost" value="http://pf.juze.pro/"/>
|
||||||
|
<add key="DevTop" value="0"/>
|
||||||
|
<add key="DevShowVirtualUser" value="false"/>
|
||||||
|
<add key="DevPort" value="21000"/>
|
||||||
|
<add key="DevTcpPort" value="21001"/>
|
||||||
</appSettings>
|
</appSettings>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -10,7 +10,10 @@ namespace OnlineUserPool.Model
|
|||||||
public int RoomId { get; set; }
|
public int RoomId { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int UserId { get; set; }//房主
|
public int UserId { get; set; }//房主
|
||||||
public int Status { get; set; }//房间状态 0 :准备状态 1:开始loading 2:结束
|
/// <summary>
|
||||||
|
/// 房间状态 0 :准备状态 1:开始loading 2:结束
|
||||||
|
/// </summary>
|
||||||
|
public int Status { get; set; }
|
||||||
public DateTime StatusChangedTime { get; set; }
|
public DateTime StatusChangedTime { get; set; }
|
||||||
public DateTime CreateTime { get; set; }//创建时间
|
public DateTime CreateTime { get; set; }//创建时间
|
||||||
public DateTime? StartTime { get; set; }//开始时间
|
public DateTime? StartTime { get; set; }//开始时间
|
||||||
|
|||||||
@ -34,6 +34,15 @@ namespace OnlineUserPool.Unility
|
|||||||
UdpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);
|
UdpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);
|
||||||
|
|
||||||
TcpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["TcpPort"]);
|
TcpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["TcpPort"]);
|
||||||
|
#if DEBUG
|
||||||
|
Host = System.Configuration.ConfigurationManager.AppSettings["DevHost"];
|
||||||
|
//Top = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Top"]);
|
||||||
|
ShowVirtualUser = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["DevShowVirtualUser"]);
|
||||||
|
//Ip = System.Configuration.ConfigurationManager.AppSettings["Ip"];
|
||||||
|
UdpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["DevPort"]);
|
||||||
|
|
||||||
|
TcpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["DevTcpPort"]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -387,15 +387,19 @@ namespace OnlineUserPool.ViewModels
|
|||||||
private void HandleCreateGameRoom(ReceiveModel msg)
|
private void HandleCreateGameRoom(ReceiveModel msg)
|
||||||
{
|
{
|
||||||
var createMsg = msg as CreateGameRoomCommand;
|
var createMsg = msg as CreateGameRoomCommand;
|
||||||
RemoveOtherRoomInfo(createMsg.UserId);
|
|
||||||
|
RemoveOtherRoomInfo(createMsg.UserId, createMsg.Id);
|
||||||
|
|
||||||
|
var roomId = RoomMaxId + 1;
|
||||||
var list = new List<RoomDetailModel>();
|
var list = new List<RoomDetailModel>();
|
||||||
list.Add(new RoomDetailModel()
|
list.Add(new RoomDetailModel()
|
||||||
{
|
{
|
||||||
|
RoomId = roomId,
|
||||||
UserId = createMsg.UserId,
|
UserId = createMsg.UserId,
|
||||||
JoinAt = DateTime.Now.ToUniversalTime(),
|
JoinAt = DateTime.Now.ToUniversalTime(),
|
||||||
IsOwner = true,
|
IsOwner = true,
|
||||||
});
|
});
|
||||||
var roomId = RoomMaxId + 1;
|
|
||||||
var room = new RoomModel
|
var room = new RoomModel
|
||||||
{
|
{
|
||||||
RoomId = roomId,
|
RoomId = roomId,
|
||||||
@ -427,9 +431,9 @@ namespace OnlineUserPool.ViewModels
|
|||||||
RoomMaxId = room.RoomId;
|
RoomMaxId = room.RoomId;
|
||||||
}
|
}
|
||||||
//先移除当前用户在其他房间的信息(考虑服务器重启的时候没有响应客户端退出命令)
|
//先移除当前用户在其他房间的信息(考虑服务器重启的时候没有响应客户端退出命令)
|
||||||
private void RemoveOtherRoomInfo(int userId)
|
private void RemoveOtherRoomInfo(int userId, int roomId)
|
||||||
{
|
{
|
||||||
var preRoom = RoomList.ToList().Where(c => c.Status == 0 && c.List.Where(c => c.UserId == userId).Any()).FirstOrDefault();
|
var preRoom = RoomList.ToList().Where(c => c.Status == 0 && c.List.Where(c => c.UserId == userId).Any() && c.RoomId != roomId).FirstOrDefault();
|
||||||
if (preRoom != null)
|
if (preRoom != null)
|
||||||
{
|
{
|
||||||
var needRemove = preRoom.List.Where(c => c.UserId == userId).FirstOrDefault();
|
var needRemove = preRoom.List.Where(c => c.UserId == userId).FirstOrDefault();
|
||||||
@ -446,7 +450,7 @@ namespace OnlineUserPool.ViewModels
|
|||||||
private void HandleJoinGameRoom(ReceiveModel msg)
|
private void HandleJoinGameRoom(ReceiveModel msg)
|
||||||
{
|
{
|
||||||
var msg1 = msg as JoinGameRoomCommand;
|
var msg1 = msg as JoinGameRoomCommand;
|
||||||
RemoveOtherRoomInfo(msg1.UserId);
|
RemoveOtherRoomInfo(msg1.UserId,msg1.RoomId);
|
||||||
var room = RoomList.ToList().Where(c => c.RoomId == msg1.RoomId).FirstOrDefault();
|
var room = RoomList.ToList().Where(c => c.RoomId == msg1.RoomId).FirstOrDefault();
|
||||||
var client = Clients.FirstOrDefault(n => n.MemberId.Equals(msg1.UserId));
|
var client = Clients.FirstOrDefault(n => n.MemberId.Equals(msg1.UserId));
|
||||||
//更新房间信息
|
//更新房间信息
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user