public static void ConnectionThread(object state) { OPTIONS.init(); OPTIONS.Login.IncomingPacket += OnLoginPacket; OPTIONS.Chat.IncomingPacket += OnChatPaket; try { #if DEBUG OPTIONS.Connection = VaserClient.ConnectClient("localhost", 3100, OPTIONS.PColl); OPTIONS.Connection.Disconnecting += OnDisconnectingLink; #else OPTIONS.Connection = VaserClient.ConnectClient(tb_ServerAddress.Text, 3100, OPTIONS.PColl); OPTIONS.Connection.Disconnecting += OnDisconnectingLink; #endif } catch { Message msg = new Message(); msg.command = 2; //close msg.Messagedata = "Can't connect."; IncommingLogin.Enqueue(msg); ConnectingRunning = false; return; } SendL1.Username = Username; OPTIONS.Login.SendContainer(OPTIONS.Connection, SendL1, SEND_LOGIN.ContID, 0); ConnectingRunning = false; }
public static void Close() { OPTIONS.Connection.Dispose(); Message msg = new Message(); msg.command = 2; //close msg.Messagedata = "Closed."; IncommingLogin.Enqueue(msg); }
public static void OnDisconnectingLink(object sender, LinkEventArgs e) { //MessageBox.Show("Lost Connection..."); if (OPTIONS.clientID != 0) { OPTIONS.clientID = 0; Message msg = new Message(); msg.command = 2; //close msg.Messagedata = "Lost connection."; IncommingLogin.Enqueue(msg); } }
private static void OnChatPaket(object sender, PacketEventArgs e) { switch (e.pak.ContainerID) { case SEND_MESSAGE.ContID: Debug.WriteLine("SEND_MESSAGE Packet"); if (SendM1.UnpackContainer(e.pak, OPTIONS.Chat)) { Message msg = new Message(); msg.command = 10; // message msg.UserID = SendM1.UserID; msg.Messagedata = SendM1.Message; msg.Username = msg.UserID.ToString(); try { msg.Username = ClientArray[msg.UserID].Username; } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } IncommingChat.Enqueue(msg); } break; case SEND_USER.ContID: Debug.WriteLine("SEND_USER Packet"); if (SendU1.UnpackContainer(e.pak, OPTIONS.Chat)) { int statID = SendU1.StatusID; if (statID == STATUS.USER_NEW) { uint ID = SendU1.UserID; string Username = SendU1.Username; Client c = new Client(); c.Username = Username; c.ID = ID; ClientArray[ID] = c; Message msg = new Message(); msg.command = 11; // new msg.cli = c; msg.UserID = SendU1.UserID; msg.Username = SendU1.Username; msg.Messagedata = "new client '" + c.Username + "' connected."; IncommingChat.Enqueue(msg); Debug.WriteLine("New User: "******" ID: " + c.ID); } if (statID == STATUS.USER_DISCONNECT) { uint ID = SendU1.UserID; try { Client c = ClientArray[ID]; Message msg = new Message(); msg.command = 12; // Delete msg.Messagedata = "Client '" + c.Username + "' disconnected."; msg.cli = c; IncommingChat.Enqueue(msg); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } } break; } }
public static void OnLoginPacket(object sender, PacketEventArgs e) { if (e.pak.ContainerID == 1) { OPTIONS.clientID = e.pak.ObjectID; Message msg = new Message(); msg.command = 1; //open IncommingLogin.Enqueue(msg); } }