コード例 #1
0
        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;
        }
コード例 #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();
 }
コード例 #3
0
 public NotificationEventArgs(Notification notification)
 {
     this.Notification = notification;
 }
コード例 #4
0
ファイル: Client.cs プロジェクト: SearchingFrog/warlock-demo
		public void Send(Notification value)
		{
			ServiceManager.Networker.SendOverStream(this.networkStream, value);
		}
コード例 #5
0
 public void SendNotification(Notification notification)
 {
     this.client.Send(notification);
 }
コード例 #6
0
ファイル: Server.cs プロジェクト: SearchingFrog/warlock-demo
		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());
			}
		}