Commit 929de022 authored by hex's avatar hex

Changed card addition from double-click to long-press (good news for those with tenosynovitis)

parent 5cf5390a
Pipeline #37618 failed
using System;
using System.Net.Sockets;
using YGOSharp.Network.Enums;
using UnityEngine;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Net.Sockets;
using System.Text;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using YGOSharp.Network.Enums;
using YGOSharp.OCGWrapper.Enums;
public static class TcpHelper
......@@ -17,7 +17,13 @@ public static class TcpHelper
static bool canjoin = true;
static bool roomListChecking = false;
public static void join(string ipString, string name, string portString, string pswString, string version)
public static void join(
string ipString,
string name,
string portString,
string pswString,
string version
)
{
if (canjoin)
{
......@@ -26,7 +32,11 @@ public static class TcpHelper
canjoin = false;
try
{
tcpClient = new TcpClientWithTimeout(ipString, int.Parse(portString), 3000).Connect();
tcpClient = new TcpClientWithTimeout(
ipString,
int.Parse(portString),
3000
).Connect();
networkStream = tcpClient.GetStream();
Thread t = new Thread(receiver);
t.Start();
......@@ -59,7 +69,9 @@ public static class TcpHelper
{
try
{
while (tcpClient != null && networkStream != null && tcpClient.Connected && Program.Running)
while (
tcpClient != null && networkStream != null && tcpClient.Connected && Program.Running
)
{
byte[] data = SocketMaster.ReadPacket(networkStream);
addDateJumoLine(data);
......@@ -72,7 +84,6 @@ public static class TcpHelper
onDisConnected = true;
Program.DEBUGLOG("onDisConnected 3");
}
}
public static void addDateJumoLine(byte[] data)
......@@ -95,7 +106,7 @@ public static class TcpHelper
public static void preFrameFunction()
{
if (datas.Count>0)
if (datas.Count > 0)
{
if (Monitor.TryEnter(datas))
{
......@@ -198,23 +209,34 @@ public static class TcpHelper
{
onDisConnected = false;
Program.I().ocgcore.setDefaultReturnServant();
if (TcpHelper.tcpClient != null)
try
{
if (TcpHelper.tcpClient.Connected)
if (tcpClient != null)
{
tcpClient.Client.Shutdown(0);
if (tcpClient.Connected)
{
tcpClient.Client.Shutdown(SocketShutdown.Both);
}
tcpClient.Close();
}
}
catch (Exception e)
{
Debug.LogWarning("Socket cleanup failed: " + e.Message);
}
tcpClient = null;
if (Program.I().ocgcore.isShowed == false)
{
if (Program.I().menu.isShowed == false)
{
if (Program.I().mycard.isMatching) {
if (Program.I().mycard.isMatching)
{
Program.I().shiftToServant(Program.I().mycard);
} else {
}
else
{
Program.I().shiftToServant(Program.I().selectServer);
}
}
......@@ -225,10 +247,13 @@ public static class TcpHelper
}
else
{
Program.I().cardDescription.RMSshow_none(InterString.Get("对方离开游戏,您现在可以截图。"));
Program
.I()
.cardDescription.RMSshow_none(
InterString.Get("对方离开游戏,您现在可以截图。")
);
Program.I().ocgcore.forceMSquit();
}
}
}
......@@ -269,7 +294,6 @@ public static class TcpHelper
public static void CtosMessage_Response(byte[] response)
{
Package message = new Package();
message.Fuction = (int)CtosMessage.Response;
message.Data.writer.Write(response);
......@@ -277,6 +301,7 @@ public static class TcpHelper
}
public static YGOSharp.Deck deck;
public static void CtosMessage_UpdateDeck(YGOSharp.Deck deckFor)
{
if (deckFor.Main.Count == 0)
......@@ -335,12 +360,11 @@ public static class TcpHelper
Send(message);
}
public static void CtosMessage_CreateGame()
{
}
public static void CtosMessage_CreateGame() { }
public static List<string> deckStrings = new List<string>();
public static void CtosMessage_JoinGame(string psw,string version)
public static void CtosMessage_JoinGame(string psw, string version)
{
deckStrings.Clear();
Package message = new Package();
......@@ -541,6 +565,7 @@ public class Package
{
public int Fuction = 0;
public BinaryMaster Data = null;
public Package()
{
Fuction = (int)CtosMessage.Response;
......@@ -553,6 +578,7 @@ public class BinaryMaster
MemoryStream memstream = null;
public BinaryReader reader = null;
public BinaryWriter writer = null;
public BinaryMaster(byte[] raw = null)
{
if (raw == null)
......@@ -566,21 +592,25 @@ public class BinaryMaster
reader = new BinaryReader(memstream);
writer = new BinaryWriter(memstream);
}
public void set(byte[] raw)
{
memstream = new MemoryStream(raw);
reader = new BinaryReader(memstream);
writer = new BinaryWriter(memstream);
}
public byte[] get()
{
byte[] bytes = memstream.ToArray();
return bytes;
}
public int getLength()
{
return (int)memstream.Length;
}
public override string ToString()
{
string return_value = "";
......@@ -588,11 +618,11 @@ public class BinaryMaster
for (int i = 0; i < bytes.Length; i++)
{
return_value += ((int)bytes[i]).ToString();
if (i < bytes.Length - 1) return_value += ",";
if (i < bytes.Length - 1)
return_value += ",";
}
return return_value;
}
}
public static class BinaryExtensions
......@@ -617,7 +647,6 @@ public static class BinaryExtensions
{
UnityEngine.Debug.Log(e);
}
}
public static string ReadUnicode(this BinaryReader reader, int len)
......@@ -661,7 +690,7 @@ public static class BinaryExtensions
return a;
}
public static void readCardData(this BinaryReader r, gameCard cardTemp=null)
public static void readCardData(this BinaryReader r, gameCard cardTemp = null)
{
gameCard cardToRefresh = cardTemp;
int flag = r.ReadInt32();
......@@ -670,13 +699,13 @@ public static class BinaryExtensions
if ((flag & (int)Query.Code) != 0)
{
code= r.ReadInt32();
code = r.ReadInt32();
}
if ((flag & (int)Query.Position) != 0)
{
gps = r.ReadGPS();
cardToRefresh = null;
cardToRefresh = Program.I().ocgcore.GCS_cardGet(gps,false);
cardToRefresh = Program.I().ocgcore.GCS_cardGet(gps, false);
}
if (cardToRefresh == null)
......@@ -699,7 +728,6 @@ public static class BinaryExtensions
cardToRefresh.p = gps;
}
if (data.Id > 0)
{
if ((cardToRefresh.p.location & (UInt32)CardLocation.Hand) > 0)
......@@ -795,7 +823,11 @@ public static class BinaryExtensions
l3 = r.ReadInt32(); //link value
data.LinkMarker = r.ReadInt32();
}
if (((flag & (int)Query.Level) != 0) || ((flag & (int)Query.Rank) != 0) || ((flag & (int)Query.Link) != 0))
if (
((flag & (int)Query.Level) != 0)
|| ((flag & (int)Query.Rank) != 0)
|| ((flag & (int)Query.Link) != 0)
)
{
if (l1 > l2)
{
......@@ -805,7 +837,7 @@ public static class BinaryExtensions
{
data.Level = l2;
}
if(l3 > data.Level)
if (l3 > data.Level)
data.Level = l3;
}
......@@ -842,7 +874,6 @@ public class SocketMaster
var buf = ReadFull(stream, plen);
return buf;
}
}
public class TcpClientWithTimeout
......@@ -860,6 +891,7 @@ public class TcpClientWithTimeout
_port = port;
_timeout_milliseconds = timeout_milliseconds;
}
public TcpClient Connect()
{
// kick off the thread that tries to connect
......@@ -891,13 +923,17 @@ public class TcpClientWithTimeout
{
// 同样地抛出错误
thread.Abort();
string message = string.Format("TcpClient connection to {0}:{1} timed out",
_hostname, _port);
string message = string.Format(
"TcpClient connection to {0}:{1} timed out",
_hostname,
_port
);
TcpHelper.onDisConnected = true;
Program.DEBUGLOG("onDisConnected 8");
throw new TimeoutException(message);
}
}
protected void BeginConnect()
{
try
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment