Commit 71daa4ce authored by Unicorn369's avatar Unicorn369

Roomlist (by szefo09)

parent b5da0029
......@@ -15,6 +15,7 @@ public static class TcpHelper
static NetworkStream networkStream = null;
static bool canjoin = true;
static bool roomListChecking=false;
public static void join(string ipString, string name, string portString, string pswString, string version)
{
......@@ -30,6 +31,14 @@ public static class TcpHelper
Thread t = new Thread(receiver);
t.Start();
CtosMessage_PlayerInfo(name);
if (pswString == "L")
{
roomListChecking = true;
}
else
{
roomListChecking = false;
}
CtosMessage_JoinGame(pswString, version);
}
catch (Exception e)
......@@ -163,6 +172,9 @@ public static class TcpHelper
case YGOSharp.Network.Enums.StocMessage.HsWatchChange:
((Room)Program.I().room).StocMessage_HsWatchChange(r);
break;
case YGOSharp.Network.Enums.StocMessage.RoomList:
((Room)Program.I().room).StocMessage_RoomList(r);
break;
default:
break;
}
......@@ -196,7 +208,11 @@ public static class TcpHelper
{
Program.I().shiftToServant(Program.I().selectServer);
}
Program.I().cardDescription.RMSshow_none(InterString.Get("链接被断开。"));
if (!roomListChecking)
{
Program.I().cardDescription.RMSshow_none(InterString.Get("链接被断开。"));
}
}
else
{
......
......@@ -87,6 +87,7 @@ public class Program : MonoBehaviour
public GameObject new_ui_setting;
public GameObject new_ui_book;
public GameObject new_ui_selectServer;
public GameObject new_ui_RoomList;
public GameObject new_ui_gameInfo;
public GameObject new_ui_cardDescription;
public GameObject new_ui_search;
......@@ -899,6 +900,7 @@ public class Program : MonoBehaviour
public DeckManager deckManager;
public Ocgcore ocgcore;
public SelectServer selectServer;
public RoomList roomList;
public Book book;
public puzzleMode puzzleMode;
public AIRoom aiRoom;
......@@ -920,6 +922,8 @@ public class Program : MonoBehaviour
servants.Add(ocgcore);
selectServer = new SelectServer();
servants.Add(selectServer);
roomList = new RoomList();
servants.Add(roomList);
book = new Book();
servants.Add(book);
selectReplay = new selectReplay();
......@@ -976,6 +980,10 @@ public class Program : MonoBehaviour
{
aiRoom.hide();
}
if(to != roomList && to != selectServer && roomList.isShowed)
{
roomList.hide();
}
if (to == backGroundPic && backGroundPic.isShowed == false) backGroundPic.show();
if (to == menu && menu.isShowed == false) menu.show();
......@@ -988,6 +996,7 @@ public class Program : MonoBehaviour
if (to == selectReplay && selectReplay.isShowed == false) selectReplay.show();
if (to == puzzleMode && puzzleMode.isShowed == false) puzzleMode.show();
if (to == aiRoom && aiRoom.isShowed == false) aiRoom.show();
if (to == roomList && !roomList.isShowed) roomList.show();
}
......
......@@ -2,6 +2,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
public class Room : WindowServantSP
{
......@@ -284,6 +286,193 @@ public class Room : WindowServantSP
RMSshow_none(result);
}
public void StocMessage_RoomList(BinaryReader r)
{
//requires a dedicated button and a list to show rooms.
short count = BitConverter.ToInt16(r.ReadBytes(2), 0);
string roomname;
string player1 = "";
string player2 = "";
string hoststr=String.Empty;
List<string[]> roomList = new List<string[]>();
for (ushort i = 0; i < count; i++)
{
List<char> chars = new List<char>();
byte[] temp = r.ReadBytes(64);
roomname = Encoding.UTF8.GetString(temp);
roomname = roomname.Trim(new char[] { '\0' });
int room_status = Convert.ToInt16(BitConverter.ToString(r.ReadBytes(1), 0),16);
int room_duel_count = Convert.ToInt16(BitConverter.ToString(r.ReadBytes(1), 0),16);
int room_turn_count = Convert.ToInt16(BitConverter.ToString(r.ReadBytes(1), 0), 16);
temp = r.ReadBytes(128);
player1 = Encoding.UTF8.GetString(temp);
player1 = player1.Trim(new char[] { '\0' });
int player1_score = Convert.ToInt16(BitConverter.ToString(r.ReadBytes(1), 0));
int player1_lp = BitConverter.ToInt32(r.ReadBytes(4), 0);
temp = r.ReadBytes(128);
player2 = Encoding.UTF8.GetString(temp);
player2 = player2.Trim(new char[] { '\0' });
int player2_score = Convert.ToInt16(BitConverter.ToString(r.ReadBytes(1), 0));
int player2_lp = BitConverter.ToInt32(r.ReadBytes(4), 0);
if (room_status == 0)
{
player1 = player1.Replace("???", " ");
player2 = player2.Replace("???", " ");
}
string roomTag = RoomNameFormatter(roomname);
string[] strings = new string[]
{
room_duel_count.ToString(),
room_turn_count.ToString(),
roomname,
player1_score.ToString(),
player1_lp.ToString(),
player1,
player2,
player2_score.ToString(),
player2_lp.ToString(),
hoststr,
room_status.ToString(),
roomTag
};
switch (room_status)
{
case 0:
{
hoststr = "[EFD334][未开始][FFFFFF] " + strings[11] +"[FFFFFF]"+ strings[5] + " VS " + strings[6];
break;
}
case 1:
{
hoststr = "[A978ED][G:" + strings[0] + ",T:" + strings[1] + "][FFFFFF] " + strings[11] +"[FFFFFF]" + strings[5] + " VS " + strings[6];
break;
}
case 2:
{
hoststr = "[A978ED][G:" + strings[0] + ",Siding][FFFFFF] " + strings[11] + "[FFFFFF]" + strings[5] + " VS " + strings[6];
break;
}
default:
{
hoststr = String.Empty;
break;
}
}
strings[9] = hoststr;
roomList.Add(strings);
}
Program.I().roomList.UpdateList(roomList);
//Do something with the roomList.
}
string RoomNameFormatter(string roomname)
{
string roomTag=String.Empty;
List<string> tags = new List<string>();
if (Regex.IsMatch(roomname, @"^S,RANDOM#\d{1,}"))
{
roomTag = "[8AE57E][Duel] ";
return roomTag;
}
else if(Regex.IsMatch(roomname, @"^M,RANDOM#\d{1,}"))
{
roomTag = "[42C1EC][Match] ";
return roomTag;
}
else if(Regex.IsMatch(roomname, @"^AI#\S{0,},\d{1,}")|| Regex.IsMatch(roomname, @"^AI\S{0,}#\d{1,}"))
{
roomTag = "[5E71FF][AI] ";
return roomTag;
}
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}NF[,#])?(?(1)|(^NF[#,]))"))
{
tags.Add("[C63111][No Banlist] ");
}
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}LF\d[,#])?(?(1)|(^LF\d[#,]))"))
{
int banlist = (int)char.GetNumericValue(roomname[roomname.LastIndexOf("LF") + 2]);
YGOSharp.Banlist blist = YGOSharp.BanlistManager.Banlists[banlist - 1];
tags.Add("[DDDDAA][" + blist.Name + "]");
}
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}OO[,#])?(?(1)|(^OO[#,]))"))
{
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}OT[,#])?(?(1)|(^OT[#,]))"))
{
tags.Add("[11C69C][TCG/OCG]");
}
else
{
tags.Add("[B62FB2][OCG]");
}
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}S[,#])?(?(1)|(^S[#,]))"))
{
tags.Add("[8AE57E][Duel] ");
}
else if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}M[,#])?(?(1)|(^M[#,]))"))
{
tags.Add("[42C1EC][Match] ");
}
else if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}T[,#])?(?(1)|(^T[#,]))"))
{
tags.Add("[D14291][TAG] ");
}
}
else if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}TO[,#])?(?(1)|(^TO[#,]))"))
{
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}OT[,#])?(?(1)|(^OT[#,]))"))
{
tags.Add("[11C69C][TCG/OCG]");
}
else
{
tags.Add("[F58637][TCG]");
}
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}S[,#])?(?(1)|(^S[#,]))"))
{
tags.Add("[8AE57E][Duel] ");
}
else if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}M[,#])?(?(1)|(^M[#,]))"))
{
tags.Add("[42C1EC][Match] ");
}
else if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}T[,#])?(?(1)|(^T[#,]))"))
{
tags.Add("[D14291][TAG] ");
}
}
else
{
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}T[,#])?(?(1)|(^T[#,]))"))
{
tags.Add("[D14291][TAG]");
}
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}M[,#])?(?(1)|(^M[#,]))"))
{
tags.Add("[42C1EC][Match]");
}
if (Regex.IsMatch(roomname, @"(\w{1,}[,^]{1}S[,#])?(?(1)|(^S[#,]))")){
tags.Add("[8AE57E][Duel]");
}
}
roomTag = String.Join("", tags.ToArray())+" ";
if (roomTag == " ")
{
roomTag ="[ "+roomname+" ] ";
}
if (roomTag.Length > 150)
{
roomTag = "[CUSTOM] ";
}
return roomTag;
}
public void StocMessage_Replay(BinaryReader r)
{
byte[] data = r.ReadToEnd();
......
using UnityEngine;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Linq;
public class RoomList : WindowServantSP
{
UIselectableList superScrollView = null;
List<string[]> listOfRooms = new List<string[]>();
bool hideAI;
bool hideStarted;
UILabel roomNameLabel;
public override void initialize()
{
createWindow(Program.I().new_ui_RoomList);
UIHelper.registEvent(gameObject, "exit_", onClickExit);
UIHelper.registEvent(gameObject, "refresh_", onRefresh);
roomNameLabel = UIHelper.getByName<UILabel>(gameObject, "roomNameLabel");
hideAI =UIHelper.getByName<UIToggle>(gameObject, "hideAIrooms_").value = UIHelper.fromStringToBool(Config.Get("hideAIrooms_", "1"));
hideStarted=UIHelper.getByName<UIToggle>(gameObject, "hideStarted_").value = UIHelper.fromStringToBool(Config.Get("hideStarted_", "1"));
UIHelper.registEvent(gameObject, "hideAIrooms_", save);
UIHelper.registEvent(gameObject, "hideStarted_", save);
superScrollView = gameObject.GetComponentInChildren<UIselectableList>();
superScrollView.selectedAction = onSelected;
superScrollView.install();
SetActiveFalse();
}
private void save()
{
hideAI = UIHelper.getByName<UIToggle>(gameObject, "hideAIrooms_").value;
hideStarted = UIHelper.getByName<UIToggle>(gameObject, "hideStarted_").value;
Config.Set("hideAIrooms_", UIHelper.fromBoolToString(UIHelper.getByName<UIToggle>(gameObject, "hideAIrooms_").value));
Config.Set("hideStarted_", UIHelper.fromBoolToString(UIHelper.getByName<UIToggle>(gameObject, "hideStarted_").value));
}
private void onRefresh()
{
Program.I().selectServer.onClickRoomList();
}
public void UpdateList(List<string[]> roomList)
{
show();
listOfRooms.Clear();
listOfRooms.AddRange(roomList);
printFile();
}
public void onClickExit()
{
hide();
}
public override void hide()
{
roomNameLabel.text = "";
base.hide();
}
private void printFile()
{
superScrollView.clear();
superScrollView.toTop();
if (hideAI)
{
listOfRooms.RemoveAll(s => s[11].Contains("AI"));
}
if (hideStarted)
{
listOfRooms.RemoveAll(s => Convert.ToInt32(s[10]) != 0);
}
listOfRooms.TrimExcess();
listOfRooms = listOfRooms.OrderBy(s => s[3]).ToList();
foreach (string[] room in listOfRooms)
{
superScrollView.add(room[9]);
}
//for (int i = 0; i < listOfRooms.Count; i++)
//{
// //if (listOfRooms[i].Length > 4)
// //{
// // //if (/*listOfRooms[i].Substring(fileInfos[i].Name.Length - 4, 4) == ".lua"*/)
// // //{
// // // // superScrollView.add(listOfRooms[i].Substring(0, listOf.Name.Length - 4));
// // //}
// //}
//}
}
string selectedString = string.Empty;
void onSelected()
{
if (!isShowed)
{
return;
}
string roomPsw;
if (selectedString == superScrollView.selectedString)
{
roomPsw= listOfRooms.Find(s => s[9] == selectedString)[2];
JoinRoom(superScrollView.selectedString,roomPsw);
return;
}
selectedString = superScrollView.selectedString;
roomPsw= listOfRooms.Find(s => s[9] == selectedString)[2];
int roomNameIndex = roomPsw.LastIndexOf("#")+1;
if (roomNameIndex > 0)
{
roomNameLabel.text = roomPsw.Substring(roomNameIndex);
}
}
void JoinRoom(string selectedString,string roomPsw)
{
string Name = UIHelper.getByName<UIInput>(Program.I().selectServer.gameObject, "name_").value;
string ipString = UIHelper.getByName<UIInput>(Program.I().selectServer.gameObject, "ip_").value;
string portString = UIHelper.getByName<UIInput>(Program.I().selectServer.gameObject, "port_").value;
string pswString = roomPsw;
string versionString = UIHelper.getByName<UIInput>(Program.I().selectServer.gameObject, "version_").value;
if (versionString == "")
{
UIHelper.getByName<UIInput>(Program.I().selectServer.gameObject, "version_").value = "0x1348";
versionString = "0x1348";
}
Program.I().roomList.hide();
Program.I().selectServer.KF_onlineGame(Name, ipString, portString, versionString, pswString);
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 3dc3c230506cd4f409746edaac651b29
timeCreated: 1551335384
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -19,6 +19,7 @@ public class SelectServer : WindowServantSP
UIHelper.registEvent(gameObject, "exit_", onClickExit);
UIHelper.registEvent(gameObject, "face_", onClickFace);
UIHelper.registEvent(gameObject, "join_", onClickJoin);
//UIHelper.registEvent(gameObject, "roomList_", onClickRoomList);
UIHelper.getByName<UIInput>(gameObject, "name_").value = Config.Get("name","一秒一喵机会");
list = UIHelper.getByName<UIPopupList>(gameObject, "history_");
UIHelper.registEvent(gameObject,"history_", onSelected);
......@@ -150,6 +151,25 @@ public class SelectServer : WindowServantSP
KF_onlineGame(Name, ipString, portString, versionString, pswString);
}
public void onClickRoomList()
{
if (!isShowed)
{
return;
}
string Name = UIHelper.getByName<UIInput>(gameObject, "name_").value;
string ipString = UIHelper.getByName<UIInput>(gameObject, "ip_").value;
string portString = UIHelper.getByName<UIInput>(gameObject, "port_").value;
string pswString = "L";
string versionString = UIHelper.getByName<UIInput>(gameObject, "version_").value;
if (versionString == "")
{
UIHelper.getByName<UIInput>(gameObject, "version_").value = "0x1348";
versionString = "0x1348";
}
KF_onlineGame(Name, ipString, portString, versionString, pswString);
}
public void KF_onlineGame(string Name,string ipString, string portString, string versionString, string pswString="")
{
name = Name;
......
......@@ -21,6 +21,7 @@
Chat = 0x19,
HsPlayerEnter = 0x20,
HsPlayerChange = 0x21,
HsWatchChange = 0x22
HsWatchChange = 0x22,
RoomList = 0x31
}
}
This diff is collapsed.
......@@ -450,7 +450,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 171500}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2, y: 274, z: 0}
m_LocalPosition: {x: 2, y: 273, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 419752}
......@@ -813,7 +813,7 @@ BoxCollider:
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 20, y: 20, z: 0}
m_Size: {x: 30, y: 30, z: 0}
m_Center: {x: 0, y: 0, z: 0}
--- !u!65 &6550730
BoxCollider:
......@@ -963,7 +963,7 @@ MonoBehaviour:
keepCrispWhenShrunk: 1
mTrueTypeFont: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
mFont: {fileID: 0}
mText: Hide active duels
mText: "\u9690\u85CF\u5F00\u59CB\u7684\u623F\u95F4"
mFontSize: 20
mFontStyle: 0
mAlignment: 0
......@@ -1251,7 +1251,7 @@ MonoBehaviour:
keepCrispWhenShrunk: 1
mTrueTypeFont: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
mFont: {fileID: 0}
mText: Room List
mText: "\u623F\u95F4\u4FE1\u606F"
mFontSize: 30
mFontStyle: 0
mAlignment: 1
......@@ -1417,7 +1417,7 @@ MonoBehaviour:
keepCrispWhenShrunk: 1
mTrueTypeFont: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
mFont: {fileID: 0}
mText: Hide AI rooms
mText: "\u9690\u85CF\u4EBA\u673A\u7684\u623F\u95F4"
mFontSize: 20
mFontStyle: 0
mAlignment: 0
......@@ -1523,24 +1523,24 @@ MonoBehaviour:
leftAnchor:
target: {fileID: 419752}
relative: 1
absolute: -39
absolute: -44
rightAnchor:
target: {fileID: 419752}
relative: 1
absolute: -19
absolute: -14
bottomAnchor:
target: {fileID: 419752}
relative: 1
absolute: -47
absolute: -52
topAnchor:
target: {fileID: 419752}
relative: 1
absolute: -27
absolute: -22
updateAnchors: 1
mColor: {r: 1, g: 1, b: 1, a: 1}
mPivot: 4
mWidth: 20
mHeight: 20
mWidth: 30
mHeight: 30
mDepth: 1
autoResizeBoxCollider: 1
hideIfOffScreen: 0
......@@ -1595,7 +1595,7 @@ MonoBehaviour:
autoResizeBoxCollider: 0
hideIfOffScreen: 0
keepAspectRatio: 0
aspectRatio: 0.9369863
aspectRatio: 0.94
mType: 0
mFillDirection: 4
mFillAmount: 1
......@@ -1762,7 +1762,7 @@ MonoBehaviour:
keepCrispWhenShrunk: 1
mTrueTypeFont: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
mFont: {fileID: 0}
mText: 'Room Name: '
mText: "\u623F\u95F4\u540D\uFF1A"
mFontSize: 25
mFontStyle: 0
mAlignment: 1
......@@ -2240,7 +2240,6 @@ MonoBehaviour:
mod: {fileID: 120608, guid: b102b714e94a8bf4abf4b4ada52e4158, type: 2}
panel: {fileID: 11450640}
scrollBar: {fileID: 11447614}
heightOfEach: 20
preHeight: 0
--- !u!114 &11487676
MonoBehaviour:
......@@ -2408,7 +2407,7 @@ MonoBehaviour:
keepCrispWhenShrunk: 1
mTrueTypeFont: {fileID: 12800000, guid: f775853fdfd14bb47934543e95c3bae3, type: 3}
mFont: {fileID: 0}
mText: Refresh
mText: "\u5237\u65B0\u623F\u95F4"
mFontSize: 20
mFontStyle: 0
mAlignment: 1
......
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