added SendProfile

This commit is contained in:
Alexander Eckart committed 2013-05-09 23:14:04 +02:00
1 parent e70ce5ad68
commit 1a68c26e9f
8 files changed
+199 -51

No files matched your search

@@ -41,6 +41,9 @@ namespace Vocaluxe.Base.Server
public const int CommandSendAvatarPicture = 500;
public const int CommandSendAvatarPictureJpg = 501;
public const int CommandSendProfile = 510;
#endregion Commands
#region General
@@ -69,7 +72,7 @@ namespace Vocaluxe.Base.Server
#endregion Keyboard
#region Avatar
#region Profiles
public static byte[] CreateCommandSendAvatarPicture(int Width, int Height, byte[] data)
{
SAvatarPicture ap = new SAvatarPicture();
@@ -86,17 +89,39 @@ namespace Vocaluxe.Base.Server
return TryDeserialize<SAvatarPicture>(Message, out AvatarPicture);
}
public static byte[] CreateCommandSendAvatarPictureJpg(byte[] data)
public static byte[] CreateCommandSendAvatarPictureJpg(byte[] AvatarJpgData)
{
SAvatarPicture ap = new SAvatarPicture();
ap.Height = 0;
ap.Width = 0;
ap.data = new byte[data.Length];
Array.Copy(data, ap.data, data.Length);
ap.data = new byte[AvatarJpgData.Length];
Array.Copy(AvatarJpgData, ap.data, AvatarJpgData.Length);
return Serialize<SAvatarPicture>(CommandSendAvatarPictureJpg, ap);
}
#endregion Avatar
public static byte[] CreateCommandSendProfile(byte[] AvatarJpgData, string PlayerName, int Difficulty)
{
SAvatarPicture ap = new SAvatarPicture();
ap.Height = 0;
ap.Width = 0;
ap.data = new byte[AvatarJpgData.Length];
Array.Copy(AvatarJpgData, ap.data, AvatarJpgData.Length);
SProfile profile = new SProfile();
profile.Avatar = ap;
profile.PlayerName = PlayerName;
profile.Difficulty = Difficulty;
return Serialize<SProfile>(CommandSendProfile, profile);
}
public static bool DecodeCommandSendProfile(byte[] Message, out SProfile Profile)
{
return TryDeserialize<SProfile>(Message, out Profile);
}
#endregion Profiles
#region Serializing
private static byte[] Serialize<T>(int Command, T obj)
@@ -13,4 +13,11 @@ namespace Vocaluxe.Base.Server
public int Height;
public byte[] data;
}
public struct SProfile
{
public SAvatarPicture Avatar;
public string PlayerName;
public int Difficulty;
}
}
+14
View File
@@ -48,6 +48,7 @@
this.btUp = new System.Windows.Forms.Button();
this.btDown = new System.Windows.Forms.Button();
this.btSendAvatar = new System.Windows.Forms.Button();
this.btSendProfile = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
@@ -239,11 +240,23 @@
this.btSendAvatar.UseVisualStyleBackColor = true;
this.btSendAvatar.Click += new System.EventHandler(this.btSendAvatar_Click);
//
// btSendProfile
//
this.btSendProfile.Enabled = false;
this.btSendProfile.Location = new System.Drawing.Point(831, 339);
this.btSendProfile.Name = "btSendProfile";
this.btSendProfile.Size = new System.Drawing.Size(165, 23);
this.btSendProfile.TabIndex = 15;
this.btSendProfile.Text = "Send Profile";
this.btSendProfile.UseVisualStyleBackColor = true;
this.btSendProfile.Click += new System.EventHandler(this.btSendProfile_Click);
//
// ClientTest
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1008, 550);
this.Controls.Add(this.btSendProfile);
this.Controls.Add(this.btSendAvatar);
this.Controls.Add(this.btDown);
this.Controls.Add(this.btUp);
@@ -293,6 +306,7 @@
private System.Windows.Forms.Button btUp;
private System.Windows.Forms.Button btDown;
private System.Windows.Forms.Button btSendAvatar;
private System.Windows.Forms.Button btSendProfile;
}
}
+39 -1
View File
@@ -3,8 +3,11 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
@@ -119,6 +122,7 @@ namespace ClientTest
btLeft.Enabled = true;
btRight.Enabled = true;
btSendAvatar.Enabled = true;
btSendProfile.Enabled = true;
});
}
else
@@ -136,6 +140,7 @@ namespace ClientTest
btLeft.Enabled = false;
btRight.Enabled = false;
btSendAvatar.Enabled = false;
btSendProfile.Enabled = false;
});
}
}
@@ -222,7 +227,40 @@ namespace ClientTest
{
data[i] = (byte) (i % 255);
}
client.SendMessage(CCommands.CreateCommandSendAvatarPicture(512, 512, data), null);
client.SendMessage(CCommands.CreateCommandSendAvatarPicture(512, 512, data), OnResponse);
}
private void btSendProfile_Click(object sender, EventArgs e)
{
if (!client.Connected || !loggedIn)
return;
if (!File.Exists("test.jpg"))
{
byte[] data = new byte[512 * 512 * 4];
for (int i = 0; i < data.Length; i++)
{
data[i] = (byte)(i % 255);
}
Bitmap bmp = new Bitmap(512, 512);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
bmp.UnlockBits(bmpData);
bmp.Save("test.jpg", ImageFormat.Jpeg);
bmp.Dispose();
}
if (File.Exists("test.jpg"))
{
byte[] data = File.ReadAllBytes("test.jpg");
if (data == null)
return;
client.SendMessage(CCommands.CreateCommandSendProfile(data, "TestUser", 0), OnResponse);
}
}
}
}