📄 winclient.cs
字号:
this.inputBox,
this.chatBox,
this.boardList,
this.clientList,
this.statusBar,
this.toolBar});
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu;
this.Name = "WinClient";
this.Text = "Aicaca Client";
((System.ComponentModel.ISupportInitialize)(this.mainStatus)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.processStatus)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void configMenu_Click(object sender, System.EventArgs e)
{
new WinConfig(this);
}
private void startMenu_Click(object sender, System.EventArgs e)
{
this.StartAll();
}
private void stopMenu_Click(object sender, System.EventArgs e)
{
this.StopAll();
}
private void hideMenu_Click(object sender, System.EventArgs e)
{
this.Visible = false;
}
private void shutMenu_Click(object sender, System.EventArgs e)
{
this.ShutDown();
}
private void aboutMenu_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start("IEXPLORE.EXE", "www.aicaca.com");
}
private void sendButton_Click(object sender, System.EventArgs e)
{
if (this.inputBox.Text.Length > 0)
{
string sendStr = WC.MakeXML("ms", "ILOVEAICACACHA") + localID + rootID + "<body>" + this.inputBox.Text;
this.SendRootMsg(sendStr);
}
this.inputBox.Text = "";
this.inputBox.Focus();
}
private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
string str = e.Button.Text;
switch(str)
{
case "Config":
new WinConfig(this);
break;
case "Client Start":
this.StartAll();
break;
case "Client Stop":
this.StopAll();
break;
case "Hide":
this.Visible = false;
break;
case "Shut Down":
this.ShutDown();
break;
}
}
private void clientList_DoubleClick (object sender, System.EventArgs e)
{
string clientName = clientList.SelectedItems[0].SubItems[0].Text;
string clientIP = clientList.SelectedItems[0].SubItems[1].Text;
string clientPort = clientList.SelectedItems[0].SubItems[2].Text;
string clientID = WC.MakeClientID("WinClient", clientName, clientIP, clientPort);
this.StartWinDialog_Connect(clientID);
}
private void boardList_DoubleClick (object sender, System.EventArgs e)
{
string boardName = this.boardList.SelectedItems[0].Text;
XmlDocument xd = new XmlDocument();
xd.Load(new XmlTextReader(new StringReader(configData)));
XmlNode xn = xd.SelectSingleNode("Config/BoardList/Board[BoardName='" + boardName + "']");
string boardID = xn.SelectSingleNode("BoardID").InnerText;
string boardPassword = xn.SelectSingleNode("BoardPassword").InnerText;
string boardType = xn.SelectSingleNode("BoardType").InnerText;
if (!FormHash.Contains(WC.MakeXML("WinBoard", boardID)))
{
this.StartWinBoard(boardID, boardName, boardPassword, boardType);
}
}
private void TrayIcon_DoubleClick (object sender, System.EventArgs e)
{
this.Visible = true;
}
private void InitializeClient()
{
DirectoryInfo xDirInfo = new DirectoryInfo(WC.varStr1);
if (!xDirInfo.Exists) xDirInfo.Create();
if (System.IO.File.Exists(WC.varStr1 + "ClientConfig.xml") == false)
{
XmlTextWriter xw = new XmlTextWriter(WC.varStr1 + "ClientConfig.xml", null);
xw.WriteStartElement("Config");
xw.WriteStartElement("LocalID");
xw.WriteElementString("LocalSort", "WinClient");
xw.WriteElementString("LocalName", "");
xw.WriteElementString("LocalPort", "1004");
xw.WriteEndElement();
xw.WriteStartElement("RootID");
xw.WriteElementString("RootSort", "WinServer");
xw.WriteElementString("RootName", "Root");
xw.WriteElementString("RootIP", "");
xw.WriteElementString("RootPort", "");
xw.WriteEndElement();
xw.WriteStartElement("Version");
xw.WriteElementString("ClientVersion", "Ver1.2");
xw.WriteEndElement();
xw.WriteEndElement();
xw.Flush();
xw.Close();
}
XmlDocument xd = new XmlDocument();
xd.Load(WC.varStr1 + "ClientConfig.xml");
string localSort = xd.SelectSingleNode("Config/LocalID/LocalSort").InnerText;
string localName = xd.SelectSingleNode("Config/LocalID/LocalName").InnerText;
string localIP = Dns.GetHostByName(Dns.GetHostName()).AddressList[0].ToString();
string localPort = xd.SelectSingleNode("Config/LocalID/LocalPort").InnerText;
string rootSort = xd.SelectSingleNode("Config/RootID/RootSort").InnerText;
string rootName = xd.SelectSingleNode("Config/RootID/RootName").InnerText;
string rootIP = xd.SelectSingleNode("Config/RootID/RootIP").InnerText;
string rootPort = xd.SelectSingleNode("Config/RootID/RootPort").InnerText;
clientVersion = xd.SelectSingleNode("Config/Version/ClientVersion").InnerText;
if (localName.Length == 0 || rootIP.Length == 0 || rootPort.Length == 0)
{
new WinConfig(this);
}
else
{
localID = WC.MakeLocalID(localSort, localName, localIP, localPort);
rootID = WC.MakeRootID(rootSort, rootName, rootIP, rootPort);
this.StartWinAccept();
}
}
private void SetConfigData()
{
XmlDocument xd = new XmlDocument();
xd.Load(new XmlTextReader(new StringReader(configData)));
string version = xd.SelectSingleNode("Config/Version/ClientVersion").InnerText;
if (version != clientVersion)
{
MessageBox.Show(this, WC.lineStr20 + version);
//System.Diagnostics.Process.Start("AicacaUpdate.exe", version);
this.ShutDown();
}
XmlNodeList xnl = xd.SelectNodes("Config/BoardList/Board");
for (IEnumerator ie = xnl.GetEnumerator() ; ie.MoveNext() ;)
{
XmlNode xn = ((XmlNode)ie.Current);
string[] strs = new string[2];
strs[0] = xn.SelectSingleNode("BoardName").InnerText;
strs[1] = xn.SelectSingleNode("BoardType").InnerText;
this.boardList.Items.Add(new ListViewItem(strs));
}
}
private void UpdateListBox()
{
int firstPos = -1;
this.clientList.Items.Clear();
while ((firstPos = clientAddr.IndexOf("<cid>", firstPos+1)) != -1)
{
string[] strs = new string[3];
strs[0] = WC.GetXML(clientAddr, "cn", firstPos);
strs[1] = WC.GetXML(clientAddr, "ci", firstPos);
strs[2] = WC.GetXML(clientAddr, "cp", firstPos);
this.clientList.Items.Add(new ListViewItem(strs));
}
}
private void SendSocketMsg(Socket sk, string str)
{
str = WC.ReplaceStr(str, "\n", "&Line;") + "\n";
if (sk != null && sk.Connected)
{
NetworkStream stream = new NetworkStream(sk);
TextWriter tempWriter = new StreamWriter(stream);
tempWriter.Write(str);
tempWriter.Flush();
}
}
private void AddChatText(string name, string str)
{
str = WC.ReplaceStr(str, "&Line;", "\n");
if (this.chatBox.Text.Length == 0)
{
this.chatBox.Text = "[" + name + "]\r\n" + str + "\r\n\r\n";
}
else
{
this.chatBox.AppendText("[" + name + "]\r\n" + str + "\r\n\r\n");
}
}
private void StartWinAccept()
{
xWinAccept = new WinAccept(this, localID, rootID);
Thread ServerThread = new Thread(new ThreadStart(xWinAccept.ServerProc));
ServerThread.Start();
}
private void StartWinBoard(string boardID, string boardName, string boardPassword, string boardType)
{
WinBoard xWinBoard = new WinBoard(this, localID, rootID, boardID, boardName, boardPassword, boardType);
Thread BoardThread = new Thread(new ThreadStart(xWinBoard.WinThread));
BoardThread.Start();
}
private void StartWinDialog_Connect(string clientID)
{
WinDialog xWinDialog = new WinDialog(this, localID, clientID);
Thread ClientThread = new Thread(new ThreadStart(xWinDialog.WinThread_Connect));
ClientThread.Start();
}
private void StartWinDialog_Accept(Socket sk, string clientID, string str)
{
WinDialog xWinDialog = new WinDialog(this, sk, localID, clientID, str);
Thread ClientThread = new Thread(new ThreadStart(xWinDialog.WinThread_Accept));
ClientThread.Start();
}
private void StartWinDialog_RoundMsg(string clientID, string str)
{
WinDialog xWinDialog = new WinDialog(this, localID, clientID, str);
Thread ClientThread = new Thread(new ThreadStart(xWinDialog.WinThread_RoundMsg));
ClientThread.Start();
}
private void StartWinReceive_Accept(Socket sk, string clientID, string str)
{
WinReceive xWinReceive = new WinReceive(this, sk, localID, clientID, str);
Thread ClientThread = new Thread(new ThreadStart(xWinReceive.WinThread_Accept));
ClientThread.Start();
}
private void StartWinReceive_RoundMsg(string clientID, string str)
{
WinReceive xWinReceive = new WinReceive(this, localID, clientID, str);
Thread ClientThread = new Thread(new ThreadStart(xWinReceive.WinThread_RoundMsg));
ClientThread.Start();
}
public void StartAll()
{
this.InitializeClient();
this.startMenu.Enabled = false;
this.startBtn.Enabled = false;
this.stopMenu.Enabled = true;
this.stopBtn.Enabled = true;
onTrayIcon.Visible = true;
offTrayIcon.Visible = false;
}
public void StopAll()
{
if (xWinAccept != null) xWinAccept.CloseThis();
if (xWinRoot != null) xWinRoot.CloseThis();
this.startMenu.Enabled = true;
this.startBtn.Enabled = true;
this.stopMenu.Enabled = false;
this.stopBtn.Enabled = false;
onTrayIcon.Visible = false;
offTrayIcon.Visible = true;
clientAddr = "";
this.chatBox.Text = "";
this.clientList.Items.Clear();
this.boardList.Items.Clear();
}
public void ShutDown()
{
shutFlag = true;
if (xWinAccept != null) xWinAccept.CloseThis();
if (xWinRoot != null) xWinRoot.CloseThis();
this.Close();
}
public void AddThread(string str, object o)
{
lock(this)
{
FormHash.Add(str, o);
}
}
public void RemoveThread(string str)
{
lock(this)
{
FormHash.Remove(str);
}
}
public bool CheckThread(string str)
{
lock(this)
{
if (FormHash.Contains(str))
{
return true;
}
else
{
return false;
}
}
}
public void SendRootMsg(string str)
{
lock(this)
{
str = WC.ReplaceStr(str, "\n", "&Line;") + "\n";
if (RootSocket != null && RootSocket.Connected)
{
SocketWriter.Write(str);
SocketWriter.Flush();
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -