public byte[] Serialize(Notification notification)
        {
            string asText = string.Format("{0} {1} ", (int)notification.Type, notification.ClientId);
            switch (notification.Type)
            {
                case NotificationType.Position :
                    Vector2 position = (Vector2) notification.Data;
                    asText += string.Format("{0} {1}", position.X, position.Y);
                    break;

                case NotificationType.SpellCast :
                    Spell spell = (Spell)notification.Data;
                    asText += string.Format("{0}", spell.Id);
                    break;

                case NotificationType.GameStarting:
                    int[] indices = (int[])notification.Data;
                    for (int i = 0; i < indices.Length; i++)
                    {
                        asText += string.Format("{0} ", indices[i]);
                    }
                    break;

                default:
                    asText += notification.Data;
                    break;
            };

            byte[] data = Encoding.GetBytes(asText);
            return data;
        }
Ejemplo n.º 2
0
 public void SendOverStream(Stream stream, Notification value)
 {
     byte[] data = ServiceManager.Serializer.Serialize(value);
     byte[] dataLength = BitConverter.GetBytes(data.Length);
     stream.Write(dataLength, 0, dataLength.Length);
     stream.Write(data, 0, data.Length);
     stream.FlushAsync();
 }
 public NotificationEventArgs(Notification notification)
 {
     this.Notification = notification;
 }
Ejemplo n.º 4
0
		public void Send(Notification value)
		{
			ServiceManager.Networker.SendOverStream(this.networkStream, value);
		}
Ejemplo n.º 5
0
 public void SendNotification(Notification notification)
 {
     this.client.Send(notification);
 }
Ejemplo n.º 6
0
		public void SendTo(int clientId, Notification message)
		{
			ClientInfo info = new ClientInfo(clientId);
			TcpClient client;
			if (this.Clients.TryGetValue(info, out client))
			{
				ServiceManager.Networker.SendOverStream(client.GetStream(), message);
				this.log.WriteDataSent(clientId, message.ToString());
			}
		}