2024-12-15 01:39:39 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using WebSocketSharp;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using TMPro;
|
|
|
|
|
|
|
|
|
|
public class MessageInfo : MenuBase
|
|
|
|
|
{
|
|
|
|
|
public static MessageInfo Ins;
|
|
|
|
|
|
|
|
|
|
public ChatUI m_ChatUI;
|
|
|
|
|
|
|
|
|
|
WebSocket ws;
|
|
|
|
|
string ws_url;
|
|
|
|
|
float ReconnectTime = 0f, PingTime = 60f;
|
|
|
|
|
List<MessageEventArgs> list_MessageEventArgs = new List<MessageEventArgs>();
|
|
|
|
|
private bool bwsOnOpen, bwsOnClose, bwsOnError;
|
|
|
|
|
|
|
|
|
|
protected override void Awake()
|
|
|
|
|
{
|
|
|
|
|
Ins = this;
|
|
|
|
|
|
|
|
|
|
ws_url = ServerInfo.Ins.m_SC_ServerStatus.URL_ChatServer;
|
|
|
|
|
ConnectToServer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
Set();
|
2025-01-04 00:06:47 +00:00
|
|
|
//();
|
2024-12-15 01:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-08 22:22:31 +00:00
|
|
|
void Update()
|
2024-12-15 01:39:39 +00:00
|
|
|
{
|
2025-02-08 22:22:31 +00:00
|
|
|
if (DSUtil.CheckNull(ws))
|
2024-12-15 01:39:39 +00:00
|
|
|
{
|
|
|
|
|
ReconnectTime += Time.deltaTime;
|
|
|
|
|
if (ReconnectTime > 60f)
|
|
|
|
|
{
|
2025-01-04 00:06:47 +00:00
|
|
|
//label_small.text = "채팅 서버에 재접속을 시도합니다.";
|
2024-12-15 01:39:39 +00:00
|
|
|
ReconnectTime = 0f;
|
|
|
|
|
ConnectToServer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Send_Ping();
|
|
|
|
|
if (list_MessageEventArgs.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
// 채팅 메시지 처리
|
|
|
|
|
var split = list_MessageEventArgs[0].Data.Split('|');
|
|
|
|
|
list_MessageEventArgs.RemoveAt(0);
|
|
|
|
|
ChatType type = DSUtil.StringToEnum<ChatType>(split[0]);
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case ChatType.Chat:
|
|
|
|
|
m_ChatUI.Add_Chat(split);
|
|
|
|
|
break;
|
|
|
|
|
case ChatType.Notice:
|
2025-01-04 00:06:47 +00:00
|
|
|
//m_NotiUI.Add_Msg(split[2]);
|
2024-12-15 01:39:39 +00:00
|
|
|
break;
|
|
|
|
|
case ChatType.HotTime:
|
|
|
|
|
ServerInfo.Ins.Set_HotTime(split[2]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bwsOnOpen)
|
|
|
|
|
{
|
|
|
|
|
bwsOnOpen = false;
|
|
|
|
|
Send_Msg(ChatType.Connect, "");
|
|
|
|
|
}
|
|
|
|
|
if (bwsOnClose)
|
|
|
|
|
{
|
|
|
|
|
bwsOnClose = false;
|
|
|
|
|
OnApplicationQuit();
|
2025-01-04 00:06:47 +00:00
|
|
|
//label_small.text = "채팅 서버에 재접속 중 입니다.";
|
2024-12-15 01:39:39 +00:00
|
|
|
}
|
|
|
|
|
if (bwsOnError)
|
|
|
|
|
{
|
|
|
|
|
bwsOnError = false;
|
|
|
|
|
OnApplicationQuit();
|
2025-01-04 00:06:47 +00:00
|
|
|
//label_small.text = "채팅 서버에 재접속 중 입니다.";
|
2024-12-15 01:39:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConnectToServer()
|
|
|
|
|
{
|
2025-01-21 23:52:24 +00:00
|
|
|
return; // TODO 정인호 : 현재 서버 off로 인해 꺼둠
|
|
|
|
|
|
2025-02-08 22:22:31 +00:00
|
|
|
if (!DSUtil.CheckNull(ws) && ws.IsAlive) return;
|
2024-12-15 01:39:39 +00:00
|
|
|
|
|
|
|
|
ws = new WebSocket(ws_url);
|
|
|
|
|
|
|
|
|
|
ws.OnMessage += ws_OnMessage; //서버에서 유니티 쪽으로 메세지가 올 경우 실행할 함수를 등록한다.
|
|
|
|
|
ws.OnOpen += ws_OnOpen;//서버가 연결된 경우 실행할 함수를 등록한다
|
|
|
|
|
ws.OnClose += ws_OnClose;//서버가 닫힌 경우 실행할 함수를 등록한다.
|
|
|
|
|
ws.OnError += ws_OnError;//에러 등록
|
|
|
|
|
//ws.ConnectAsync();//서버에 연결한다. (비동기)
|
|
|
|
|
ws.Connect();//서버에 연결한다. (동기)
|
|
|
|
|
}
|
|
|
|
|
void ws_OnMessage(object sender, MessageEventArgs e) { list_MessageEventArgs.Add(e); }
|
|
|
|
|
void ws_OnOpen(object sender, EventArgs e) { bwsOnOpen = true; }
|
|
|
|
|
void ws_OnClose(object sender, CloseEventArgs e) { bwsOnClose = true; }
|
|
|
|
|
void ws_OnError(object sender, ErrorEventArgs e) { bwsOnError = true; }
|
|
|
|
|
|
|
|
|
|
void OnApplicationQuit()
|
|
|
|
|
{
|
|
|
|
|
Send_Msg(ChatType.DisConnect, "");
|
2025-02-08 22:22:31 +00:00
|
|
|
if (!DSUtil.CheckNull(ws)) ws.Close();
|
2024-12-15 01:39:39 +00:00
|
|
|
ws = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Send_Msg(ChatType _type, string _msg)
|
|
|
|
|
{
|
|
|
|
|
if (ServerInfo.Ins.IsChatBan && _type == ChatType.Chat)
|
|
|
|
|
{
|
|
|
|
|
ToastUI.Ins.Set(107);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ws != null)
|
|
|
|
|
{
|
|
|
|
|
_msg = _msg.Replace("|", ""); // | 구분자이므로 모두 제거
|
|
|
|
|
string sendMsg;
|
|
|
|
|
switch (_type)
|
|
|
|
|
{
|
|
|
|
|
case ChatType.Connect:
|
|
|
|
|
case ChatType.DisConnect:
|
|
|
|
|
sendMsg = DSUtil.Format("{0}|{1}", _type, ServerInfo.Ins.m_LoginInfo.PlayFabId);
|
|
|
|
|
break;
|
|
|
|
|
case ChatType.Notice:
|
|
|
|
|
sendMsg = DSUtil.Format("{0}|{1}|{2}", _type, ServerInfo.Ins.m_LoginInfo.PlayFabId, _msg); // 이유는 모르겠는데 플레이팹 아이디를 중간에 끼우니까 메시지 여러 번 오는 버그 사라짐 -_-;;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
var sdata = ServerInfo.Ins.m_ServerData;
|
2025-06-28 22:40:22 +00:00
|
|
|
// 타입(0) | 플레이팹ID(1) | 얼굴아이콘(2) | 이름(3) | 메시지(4)
|
|
|
|
|
sendMsg = DSUtil.Format("{0}|{1}|{2}|{3}|{4}", _type, ServerInfo.Ins.m_LoginInfo.PlayFabId, sdata.Get_EqiupmentEquip(eItem.PC), ServerInfo.Ins.UserName, ChattingCheckWords.ConvertChat(_msg));
|
2024-12-15 01:39:39 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ws.Send(sendMsg);
|
|
|
|
|
PingTime = 60f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void Send_Ping()
|
|
|
|
|
{
|
|
|
|
|
if (ws != null)
|
|
|
|
|
{
|
|
|
|
|
if (PingTime > 0f)
|
|
|
|
|
{
|
|
|
|
|
PingTime -= RealTime.deltaTime;
|
|
|
|
|
if (PingTime <= 0f)
|
|
|
|
|
{
|
|
|
|
|
PingTime = 60f;
|
|
|
|
|
ws.Ping(); // 일단 핑 보내기만 true, false 처리는 따로 안해도 될 듯
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void Add_NotiToChatServer(string _msg)
|
|
|
|
|
{
|
|
|
|
|
Send_Msg(ChatType.Notice, _msg);
|
|
|
|
|
}
|
2025-01-04 00:06:47 +00:00
|
|
|
public void Add_Log(int _msgkey)
|
|
|
|
|
{
|
|
|
|
|
//m_LogUI.Add_Msg(table_localtext.Ins.Get_Text(_msgkey));
|
|
|
|
|
}
|
|
|
|
|
public void Add_Log(int _msgkey, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
//m_LogUI.Add_Msg(DSUtil.Format(_msgkey, args));
|
|
|
|
|
}
|
2024-12-15 01:39:39 +00:00
|
|
|
|
|
|
|
|
public void OnClick_ShowBig()
|
|
|
|
|
{
|
|
|
|
|
Set();
|
|
|
|
|
//go_Move.transform.localPosition = new Vector3(245f, 9f, -750f);
|
2025-01-04 00:06:47 +00:00
|
|
|
m_ChatUI.GetComponent<RectTransform>().anchoredPosition = new Vector2(275f, 261f);
|
2024-12-15 01:39:39 +00:00
|
|
|
m_ChatUI.OnSubmit_ResetStatus();
|
|
|
|
|
}
|
|
|
|
|
public override void OnClick_Back()
|
|
|
|
|
{
|
|
|
|
|
BackKeyMgr.Ins.Del_Back(OnClick_Back);
|
2025-01-04 00:06:47 +00:00
|
|
|
m_ChatUI.GetComponent<RectTransform>().anchoredPosition = new Vector2(-1000f, 261f);
|
2024-12-15 01:39:39 +00:00
|
|
|
}
|
|
|
|
|
public void AlphaChange()
|
|
|
|
|
{
|
2025-01-04 00:06:47 +00:00
|
|
|
//m_CanvasGroup.alpha = Mathf.Max(0.2f, slider_alpha.value);
|
2024-12-15 01:39:39 +00:00
|
|
|
}
|
|
|
|
|
}
|