private void RestClient_GotUserPacket(object sender, PacketEventArgs e) { if (e.packet.ID.Equals(this.myID)) { //Ignore my own packets... return; } UserPacket upkt = (UserPacket)e.packet; RadioID to = upkt.Destination; if (activeCalls.ContainsKey(to)) { //Console.WriteLine("Appending to active call..."); activeCalls[to].AppendPkt(upkt); } else { //Console.WriteLine("Creating new call..."); if (upkt.PacketType == PacketType.GroupDataCall || upkt.PacketType == PacketType.PrivateDataCall) { activeCalls[to] = new DataCall(upkt); } else { activeCalls[to] = new AudioCall(upkt); } } if (activeCalls[to].IsEnded) { this.GotRestCall?.Invoke(this, new CallEventArgs(activeCalls[to])); activeCalls.Remove(to); } }
protected void FireUserPacket(Packet pkt, System.Net.IPEndPoint ep) { if (this.GotUserPacket != null) { PacketEventArgs e = new PacketEventArgs(pkt, ep); this.GotUserPacket(this, e); } UserPacket upkt = (UserPacket)pkt; RadioID to = upkt.Destination; if (activeCalls.ContainsKey(to)) { //Console.WriteLine("Appending to active call..."); activeCalls[to].AppendPkt(upkt); } else { //Console.WriteLine("Creating new call..."); if (upkt.PacketType == PacketType.GroupDataCall || upkt.PacketType == PacketType.PrivateDataCall) { activeCalls[to] = new DataCall(upkt); } else { activeCalls[to] = new AudioCall(upkt); } } if (activeCalls[to].IsEnded) { this.GotUserCall?.Invoke(this, new CallEventArgs(activeCalls[to])); activeCalls.Remove(to); } }
public AudioCall(UserPacket pkt) : base(pkt) { if (this.IsAudio == false) { throw new ArgumentException("Cannot process data packets as AudioCall"); } }
public DataCall(UserPacket pkt) : base(pkt) { if (this.IsAudio == true) { throw new ArgumentException("Cannot process audio packets as DataCall"); } }
public void AppendPkt(UserPacket upkt) { this.bursts.Add(upkt.Burst); this.isEnded = upkt.End; if (upkt.End) { this.endTime = DateTime.Now; } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (txtNick.Text != null) { UserPacket user = new UserPacket(txtNick.Text, comboBox1.Text); client.SendMessage(user); ServerMessagePacket server = new ServerMessagePacket(txtNick.Text + " is now " + comboBox1.Text + "."); client.SendMessage(server); } }
public async void EnqueuePacket(UserPacket packet) { _commandProcessor.Enqueue(packet); if (Interlocked.CompareExchange(ref _executeTask, null, null) == null) { _executeTask = Task.Factory.StartNew(ExecutePackets); await _executeTask; _executeTask = null; } }
private void btnNick_Click_1(object sender, EventArgs e) { //NickNamePacket nickname = new NickNamePacket(txtNick.Text); UserPacket user = new UserPacket(txtNick.Text, "Online"); client.SendMessage(user); ServerMessagePacket message = new ServerMessagePacket(txtNick.Text + " has joined the chat."); client.SendMessage(message); txtNick.Enabled = false; btnNick.Enabled = false; btnSend.Enabled = true; }
protected RadioCall(UserPacket upkt) { this.startTime = DateTime.Now; this.bursts = new List <Burst>() { upkt.Burst }; this.isGroupCall = (upkt.PacketType == PacketType.GroupDataCall || upkt.PacketType == PacketType.GroupVoiceCall); this.isAudio = (upkt.PacketType == PacketType.PrivateVoiceCall || upkt.PacketType == PacketType.GroupVoiceCall); this.from = upkt.Source; this.to = upkt.Destination; this.isEncrypted = upkt.Encrypted; this.isEnded = upkt.End; this.isPhoneCall = upkt.PhoneCall; this.groupTag = upkt.GroupTag; }
public UserPacket[] ToPackets(RadioID initiator) { UserPacket[] ret = new UserPacket[this.bursts.Count]; for (int i = 0; i < ret.Length; i++) { if (i > 0) { //Make sure we get different timestamps... Thread.Sleep(1); } UserPacket pkt = new UserPacket(initiator, !this.isAudio, this.isGroupCall, this.from, this.to, this.isEncrypted, this.isPhoneCall, this.groupTag, this.bursts[i]); ret[i] = pkt; } ret[ret.Length - 1].End = true; return(ret); }
internal void AddPacket(UserPacket userPacket) { if (userPacket != null) { System.Action<UserPacket> @event = null; if (eventDic.TryGetValue(userPacket.msgid, out @event)) { @event(userPacket); } else { if (OnUserPacketEvent != null) { OnUserPacketEvent(userPacket); } } } }
internal void Write(SocketAsyncEventArgs e) { try { readStream.Write(e.Buffer, e.Offset, e.BytesTransferred); while (readStream.Length >= headSize) { if (userPacket == null) { userPacket = new UserPacket(); userPacket.server = netServer; userPacket.netUser = this; readStream.Position = 0; readStream.Read(headDataOnce, 0, headSize); readStream.Position = readStream.Length; userPacket.size = BitConverter.ToUInt32(headDataOnce, 4); userPacket.msgid = BitConverter.ToInt32(headDataOnce, 0); } if (userPacket.size <= readStream.Length) { userPacket.msgData = new byte[userPacket.size - headSize]; readStream.Position = headSize; readStream.Read(userPacket.msgData, 0, userPacket.msgData.Length); byte[] datalist = new byte[readStream.Length - readStream.Position]; readStream.Read(datalist, 0, datalist.Length); readStream.SetLength(0); readStream.Write(datalist, 0, datalist.Length); UserPacket userPacket1 = userPacket; userPacket = null; netServer.AddPacket(userPacket1); } } } catch (Exception ex) { Debug(ex.Message + " " + ex.StackTrace + " " + userPacket.size + " " + headSize); } }
public void Enqueue(UserPacket msg) { _packets.Enqueue(msg); }
public bool TryDequeue(out UserPacket result) { return(_packets.TryDequeue(out result)); }