You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
using Core;
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
|
|
|
namespace Client
|
|
|
|
{
|
|
|
|
public partial class LoginForm : Form
|
|
|
|
{
|
|
|
|
public LoginForm()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
InitInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void InitInstance()
|
|
|
|
{
|
|
|
|
Singleton.Instance.LoginResponsed += LoginResponsed;
|
|
|
|
FormClosing += LoginForm_FormClosing;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LoginForm_FormClosing(object? sender, FormClosingEventArgs e)
|
|
|
|
{
|
|
|
|
Singleton.Instance.LoginResponsed -= LoginResponsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async void btnLogin_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
string id = tbxId.Text;
|
|
|
|
string nickname = tbxNickname.Text;
|
|
|
|
if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(nickname))
|
|
|
|
{
|
|
|
|
MessageBox.Show("Please input ID and Nickname.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await Singleton.Instance.ConnectAsync("127.0.0.1", 20000);
|
|
|
|
|
|
|
|
Singleton.Instance.Id = id;
|
|
|
|
Singleton.Instance.Nickname = nickname;
|
|
|
|
|
|
|
|
LoginRequestPacket packet = new LoginRequestPacket(id, nickname);
|
|
|
|
await Singleton.Instance.SendAsync(packet.Serialize(), SocketFlags.None);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LoginResponsed(object? sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (sender == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LoginResponsePacket packet = (LoginResponsePacket)sender;
|
|
|
|
MessageBox.Show(packet.Code.ToString());
|
|
|
|
if (packet.Code != StatusCode.Success)
|
|
|
|
{
|
|
|
|
RoomListForm roomListForm = new RoomListForm();
|
|
|
|
roomListForm.ShowDialog();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Singleton.Instance.Socket.Shutdown(SocketShutdown.Send);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|