fixed connected event, added ordered tcp messages (not group), automatically running login/connect
parent
06bc4a09fd
commit
9819ccfbf7
|
|
@ -19,6 +19,8 @@ namespace VelNet
|
||||||
{
|
{
|
||||||
public enum MessageSendType
|
public enum MessageSendType
|
||||||
{
|
{
|
||||||
|
MESSAGE_OTHERS_ORDERED = 7,
|
||||||
|
MESSAGE_ALL_ORDERED = 8,
|
||||||
MESSAGE_LOGIN = 0,
|
MESSAGE_LOGIN = 0,
|
||||||
MESSAGE_GETROOMS = 1,
|
MESSAGE_GETROOMS = 1,
|
||||||
MESSAGE_JOINROOM = 2,
|
MESSAGE_JOINROOM = 2,
|
||||||
|
|
@ -128,6 +130,11 @@ namespace VelNet
|
||||||
public int masterId;
|
public int masterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ConnectedMessage: Message
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public readonly List<Message> receivedMessages = new List<Message>();
|
public readonly List<Message> receivedMessages = new List<Message>();
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
|
|
@ -146,20 +153,9 @@ namespace VelNet
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
ConnectToTcpServer();
|
ConnectToTcpServer();
|
||||||
yield return null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
OnConnectedToServer?.Invoke();
|
|
||||||
}
|
|
||||||
// prevent errors in subscribers from breaking our code
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Debug.LogError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -181,6 +177,19 @@ namespace VelNet
|
||||||
{
|
{
|
||||||
switch (m)
|
switch (m)
|
||||||
{
|
{
|
||||||
|
case ConnectedMessage connected:
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OnConnectedToServer?.Invoke();
|
||||||
|
}
|
||||||
|
// prevent errors in subscribers from breaking our code
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError(e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case LoginMessage lm:
|
case LoginMessage lm:
|
||||||
{
|
{
|
||||||
userid = lm.userId;
|
userid = lm.userId;
|
||||||
|
|
@ -445,6 +454,8 @@ namespace VelNet
|
||||||
socketConnection = new TcpClient(host, port);
|
socketConnection = new TcpClient(host, port);
|
||||||
socketConnection.NoDelay = true;
|
socketConnection.NoDelay = true;
|
||||||
NetworkStream stream = socketConnection.GetStream();
|
NetworkStream stream = socketConnection.GetStream();
|
||||||
|
//now we are connected, so add a message to the queue
|
||||||
|
AddMessage(new ConnectedMessage());
|
||||||
//Join("MyRoom");
|
//Join("MyRoom");
|
||||||
//SendTo(MessageSendType.MESSAGE_OTHERS, Encoding.UTF8.GetBytes("Hello"));
|
//SendTo(MessageSendType.MESSAGE_OTHERS, Encoding.UTF8.GetBytes("Hello"));
|
||||||
//FormGroup("close", new List<uint> { 1 });
|
//FormGroup("close", new List<uint> { 1 });
|
||||||
|
|
@ -685,9 +696,14 @@ namespace VelNet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SendToRoom(byte[] message, bool include_self = false, bool reliable = true)
|
public static void SendToRoom(byte[] message, bool include_self = false, bool reliable = true, bool ordered = false)
|
||||||
{
|
{
|
||||||
byte sendType = (byte)(include_self ? MessageSendType.MESSAGE_ALL : MessageSendType.MESSAGE_OTHERS);
|
byte sendType = (byte) MessageSendType.MESSAGE_OTHERS;
|
||||||
|
if (include_self && ordered) sendType = (byte)MessageSendType.MESSAGE_ALL_ORDERED;
|
||||||
|
if (include_self && !ordered) sendType = (byte)MessageSendType.MESSAGE_ALL;
|
||||||
|
if (!include_self && ordered) sendType = (byte)MessageSendType.MESSAGE_OTHERS_ORDERED;
|
||||||
|
|
||||||
|
|
||||||
if (reliable)
|
if (reliable)
|
||||||
{
|
{
|
||||||
MemoryStream stream = new MemoryStream();
|
MemoryStream stream = new MemoryStream();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue