1
This commit is contained in:
parent
ee123745b1
commit
60cb29e75a
38
Managers/Battle.cs
Normal file
38
Managers/Battle.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Google.Protobuf;
|
||||||
|
|
||||||
|
class Battle
|
||||||
|
{
|
||||||
|
private JoinInfo joinInfo;
|
||||||
|
private Net.ClientNet conn;
|
||||||
|
|
||||||
|
public Battle(JoinInfo joinInfo)
|
||||||
|
{
|
||||||
|
this.conn = new Net.ClientNet("ws://192.168.100.21:7601/websocket?server_id=2");
|
||||||
|
this.conn.OnOpen += (Net.ClientNet conn) =>
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
var joinMsg = new battle.cs.CMJoin();
|
||||||
|
joinMsg.AccountId = joinInfo.account_id;
|
||||||
|
joinMsg.SessionId = joinInfo.session_id;
|
||||||
|
joinMsg.TeamUuid = joinInfo.team_uuid;
|
||||||
|
joinMsg.PayloadData = joinInfo.payload_data;
|
||||||
|
this.conn.SendMsg(joinMsg);
|
||||||
|
};
|
||||||
|
this.conn.Open();
|
||||||
|
{
|
||||||
|
var joinMsg = new battle.cs.CMJoin();
|
||||||
|
joinMsg.AccountId = joinInfo.account_id;
|
||||||
|
joinMsg.SessionId = joinInfo.session_id;
|
||||||
|
joinMsg.TeamUuid = joinInfo.team_uuid;
|
||||||
|
joinMsg.PayloadData = joinInfo.payload_data;
|
||||||
|
this.conn.SendMsg(joinMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -40,6 +40,9 @@ public class BattleMgr
|
|||||||
TransformExtension.localEulerAngles(terrainObj.transform, 0, 0, 0);
|
TransformExtension.localEulerAngles(terrainObj.transform, 0, 0, 0);
|
||||||
TransformExtension.localPosition(terrainObj.transform, 0, 0, 0);
|
TransformExtension.localPosition(terrainObj.transform, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
var b = new Battle(join_info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,15 +8,19 @@ namespace Mt
|
|||||||
{
|
{
|
||||||
class Table
|
class Table
|
||||||
{
|
{
|
||||||
public static string RES_PATH = @"D:\opensource\pubgv4\branch\config_v4_dev3d_10_9\upload_files\equip@equip.json";
|
private static bool loadEd;
|
||||||
|
public static string RES_PATH = @"D:\opensource\pubgv4\branch\config_v4_dev3d_10_9\upload_files\";
|
||||||
public static EquipTable Equip = new EquipTable(RES_PATH + "equip@equip.json", "id");
|
public static EquipTable Equip = new EquipTable(RES_PATH + "equip@equip.json", "id");
|
||||||
public static MapTable Map = new MapTable(RES_PATH + "map@map.json", "map_id");
|
public static MapTable Map = new MapTable(RES_PATH + "map@map.json", "map_id");
|
||||||
|
|
||||||
public static void Load()
|
public static void Load()
|
||||||
|
{
|
||||||
|
if (!loadEd)
|
||||||
{
|
{
|
||||||
Equip.Load();
|
Equip.Load();
|
||||||
Map.Load();
|
Map.Load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,59 +10,68 @@ using pbr = global::Google.Protobuf.Reflection;
|
|||||||
|
|
||||||
namespace Net
|
namespace Net
|
||||||
{
|
{
|
||||||
|
public delegate void OnNetOpen(ClientNet conn);
|
||||||
|
public delegate void OnNetError(ClientNet conn);
|
||||||
|
public delegate void OnNetClosed(ClientNet conn);
|
||||||
|
|
||||||
public class ClientNet
|
public class ClientNet
|
||||||
{
|
{
|
||||||
|
|
||||||
private string uri;
|
private string uri;
|
||||||
private WebSocket ws;
|
private WebSocket ws;
|
||||||
|
private byte[] recvBuf = new byte[1024 * 64 * 3];
|
||||||
|
private int recvBufLen = 0;
|
||||||
|
public OnNetOpen OnOpen;
|
||||||
|
public OnNetError OnError;
|
||||||
|
public OnNetClosed OnClosed;
|
||||||
|
|
||||||
public ClientNet(string uri)
|
public ClientNet(string uri)
|
||||||
{
|
{
|
||||||
this.ws = new WebSocket(new Uri(uri));
|
this.ws = new WebSocket(new Uri(uri));
|
||||||
this.ws.OnOpen += this.OnOpen;
|
this.ws.OnOpen += this.OnWsOpen;
|
||||||
this.ws.OnBinary += this.OnBinaryReceived;
|
this.ws.OnBinary += this.OnWsBinaryReceived;
|
||||||
this.ws.OnError += this.OnError;
|
this.ws.OnError += this.OnWsError;
|
||||||
this.ws.OnClosed += this.OnClosed;
|
this.ws.OnClosed += this.OnWsClosed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Open()
|
public void Open()
|
||||||
{
|
{
|
||||||
this.ws.Open();
|
this.ws.Open();
|
||||||
battle.cs.CMJoin joinMsg = new battle.cs.CMJoin();
|
}
|
||||||
this.SendMsg(joinMsg);
|
|
||||||
battle.cs.CMMove moveMsg = new battle.cs.CMMove();
|
|
||||||
this.SendMsg(moveMsg);
|
|
||||||
|
|
||||||
|
public int GetCMMsgId(string msgName)
|
||||||
|
{
|
||||||
|
return this.GetPbMsgId(typeof(battle.cs.CMMessageId_e), "_" + msgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetSMMsgId(string msgName)
|
||||||
|
{
|
||||||
|
return this.GetPbMsgId(typeof(battle.cs.SMMessageId_e), "_" + msgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetPbMsgId(Type enumType,string msgName)
|
||||||
|
{
|
||||||
|
foreach (var f in enumType.GetFields())
|
||||||
|
{
|
||||||
|
var tAttrs = f.GetCustomAttributes(typeof(pbr::OriginalNameAttribute), false);
|
||||||
|
if (tAttrs.Length > 0)
|
||||||
|
{
|
||||||
|
var tAttr = (pbr::OriginalNameAttribute)tAttrs[0];
|
||||||
|
if (tAttr.Name.Equals(msgName))
|
||||||
|
{
|
||||||
|
var val = Enum.Parse(enumType, f.Name);
|
||||||
|
return Convert.ToInt32(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendMsg<T>(T msg) where T : IMessage<T>
|
public void SendMsg<T>(T msg) where T : IMessage<T>
|
||||||
{
|
{
|
||||||
int msgId = 0;
|
try
|
||||||
Type enumType = typeof(battle.cs.CMMessageId_e);
|
|
||||||
foreach(var f in enumType.GetFields())
|
|
||||||
{
|
{
|
||||||
var tAttrs = f.GetCustomAttributes(typeof(pbr::OriginalNameAttribute), false);
|
int msgId = this.GetCMMsgId(typeof(T).Name);
|
||||||
if (tAttrs.Length > 0) {
|
|
||||||
var tAttr = (pbr::OriginalNameAttribute)tAttrs[0];
|
|
||||||
if (tAttr.Name.Equals("")) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
var b = by.ToBytes();
|
|
||||||
by.Close();
|
|
||||||
ByteBuffer buffer = new ByteBuffer();
|
|
||||||
buffer.WriteShort((ushort)b.Length);
|
|
||||||
buffer.WriteShort((ushort)msgid);
|
|
||||||
buffer.WriteInt(0);
|
|
||||||
buffer.WriteShort(21323);
|
|
||||||
buffer.WriteShort(0);
|
|
||||||
buffer.WriteBytesNo(b);
|
|
||||||
var buf = buffer.ToBytes();
|
|
||||||
m_webSocket.Send(buf);
|
|
||||||
*/
|
|
||||||
int packLen = msg.CalculateSize();
|
int packLen = msg.CalculateSize();
|
||||||
const int magicCode = 21323;
|
const int magicCode = 21323;
|
||||||
byte[] data = new byte[12 + packLen];
|
byte[] data = new byte[12 + packLen];
|
||||||
@ -80,26 +89,33 @@ namespace Net
|
|||||||
data[11] = 0;
|
data[11] = 0;
|
||||||
msg.ToByteArray().CopyTo(data, 12);
|
msg.ToByteArray().CopyTo(data, 12);
|
||||||
this.ws.Send(data);
|
this.ws.Send(data);
|
||||||
}
|
}catch(Exception e)
|
||||||
|
|
||||||
private void OnOpen(WebSocket ws)
|
|
||||||
{
|
{
|
||||||
|
int i = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBinaryReceived(WebSocket ws, byte[] data)
|
private void OnWsOpen(WebSocket ws)
|
||||||
{
|
{
|
||||||
|
Debug.Log("ClientNet.OnOpen");
|
||||||
|
this.OnOpen(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnError(WebSocket ws, string reason)
|
private void OnWsBinaryReceived(WebSocket ws, byte[] data)
|
||||||
{
|
{
|
||||||
|
Debug.Log("ClientNet.OnBinaryReceived");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClosed(WebSocket ws, UInt16 code, string message)
|
private void OnWsError(WebSocket ws, string reason)
|
||||||
{
|
{
|
||||||
|
Debug.Log("ClientNet.OnError");
|
||||||
|
this.OnError(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnWsClosed(WebSocket ws, UInt16 code, string message)
|
||||||
|
{
|
||||||
|
Debug.Log("ClientNet.OnClosed");
|
||||||
|
this.OnClosed(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user