加入房间,踢人,准备等tcp命令
This commit is contained in:
1 parent
de8dd933e8
commit
06582201fa
101 files changed
+246552
-565
No files matched your search
@@ -8,11 +8,43 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
public class VideoMapModel {
|
||||
public double x { get; set; }
|
||||
public double y { get; set; }
|
||||
public double speed { get; set; }
|
||||
public int position { get; set; }
|
||||
public class RoomDetailModel
|
||||
{
|
||||
public int RoomId { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public DateTime JoinAt { get; set; }
|
||||
public int Status { get; set; }
|
||||
public double Process { get; set; }
|
||||
public bool IsOwner { get; set; }
|
||||
|
||||
public static RoomDetailModel Parse(string msg)
|
||||
{
|
||||
var detail = new RoomDetailModel();
|
||||
try
|
||||
{
|
||||
var arr = msg.Split(',');
|
||||
detail.RoomId = Convert.ToInt32(arr[0], CultureInfo.InvariantCulture);
|
||||
detail.UserId = Convert.ToInt32(arr[1], CultureInfo.InvariantCulture);
|
||||
detail.JoinAt = Convert.ToDateTime(arr[2], CultureInfo.InvariantCulture);
|
||||
detail.Status = Convert.ToInt32(arr[3], CultureInfo.InvariantCulture);
|
||||
detail.Process = Convert.ToDouble(arr[4], CultureInfo.InvariantCulture);
|
||||
detail.IsOwner = Convert.ToBoolean(arr[5], CultureInfo.InvariantCulture);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
public class JoinGameRoomCommand
|
||||
{
|
||||
public byte CommandType { get; set; }
|
||||
public byte SubType { get; set; }
|
||||
public int V { get; set; }
|
||||
public int RoomId { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public DateTime JoinAt { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 排名
|
||||
@@ -378,6 +410,8 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
//public int V { get; set; }
|
||||
|
||||
public int FrameRate { get; set; }
|
||||
public int RoomId { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
}
|
||||
|
||||
public class GzipMsgModel
|
||||
@@ -439,17 +473,25 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
public string WatchIdList { get; set; }
|
||||
|
||||
public int? FrameRate { get; set; }
|
||||
public int? RoomId { get; set; }
|
||||
public RoomDetailModel RoomDetail { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
|
||||
public static ReceiveMsgModel Parse(string str)
|
||||
{
|
||||
var list = str.Split(',');
|
||||
if (list.Length != 15)
|
||||
if (list.Length < 14)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DateTime ? startTime = null;// string.IsNullOrEmpty(list[16]) ? null : Convert.ToDateTime(list[16], CultureInfo.InvariantCulture);
|
||||
if (!string.IsNullOrEmpty(list[16]))
|
||||
{
|
||||
startTime = Convert.ToDateTime(list[16], CultureInfo.InvariantCulture);
|
||||
}
|
||||
return new ReceiveMsgModel
|
||||
{
|
||||
RouteId = Convert.ToInt32(list[0],CultureInfo.InvariantCulture),
|
||||
@@ -468,9 +510,11 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
Cadence = Convert.ToDouble(list[12], CultureInfo.InvariantCulture),
|
||||
TotoalTicks = Convert.ToInt32(list[13], CultureInfo.InvariantCulture),
|
||||
FrameRate = Convert.ToInt32(list[14], CultureInfo.InvariantCulture),
|
||||
//RoomId = Convert.ToInt32(list[15], CultureInfo.InvariantCulture),
|
||||
//StartTime = startTime,
|
||||
};
|
||||
}
|
||||
catch
|
||||
catch(Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -601,6 +645,8 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
public int? FrameRate { get; set; }
|
||||
|
||||
public RoomDetailModel RoomDetail { get; set; }
|
||||
}
|
||||
|
||||
public class KeyPaire
|
||||
|
||||
@@ -110,36 +110,108 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] Compress(string text)
|
||||
|
||||
//获取房间人物列表
|
||||
private static void SendGameRoomListPlayers(int[] roomIds)
|
||||
{
|
||||
var bytes = Encoding.Unicode.GetBytes(text);
|
||||
using (var mso = new MemoryStream())
|
||||
var model = new
|
||||
{
|
||||
using (var gs = new GZipStream(mso, CompressionMode.Compress))
|
||||
{
|
||||
gs.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
return mso.ToArray();
|
||||
}
|
||||
CommandType = 3,
|
||||
SubType = 0,
|
||||
V = 2,
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
}
|
||||
//加入对战房间
|
||||
public static void SendJoinGameRoom(int roomId, int userId,DateTime startTime)
|
||||
{
|
||||
var model = new
|
||||
{
|
||||
CommandType = 3,
|
||||
SubType = 1,
|
||||
UserId = userId,
|
||||
RoomId = roomId,
|
||||
JoinAt = startTime,
|
||||
V = 2,
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
}
|
||||
//发送准备状态
|
||||
public static void SendGameRoomReadyStatus(int roomId, int userId,int status)
|
||||
{
|
||||
var model = new
|
||||
{
|
||||
CommandType = 3,
|
||||
SubType = 2,
|
||||
UserId = userId,
|
||||
RoomId = roomId,
|
||||
Status = status,
|
||||
V = 2,
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
}
|
||||
//发送对战开始时间
|
||||
public static void SendGameRoomStartTime(int roomId,DateTime startTime)
|
||||
{
|
||||
var model = new
|
||||
{
|
||||
CommandType = 3,
|
||||
SubType = 3,
|
||||
RoomId = roomId,
|
||||
StartTime = startTime,
|
||||
V = 2,
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
}
|
||||
//踢人
|
||||
public static void SendGameRoomKick(int roomId,int userId,int onwerId)
|
||||
{
|
||||
var model = new
|
||||
{
|
||||
CommandType = 3,
|
||||
SubType = 4,
|
||||
RoomId = roomId,
|
||||
UserId = userId,
|
||||
OnwerId = onwerId,
|
||||
V = 2,
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
}
|
||||
|
||||
public static string Decompress(byte[] data)
|
||||
//发送当前loading进度
|
||||
private static void SendGameRoomLoadingProcess(int roomId, int userId,int process)
|
||||
{
|
||||
// Read the last 4 bytes to get the length
|
||||
byte[] lengthBuffer = new byte[4];
|
||||
Array.Copy(data, data.Length - 4, lengthBuffer, 0, 4);
|
||||
int uncompressedSize = BitConverter.ToInt32(lengthBuffer, 0);
|
||||
|
||||
var buffer = new byte[uncompressedSize];
|
||||
using (var ms = new MemoryStream(data))
|
||||
var model = new
|
||||
{
|
||||
using (var gzip = new GZipStream(ms, CompressionMode.Decompress))
|
||||
{
|
||||
gzip.Read(buffer, 0, uncompressedSize);
|
||||
}
|
||||
}
|
||||
return Encoding.Unicode.GetString(buffer);
|
||||
CommandType = 3,
|
||||
SubType = 5,
|
||||
V = 2,
|
||||
RoomId = roomId,
|
||||
UserId = userId,
|
||||
Process = process,
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
}
|
||||
|
||||
private static void SendGameRoomBaseMsg(int roomId, int userId,int process)
|
||||
{
|
||||
var model = new
|
||||
{
|
||||
CommandType = 3,
|
||||
V = 2,
|
||||
RoomId = roomId,
|
||||
UserId = userId,
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送心跳包
|
||||
/// </summary>
|
||||
@@ -207,7 +279,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
/// <param name="exit">是否退出</param>
|
||||
public static void Send(int RouteId, int MemberId, double[] Point, bool IsCompleted = false, bool exit = false,
|
||||
double endDistance = 0, bool showVirtual = false, byte commandType = 1, double speed = 0, bool isVirtual = false, double preDistance = 0,
|
||||
double weightKg = 0, int competitionId = 0, bool saved = false,double? heartRate = 0, double power = 0, double? cadence = 0,int totalTicks = 0, int frameRate = 0)
|
||||
double weightKg = 0, int competitionId = 0, bool saved = false,double? heartRate = 0, double power = 0, double? cadence = 0,int totalTicks = 0, int frameRate = 0, int roomId = 0,DateTime? startTime = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -235,7 +307,9 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
WeightKg = weightKg,
|
||||
Competitionid = competitionId,
|
||||
Saved = saved,
|
||||
FrameRate = frameRate
|
||||
FrameRate = frameRate,
|
||||
RoomId = roomId,//房间Id
|
||||
StartTime = startTime
|
||||
//V = 1
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
@@ -282,7 +356,18 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
}
|
||||
|
||||
public static List<OnlineUser> GetGameRoomList(int roomId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return onlineUserHelper.OnlineUsers.Where(c => c.RoomDetail != null && c.RoomDetail.RoomId == roomId).OrderBy(c=>c.Id).ToList();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static OnlineUser GetOnlineUserLastDataById(int userId)
|
||||
{
|
||||
@@ -493,6 +578,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
user.IsWatcher = user.WatcherList.Contains(item.MemberId);
|
||||
user.CreateTime = DateTime.MaxValue;
|
||||
user.FrameRate = item.FrameRate;
|
||||
user.RoomDetail = item.RoomDetail;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -196,6 +196,21 @@ namespace Assets.Scenes.Ride.Scripts.Network
|
||||
o.WatchIdList = w;
|
||||
}
|
||||
}
|
||||
//
|
||||
if (t.IndexOf('g') == 0)
|
||||
{
|
||||
var g = t.Replace("g{", "").Replace("}", "");
|
||||
var glist = g.Split('|');
|
||||
foreach (var i in glist)
|
||||
{
|
||||
var gameRoom = RoomDetailModel.Parse(i);
|
||||
var owner = list.Where(c => c.MemberId == gameRoom.UserId).FirstOrDefault();
|
||||
if (owner != null)
|
||||
{
|
||||
owner.RoomDetail = gameRoom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_action(list);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user