scripts
This commit is contained in:
@@ -0,0 +1,261 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
|
||||
namespace ExitGames.Client.Photon
|
||||
{
|
||||
// Token: 0x02000032 RID: 50
|
||||
internal class SocketUdp : IPhotonSocket, IDisposable
|
||||
{
|
||||
// Token: 0x06000238 RID: 568 RVA: 0x00012064 File Offset: 0x00010264
|
||||
public SocketUdp(PeerBase npeer)
|
||||
: base(npeer)
|
||||
{
|
||||
bool flag = base.ReportDebugOfLevel(DebugLevel.ALL);
|
||||
if (flag)
|
||||
{
|
||||
base.Listener.DebugReturn(DebugLevel.ALL, "CSharpSocket: UDP, Unity3d.");
|
||||
}
|
||||
this.PollReceive = false;
|
||||
}
|
||||
|
||||
// Token: 0x06000239 RID: 569 RVA: 0x000120AC File Offset: 0x000102AC
|
||||
public void Dispose()
|
||||
{
|
||||
base.State = PhotonSocketState.Disconnecting;
|
||||
bool flag = this.sock != null;
|
||||
if (flag)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool connected = this.sock.Connected;
|
||||
if (connected)
|
||||
{
|
||||
this.sock.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
base.EnqueueDebugReturn(DebugLevel.INFO, "Exception in Dispose(): " + ex);
|
||||
}
|
||||
}
|
||||
this.sock = null;
|
||||
base.State = PhotonSocketState.Disconnected;
|
||||
}
|
||||
|
||||
// Token: 0x0600023A RID: 570 RVA: 0x00012128 File Offset: 0x00010328
|
||||
public override bool Connect()
|
||||
{
|
||||
object obj = this.syncer;
|
||||
bool flag3;
|
||||
lock (obj)
|
||||
{
|
||||
bool flag = base.Connect();
|
||||
bool flag2 = !flag;
|
||||
if (flag2)
|
||||
{
|
||||
flag3 = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.State = PhotonSocketState.Connecting;
|
||||
new Thread(new ThreadStart(this.DnsAndConnect))
|
||||
{
|
||||
Name = "photon dns thread",
|
||||
IsBackground = true
|
||||
}.Start();
|
||||
flag3 = true;
|
||||
}
|
||||
}
|
||||
return flag3;
|
||||
}
|
||||
|
||||
// Token: 0x0600023B RID: 571 RVA: 0x000121B0 File Offset: 0x000103B0
|
||||
public override bool Disconnect()
|
||||
{
|
||||
bool flag = base.ReportDebugOfLevel(DebugLevel.INFO);
|
||||
if (flag)
|
||||
{
|
||||
base.EnqueueDebugReturn(DebugLevel.INFO, "CSharpSocket.Disconnect()");
|
||||
}
|
||||
base.State = PhotonSocketState.Disconnecting;
|
||||
object obj = this.syncer;
|
||||
lock (obj)
|
||||
{
|
||||
bool flag2 = this.sock != null;
|
||||
if (flag2)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.sock.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
base.EnqueueDebugReturn(DebugLevel.INFO, "Exception in Disconnect(): " + ex);
|
||||
}
|
||||
this.sock = null;
|
||||
}
|
||||
}
|
||||
base.State = PhotonSocketState.Disconnected;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x0600023C RID: 572 RVA: 0x00012264 File Offset: 0x00010464
|
||||
public override PhotonSocketError Send(byte[] data, int length)
|
||||
{
|
||||
object obj = this.syncer;
|
||||
lock (obj)
|
||||
{
|
||||
bool flag = this.sock == null || !this.sock.Connected;
|
||||
if (flag)
|
||||
{
|
||||
return PhotonSocketError.Skipped;
|
||||
}
|
||||
try
|
||||
{
|
||||
this.sock.Send(data, 0, length, SocketFlags.None);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bool flag2 = base.ReportDebugOfLevel(DebugLevel.ERROR);
|
||||
if (flag2)
|
||||
{
|
||||
base.EnqueueDebugReturn(DebugLevel.ERROR, "Cannot send to: " + base.ServerAddress + ". " + ex.Message);
|
||||
}
|
||||
return PhotonSocketError.Exception;
|
||||
}
|
||||
}
|
||||
return PhotonSocketError.Success;
|
||||
}
|
||||
|
||||
// Token: 0x0600023D RID: 573 RVA: 0x0001231C File Offset: 0x0001051C
|
||||
public override PhotonSocketError Receive(out byte[] data)
|
||||
{
|
||||
data = null;
|
||||
return PhotonSocketError.NoData;
|
||||
}
|
||||
|
||||
// Token: 0x0600023E RID: 574 RVA: 0x00012334 File Offset: 0x00010534
|
||||
internal void DnsAndConnect()
|
||||
{
|
||||
IPAddress ipaddress = null;
|
||||
try
|
||||
{
|
||||
ipaddress = IPhotonSocket.GetIpAddress(base.ServerAddress);
|
||||
bool flag = ipaddress == null;
|
||||
if (flag)
|
||||
{
|
||||
throw new ArgumentException("Invalid IPAddress. Address: " + base.ServerAddress);
|
||||
}
|
||||
object obj = this.syncer;
|
||||
lock (obj)
|
||||
{
|
||||
bool flag2 = base.State == PhotonSocketState.Disconnecting || base.State == PhotonSocketState.Disconnected;
|
||||
if (flag2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.sock = new Socket(ipaddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
|
||||
this.sock.Connect(ipaddress, base.ServerPort);
|
||||
base.AddressResolvedAsIpv6 = base.IsIpv6SimpleCheck(ipaddress);
|
||||
base.State = PhotonSocketState.Connected;
|
||||
this.peerBase.OnConnect();
|
||||
}
|
||||
}
|
||||
catch (SecurityException ex)
|
||||
{
|
||||
bool flag3 = base.ReportDebugOfLevel(DebugLevel.ERROR);
|
||||
if (flag3)
|
||||
{
|
||||
base.Listener.DebugReturn(DebugLevel.ERROR, string.Concat(new string[]
|
||||
{
|
||||
"Connect() to '",
|
||||
base.ServerAddress,
|
||||
"' (",
|
||||
(ipaddress == null) ? "" : ipaddress.AddressFamily.ToString(),
|
||||
") failed: ",
|
||||
ex.ToString()
|
||||
}));
|
||||
}
|
||||
base.HandleException(StatusCode.SecurityExceptionOnConnect);
|
||||
return;
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
bool flag4 = base.ReportDebugOfLevel(DebugLevel.ERROR);
|
||||
if (flag4)
|
||||
{
|
||||
base.Listener.DebugReturn(DebugLevel.ERROR, string.Concat(new string[]
|
||||
{
|
||||
"Connect() to '",
|
||||
base.ServerAddress,
|
||||
"' (",
|
||||
(ipaddress == null) ? "" : ipaddress.AddressFamily.ToString(),
|
||||
") failed: ",
|
||||
ex2.ToString()
|
||||
}));
|
||||
}
|
||||
base.HandleException(StatusCode.ExceptionOnConnect);
|
||||
return;
|
||||
}
|
||||
new Thread(new ThreadStart(this.ReceiveLoop))
|
||||
{
|
||||
Name = "photon receive thread",
|
||||
IsBackground = true
|
||||
}.Start();
|
||||
}
|
||||
|
||||
// Token: 0x0600023F RID: 575 RVA: 0x0001255C File Offset: 0x0001075C
|
||||
public void ReceiveLoop()
|
||||
{
|
||||
byte[] array = new byte[base.MTU];
|
||||
while (base.State == PhotonSocketState.Connected)
|
||||
{
|
||||
try
|
||||
{
|
||||
int num = this.sock.Receive(array);
|
||||
base.HandleReceivedDatagram(array, num, true);
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
bool flag = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected;
|
||||
if (flag)
|
||||
{
|
||||
bool flag2 = base.ReportDebugOfLevel(DebugLevel.ERROR);
|
||||
if (flag2)
|
||||
{
|
||||
base.EnqueueDebugReturn(DebugLevel.ERROR, string.Concat(new object[]
|
||||
{
|
||||
"Receive issue. State: ", base.State, ". Server: '", base.ServerAddress, "' ErrorCode: ", ex.ErrorCode, " SocketErrorCode: ", ex.SocketErrorCode, " Message: ", ex.Message,
|
||||
" ", ex
|
||||
}));
|
||||
}
|
||||
base.HandleException(StatusCode.ExceptionOnReceive);
|
||||
}
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
bool flag3 = base.State != PhotonSocketState.Disconnecting && base.State > PhotonSocketState.Disconnected;
|
||||
if (flag3)
|
||||
{
|
||||
bool flag4 = base.ReportDebugOfLevel(DebugLevel.ERROR);
|
||||
if (flag4)
|
||||
{
|
||||
base.EnqueueDebugReturn(DebugLevel.ERROR, string.Concat(new object[] { "Receive issue. State: ", base.State, ". Server: '", base.ServerAddress, "' Message: ", ex2.Message, " Exception: ", ex2 }));
|
||||
}
|
||||
base.HandleException(StatusCode.ExceptionOnReceive);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Disconnect();
|
||||
}
|
||||
|
||||
// Token: 0x0400014D RID: 333
|
||||
private Socket sock;
|
||||
|
||||
// Token: 0x0400014E RID: 334
|
||||
private readonly object syncer = new object();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user