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
+189 -41

No files matched your search

@@ -41,6 +41,9 @@ namespace Vocaluxe.Base.Server
public const int CommandSendAvatarPicture = 500; public const int CommandSendAvatarPicture = 500;
public const int CommandSendAvatarPictureJpg = 501; public const int CommandSendAvatarPictureJpg = 501;
public const int CommandSendProfile = 510;
#endregion Commands #endregion Commands
#region General #region General
@@ -69,7 +72,7 @@ namespace Vocaluxe.Base.Server
#endregion Keyboard #endregion Keyboard
#region Avatar #region Profiles
public static byte[] CreateCommandSendAvatarPicture(int Width, int Height, byte[] data) public static byte[] CreateCommandSendAvatarPicture(int Width, int Height, byte[] data)
{ {
SAvatarPicture ap = new SAvatarPicture(); SAvatarPicture ap = new SAvatarPicture();
@@ -86,17 +89,39 @@ namespace Vocaluxe.Base.Server
return TryDeserialize<SAvatarPicture>(Message, out AvatarPicture); return TryDeserialize<SAvatarPicture>(Message, out AvatarPicture);
} }
public static byte[] CreateCommandSendAvatarPictureJpg(byte[] data) public static byte[] CreateCommandSendAvatarPictureJpg(byte[] AvatarJpgData)
{ {
SAvatarPicture ap = new SAvatarPicture(); SAvatarPicture ap = new SAvatarPicture();
ap.Height = 0; ap.Height = 0;
ap.Width = 0; ap.Width = 0;
ap.data = new byte[data.Length]; ap.data = new byte[AvatarJpgData.Length];
Array.Copy(data, ap.data, data.Length); Array.Copy(AvatarJpgData, ap.data, AvatarJpgData.Length);
return Serialize<SAvatarPicture>(CommandSendAvatarPictureJpg, ap); 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 #region Serializing
private static byte[] Serialize<T>(int Command, T obj) private static byte[] Serialize<T>(int Command, T obj)
@@ -13,4 +13,11 @@ namespace Vocaluxe.Base.Server
public int Height; public int Height;
public byte[] data; 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.btUp = new System.Windows.Forms.Button();
this.btDown = new System.Windows.Forms.Button(); this.btDown = new System.Windows.Forms.Button();
this.btSendAvatar = new System.Windows.Forms.Button(); this.btSendAvatar = new System.Windows.Forms.Button();
this.btSendProfile = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@@ -239,11 +240,23 @@
this.btSendAvatar.UseVisualStyleBackColor = true; this.btSendAvatar.UseVisualStyleBackColor = true;
this.btSendAvatar.Click += new System.EventHandler(this.btSendAvatar_Click); 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 // ClientTest
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1008, 550); this.ClientSize = new System.Drawing.Size(1008, 550);
this.Controls.Add(this.btSendProfile);
this.Controls.Add(this.btSendAvatar); this.Controls.Add(this.btSendAvatar);
this.Controls.Add(this.btDown); this.Controls.Add(this.btDown);
this.Controls.Add(this.btUp); this.Controls.Add(this.btUp);
@@ -293,6 +306,7 @@
private System.Windows.Forms.Button btUp; private System.Windows.Forms.Button btUp;
private System.Windows.Forms.Button btDown; private System.Windows.Forms.Button btDown;
private System.Windows.Forms.Button btSendAvatar; 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.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.IO;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
@@ -119,6 +122,7 @@ namespace ClientTest
btLeft.Enabled = true; btLeft.Enabled = true;
btRight.Enabled = true; btRight.Enabled = true;
btSendAvatar.Enabled = true; btSendAvatar.Enabled = true;
btSendProfile.Enabled = true;
}); });
} }
else else
@@ -136,6 +140,7 @@ namespace ClientTest
btLeft.Enabled = false; btLeft.Enabled = false;
btRight.Enabled = false; btRight.Enabled = false;
btSendAvatar.Enabled = false; btSendAvatar.Enabled = false;
btSendProfile.Enabled = false;
}); });
} }
} }
@@ -222,7 +227,40 @@ namespace ClientTest
{ {
data[i] = (byte) (i % 255); 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; break;
change.Profile.ID = _ProfileIDs.Dequeue(); change.Profile.ID = _ProfileIDs.Dequeue();
change.Profile.Avatar = _GetAvatar(change.Profile.AvatarFileName);
_Profiles.Add(change.Profile.ID, change.Profile); _Profiles.Add(change.Profile.ID, change.Profile);
_ProfilesChanged = true; _ProfilesChanged = true;
break; break;
@@ -668,9 +670,11 @@ namespace Vocaluxe.Base
private static CAvatar _GetAvatar(string fileName) private static CAvatar _GetAvatar(string fileName)
{ {
string Name = Path.GetFileName(fileName);
foreach (int id in _Avatars.Keys) foreach (int id in _Avatars.Keys)
{ {
if (Path.GetFileName(_Avatars[id].FileName) == fileName) if (Path.GetFileName(_Avatars[id].FileName) == Name)
return _Avatars[id]; return _Avatars[id];
} }
return new CAvatar(-1); return new CAvatar(-1);
+48 -16
View File
@@ -149,7 +149,49 @@ namespace Vocaluxe.Base.Server
SAvatarPicture avatarPictureJpg; SAvatarPicture avatarPictureJpg;
if (CCommands.DecodeCommandSendAvatarPicture(Message, out avatarPictureJpg)) if (CCommands.DecodeCommandSendAvatarPicture(Message, out avatarPictureJpg))
{ {
bool success = false; 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 try
{ {
string filename = Path.Combine(CSettings.FolderProfiles, "snapshot"); string filename = Path.Combine(CSettings.FolderProfiles, "snapshot");
@@ -159,31 +201,21 @@ namespace Vocaluxe.Base.Server
filename = filename + i + ".jpg"; filename = filename + i + ".jpg";
FileStream fs = File.Create(filename); FileStream fs = File.Create(filename);
fs.Write(avatarPictureJpg.data, 0, avatarPictureJpg.data.Length); fs.Write(JpgData, 0, JpgData.Length);
fs.Flush(); fs.Flush();
fs.Close(); fs.Close();
CAvatar avatar = new CAvatar(-1); CAvatar avatar = new CAvatar(-1);
success = avatar.LoadFromFile(filename); if (avatar.LoadFromFile(filename))
if (success)
{ {
CProfiles.AddAvatar(avatar); CProfiles.AddAvatar(avatar);
result = filename;
} }
} }
catch {} catch { }
if (success) return result;
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
}
break;
default:
break;
}
return answer;
} }
} }
} }
+46 -18
View File
@@ -62,7 +62,10 @@ namespace Vocaluxe.Screens
private int _SelectingSwitchNr = -1; private int _SelectingSwitchNr = -1;
private int _SelectingFastPlayerNr = 0; private int _SelectingFastPlayerNr = 0;
private int _SelectedPlayerNr = -1; private int _SelectedPlayerNr = -1;
private bool _AvatarsChanged = false;
private bool _ProfilesChanged = false;
#region public methods
public override void Init() public override void Init()
{ {
base.Init(); base.Init();
@@ -100,6 +103,8 @@ namespace Vocaluxe.Screens
_ChooseAvatarStatic = GetNewStatic(); _ChooseAvatarStatic = GetNewStatic();
_ChooseAvatarStatic.Visible = false; _ChooseAvatarStatic.Visible = false;
CProfiles.AddProfileChangedCallback(new ProfileChangedCallback(_OnProfileChanged));
} }
public override void LoadTheme(string xmlPath) public override void LoadTheme(string xmlPath)
@@ -619,6 +624,9 @@ namespace Vocaluxe.Screens
public override bool UpdateGame() public override bool UpdateGame()
{ {
if (_ProfilesChanged || _AvatarsChanged)
_LoadProfiles();
for (int i = 1; i <= CGame.NumPlayer; i++) for (int i = 1; i <= CGame.NumPlayer; i++)
{ {
CSound.AnalyzeBuffer(i - 1); CSound.AnalyzeBuffer(i - 1);
@@ -633,6 +641,41 @@ namespace Vocaluxe.Screens
CSound.RecordStart(); CSound.RecordStart();
_NameSelections[_NameSelection].Init(); _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(); _UpdateSlides();
_UpdatePlayerNumber(); _UpdatePlayerNumber();
@@ -657,24 +700,8 @@ namespace Vocaluxe.Screens
_SelectSlides[_SelectSlideDuetPlayer[i]].Visible = false; _SelectSlides[_SelectSlideDuetPlayer[i]].Visible = false;
} }
_SetInteractionToButton(_Buttons[_ButtonStart]); _ProfilesChanged = false;
} _AvatarsChanged = false;
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;
} }
private void _StartSong() private void _StartSong()
@@ -818,5 +845,6 @@ namespace Vocaluxe.Screens
_Texts[_TextWarningProfiles].Visible = false; _Texts[_TextWarningProfiles].Visible = false;
} }
} }
#endregion private methods
} }
} }