HaoYueNet/Simple/Client-Cli/Program.cs

68 lines
1.9 KiB
C#
Raw Normal View History

2023-05-25 13:46:54 +08:00
using ClientCore;
2023-05-25 18:04:01 +08:00
using ClientCore.Event;
2023-06-02 18:24:54 +08:00
using System.Net;
using System.Net.Sockets;
2023-05-25 18:04:01 +08:00
2023-05-25 13:46:54 +08:00
App.Init("127.0.0.1", 23846);
2023-05-25 18:04:01 +08:00
//注册事件
EventSystem.Instance.RegisterEvent<string, string>(EEvent.OnChatMsg, OnChatMsg);
2023-05-25 13:46:54 +08:00
while (true)
{
string CommandStr = Console.ReadLine();
string Command = "";
Command = ((CommandStr.IndexOf(" ") <= 0) ? CommandStr : CommandStr.Substring(0, CommandStr.IndexOf(" ")));
string[] CmdArr = CommandStr.Split(' ');
switch (Command)
{
case "login":
case "l":
if (CmdArr.Length < 2)
{
Console.WriteLine("缺省用户名");
return;
}
App.login.Login(CmdArr[1]);
break;
case "say":
if (CmdArr.Length < 2)
{
Console.WriteLine("缺省参数");
return;
}
App.chat.SendChatMsg(CmdArr[1]);
break;
2023-12-14 18:15:04 +08:00
case "at":
//test
string guid = Guid.NewGuid().ToString();
App.login.Login(guid);
while (true)
{
if (!App.networkHelper.GetClientSocket().Connected)
return;
Thread.Sleep(10);
App.chat.SendChatMsg(guid);
}
//test end
break;
2023-06-02 18:24:54 +08:00
case "socket":
{
Socket socket = App.networkHelper.GetClientSocket();
if (socket == null)
return;
IPEndPoint endpoint = ((IPEndPoint)socket.LocalEndPoint);
Console.WriteLine($"LocalEndPoint IP->{endpoint.Address.ToString()} Port->{endpoint.Port}");
}
break;
2023-05-25 13:46:54 +08:00
default:
Console.WriteLine("未知命令" + CommandStr);
break;
}
}
void OnChatMsg(string str1, string str2)
{
Console.WriteLine($"[Chat]{str1}:{str2}");
}