123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using System;
- using System.IO;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using UnityEngine;
- public class PresetServer : MonoBehaviour
- {
- public void Start()
- {
- int num = 47560;
- try
- {
- this.m_listener = new TcpListener(IPAddress.Any, num);
- this.m_listener.Start();
- Debug.Log("Port" + num.ToString() + "のListenを開始しました。");
- }
- catch (Exception ex)
- {
- NDebug.Assert(string.Concat(new object[]
- {
- "インターネット機能:ポート番号",
- num,
- "は既に利用されています。\n他の通信アプリケーションを終了してゲームを再起動して下さい。\n\n",
- ex.Message
- }), false);
- }
- }
- public void OnDestroy()
- {
- if (this.m_listener != null)
- {
- this.m_listener.Stop();
- }
- this.m_listener = null;
- if (this.nsWEB != null)
- {
- this.nsWEB.Close();
- }
- if (this.tcpWEB != null)
- {
- this.tcpWEB.Close();
- }
- this.nsWEB = null;
- this.tcpWEB = null;
- }
- [Obsolete("GameUty.RidMenuDic廃止により使用不可", true)]
- public void Update()
- {
- if (this.m_listener == null)
- {
- return;
- }
- if (this.nsWEB == null)
- {
- try
- {
- if (!this.m_listener.Pending())
- {
- return;
- }
- }
- catch (Exception ex)
- {
- Debug.LogError("PresetServer::Pending 例外。" + ex.Message);
- this.m_listener = null;
- return;
- }
- this.tcpWEB = this.m_listener.AcceptTcpClient();
- if (this.tcpWEB == null)
- {
- return;
- }
- this.nsWEB = this.tcpWEB.GetStream();
- if (this.nsWEB == null)
- {
- this.tcpWEB.Close();
- this.nsWEB = null;
- this.tcpWEB = null;
- }
- this.tcpWEB_count = 0;
- return;
- }
- else
- {
- if (!this.nsWEB.DataAvailable)
- {
- this.tcpWEB_count++;
- if (this.tcpWEB_count > 100)
- {
- this.nsWEB.Close();
- this.tcpWEB.Close();
- this.nsWEB = null;
- this.tcpWEB = null;
- Debug.Log("NotCanread クライアントを切断しました");
- }
- return;
- }
- byte[] array = new byte[4096];
- MemoryStream memoryStream = new MemoryStream();
- for (;;)
- {
- int num = this.nsWEB.Read(array, 0, array.Length);
- if (num == 0)
- {
- break;
- }
- memoryStream.Write(array, 0, num);
- if (!this.nsWEB.DataAvailable)
- {
- goto Block_8;
- }
- }
- this.nsWEB.Close();
- this.tcpWEB.Close();
- this.nsWEB = null;
- this.tcpWEB = null;
- Debug.Log("クライアントから切断されました。");
- return;
- Block_8:
- string text = this.enc.GetString(memoryStream.ToArray());
- memoryStream.Close();
- Debug.Log(text);
- if (text == null)
- {
- this.nsWEB.Close();
- this.tcpWEB.Close();
- this.nsWEB = null;
- this.tcpWEB = null;
- Debug.Log("resMsg==null");
- return;
- }
- int num2 = text.IndexOf("token=");
- if (0 < num2)
- {
- text = WWW.UnEscapeURL(text.Substring(num2, text.Length - num2).Replace("token=", string.Empty));
- CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
- if (!characterMgr.IsBusy() && characterMgr.GetMaid(0) != null)
- {
- CharacterMgr.Preset preset = CharacterMgr.LoadePresetLowCapacityData(text);
- if (preset != null)
- {
- characterMgr.PresetSet(characterMgr.GetMaid(0), preset, false);
- string s = "HTTP/1.0 204 OK\r\nConnection: close\r\n\r\n";
- byte[] bytes = this.enc.GetBytes(s);
- this.nsWEB.Write(bytes, 0, bytes.Length);
- }
- else
- {
- Debug.Log("CM3D2のプリセットデータではありません");
- }
- }
- }
- else
- {
- string text2 = "HTTP/1.0 204 OK\r\nConnection: close\r\n\r\n";
- byte[] bytes2 = this.enc.GetBytes(text2);
- this.nsWEB.Write(bytes2, 0, bytes2.Length);
- Debug.Log(text2);
- }
- this.nsWEB.Close();
- this.tcpWEB.Close();
- this.nsWEB = null;
- this.tcpWEB = null;
- }
- }
- private Encoding enc = Encoding.UTF8;
- private NetworkStream nsWEB;
- private TcpClient tcpWEB;
- private TcpListener m_listener;
- private int tcpWEB_count;
- }
|