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);
}
}
}
}
Binary file not shown.
+5 -1
View File
@@ -133,7 +133,9 @@ namespace Vocaluxe.Base
break;
change.Profile.ID = _ProfileIDs.Dequeue();
change.Profile.Avatar = _GetAvatar(change.Profile.AvatarFileName);
_Profiles.Add(change.Profile.ID, change.Profile);
_ProfilesChanged = true;
break;
@@ -668,9 +670,11 @@ namespace Vocaluxe.Base
private static CAvatar _GetAvatar(string fileName)
{
string Name = Path.GetFileName(fileName);
foreach (int id in _Avatars.Keys)
{
if (Path.GetFileName(_Avatars[id].FileName) == fileName)
if (Path.GetFileName(_Avatars[id].FileName) == Name)
return _Avatars[id];
}
return new CAvatar(-1);
+58 -26
View File
@@ -149,41 +149,73 @@ namespace Vocaluxe.Base.Server
SAvatarPicture avatarPictureJpg;
if (CCommands.DecodeCommandSendAvatarPicture(Message, out avatarPictureJpg))
{
bool success = false;
try
{
string filename = Path.Combine(CSettings.FolderProfiles, "snapshot");
int i = 0;
while (File.Exists(filename + i + ".jpg"))
i++;
filename = filename + i + ".jpg";
FileStream fs = File.Create(filename);
fs.Write(avatarPictureJpg.data, 0, avatarPictureJpg.data.Length);
fs.Flush();
fs.Close();
CAvatar avatar = new CAvatar(-1);
success = avatar.LoadFromFile(filename);
if (success)
{
CProfiles.AddAvatar(avatar);
}
}
catch {}
if (success)
if (_AddAvatar(avatarPictureJpg.data) != String.Empty)
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
}
break;
case CCommands.CommandSendProfile:
SProfile profile;
if (CCommands.DecodeCommandSendProfile(Message, out profile))
{
try
{
string AvatarFilename = _AddAvatar(profile.Avatar.data);
if (AvatarFilename != String.Empty)
{
CProfile p = new CProfile();
p.Active = EOffOn.TR_CONFIG_ON;
p.AvatarFileName = AvatarFilename;
p.Difficulty = (EGameDifficulty)profile.Difficulty;
p.GuestProfile = EOffOn.TR_CONFIG_OFF;
p.PlayerName = profile.PlayerName;
p.SaveProfile();
CProfiles.AddProfile(p);
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
}
}
catch (Exception)
{
}
}
break;
default:
break;
}
return answer;
}
private static string _AddAvatar(byte[] JpgData)
{
string result = String.Empty;
try
{
string filename = Path.Combine(CSettings.FolderProfiles, "snapshot");
int i = 0;
while (File.Exists(filename + i + ".jpg"))
i++;
filename = filename + i + ".jpg";
FileStream fs = File.Create(filename);
fs.Write(JpgData, 0, JpgData.Length);
fs.Flush();
fs.Close();
CAvatar avatar = new CAvatar(-1);
if (avatar.LoadFromFile(filename))
{
CProfiles.AddAvatar(avatar);
result = filename;
}
}
catch { }
return result;
}
}
}
+46 -18
View File
@@ -62,7 +62,10 @@ namespace Vocaluxe.Screens
private int _SelectingSwitchNr = -1;
private int _SelectingFastPlayerNr = 0;
private int _SelectedPlayerNr = -1;
private bool _AvatarsChanged = false;
private bool _ProfilesChanged = false;
#region public methods
public override void Init()
{
base.Init();
@@ -100,6 +103,8 @@ namespace Vocaluxe.Screens
_ChooseAvatarStatic = GetNewStatic();
_ChooseAvatarStatic.Visible = false;
CProfiles.AddProfileChangedCallback(new ProfileChangedCallback(_OnProfileChanged));
}
public override void LoadTheme(string xmlPath)
@@ -619,6 +624,9 @@ namespace Vocaluxe.Screens
public override bool UpdateGame()
{
if (_ProfilesChanged || _AvatarsChanged)
_LoadProfiles();
for (int i = 1; i <= CGame.NumPlayer; i++)
{
CSound.AnalyzeBuffer(i - 1);
@@ -633,6 +641,41 @@ namespace Vocaluxe.Screens
CSound.RecordStart();
_NameSelections[_NameSelection].Init();
_LoadProfiles();
_SetInteractionToButton(_Buttons[_ButtonStart]);
}
public override void OnClose()
{
base.OnClose();
CSound.RecordStop();
}
public override bool Draw()
{
base.Draw();
if (_ChooseAvatarStatic.Visible)
_ChooseAvatarStatic.Draw();
for (int i = 1; i <= CGame.NumPlayer; i++)
_Equalizers["EqualizerPlayer" + i].Draw();
return true;
}
#endregion public methods
#region private methods
private void _OnProfileChanged(EProfileChangedFlags Flags)
{
if (EProfileChangedFlags.Avatar == (EProfileChangedFlags.Avatar & Flags))
_AvatarsChanged = true;
if (EProfileChangedFlags.Profile == (EProfileChangedFlags.Profile & Flags))
_ProfilesChanged = true;
}
private void _LoadProfiles()
{
_NameSelections[_NameSelection].UpdateList();
_UpdateSlides();
_UpdatePlayerNumber();
@@ -657,24 +700,8 @@ namespace Vocaluxe.Screens
_SelectSlides[_SelectSlideDuetPlayer[i]].Visible = false;
}
_SetInteractionToButton(_Buttons[_ButtonStart]);
}
public override void OnClose()
{
base.OnClose();
CSound.RecordStop();
}
public override bool Draw()
{
base.Draw();
if (_ChooseAvatarStatic.Visible)
_ChooseAvatarStatic.Draw();
for (int i = 1; i <= CGame.NumPlayer; i++)
_Equalizers["EqualizerPlayer" + i].Draw();
return true;
_ProfilesChanged = false;
_AvatarsChanged = false;
}
private void _StartSong()
@@ -818,5 +845,6 @@ namespace Vocaluxe.Screens
_Texts[_TextWarningProfiles].Visible = false;
}
}
#endregion private methods
}
}