Example #1
0
 public void SendMessage(TransportContainer msg)
 {
     if (this.CurrentRoom != null)
     {
         msg.Room = this.CurrentRoom.GetGameRoomInfo();
         msg.User = this.Gamer;
         Sender.SendMessage(msg);
     }
 }
Example #2
0
 public void SendMessage(TransportContainer msg)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         var data = Encoding.UTF8.GetBytes(msg.UTFSerialize());
         ms.Write(data, 0, data.Length);
         this.Sock.Send(ms.ToArray());
     }
 }
Example #3
0
        private void AfterRecieve(IAsyncResult ar)
        {
            Abonent ab = (Abonent)ar.AsyncState;

                try
                {
                    ab.Sender.EndReceive(ar);
                    if (ab.Status != AbonentStatusEnum.Disconnected)
                    {

                            try
                            {
                                string utf8 = Encoding.UTF8.GetString(ab.Sender.buffer);

                                char[] removed = new char[1];
                                removed[0] = (char)0;
                                utf8 = utf8.Trim(removed);

                                TransportContainer msg = new TransportContainer();
                                msg.UTFDeSerialize(utf8);
                                switch (msg.Type)
                                {
                                    case TCTypes.AbonentCommand:
                                        {
                                            AbonentsCommandMessage acmsg = (AbonentsCommandMessage)msg.GetInnerMessage();
                                            AfterRecieveCommand(acmsg, ab);
                                            break;
                                        }
                                }
                            }
                            catch (Exception ex)
                            {

                            }
                            ab.Sender.ClearBuffer();
                            if (this.AbnsToList().Contains(ab))
                            {
                                ab.Sender.ClearBuffer();
                                ab.Sender.BeginReceive( new AsyncCallback(AfterRecieve), ab);
                                return;
                            }

                    }
                }
                catch
                {

                    ab.Status = AbonentStatusEnum.Disconnected;
                    ab.Gamer.Name = String.Empty;
                    ab.Gamer.Id = 0;
                }
                try
                {
                    if (ab.Status == AbonentStatusEnum.Disconnected)
                    {
                        ab.Sender.Close();
                        RemoveAbonent(ab);
                        if (ab.Gamer.Id == this.Owner.Id)
                            AfterRemoveOwner();
                        this.SendRoomStatusMessage();
                    }
                }
                catch { }
        }
Example #4
0
 public void SendMessage(TransportContainer msg)
 {
     msg.Room = this.GetGameRoomInfo();
     foreach (var abn in AbnsToList())
     {
         abn.SendMessage(msg);
     }
 }