blub
This commit is contained in:
parent
85b028e3e7
commit
edae7a075a
@ -215,23 +215,8 @@ namespace RageCoop.Client
|
||||
_lastDead=P.IsDead;
|
||||
Ticked++;
|
||||
}
|
||||
private bool recording = false;
|
||||
private void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.B)
|
||||
{
|
||||
if (!recording)
|
||||
{
|
||||
recording = true;
|
||||
Sync.Voice.StartRecording();
|
||||
}
|
||||
else
|
||||
{
|
||||
Sync.Voice.StopRecording();
|
||||
recording = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (MainChat.Focused)
|
||||
{
|
||||
MainChat.OnKeyDown(e.KeyCode);
|
||||
@ -239,6 +224,16 @@ namespace RageCoop.Client
|
||||
}
|
||||
if (Networking.IsOnServer)
|
||||
{
|
||||
if (Game.IsControlPressed(GTA.Control.PushToTalk))
|
||||
{
|
||||
Sync.Voice.StartRecording();
|
||||
return;
|
||||
}
|
||||
else if (Sync.Voice.IsRecording)
|
||||
{
|
||||
Sync.Voice.StopRecording();
|
||||
}
|
||||
|
||||
if (Game.IsControlPressed(GTA.Control.FrontendPause))
|
||||
{
|
||||
Function.Call(Hash.ACTIVATE_FRONTEND_MENU, Function.Call<int>(Hash.GET_HASH_KEY, "FE_MENU_VERSION_SP_PAUSE"), false, 0);
|
||||
|
@ -248,6 +248,12 @@ namespace RageCoop.Client
|
||||
}
|
||||
break;
|
||||
|
||||
case PacketType.Voice:
|
||||
{
|
||||
GTA.UI.Notification.Show("VOICE RECEIVED!");
|
||||
}
|
||||
break;
|
||||
|
||||
case PacketType.CustomEvent:
|
||||
{
|
||||
Packets.CustomEvent packet = new Packets.CustomEvent(_resolveHandle);
|
||||
|
@ -173,5 +173,9 @@ namespace RageCoop.Client
|
||||
{ Username = Main.Settings.Username, Message = message },ServerConnection, ConnectionChannel.Chat, NetDeliveryMethod.ReliableOrdered);
|
||||
Peer.FlushSendQueue();
|
||||
}
|
||||
public static void SendVoiceMessage(byte[] buffer)
|
||||
{
|
||||
SendSync(new Packets.Voice() { Buffer = buffer }, ConnectionChannel.Voice, NetDeliveryMethod.ReliableOrdered);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ namespace RageCoop.Client.Sync
|
||||
{
|
||||
internal static class Voice
|
||||
{
|
||||
public static bool IsRecording = false;
|
||||
|
||||
private static WaveInEvent _waveIn;
|
||||
private static BufferedWaveProvider _waveProvider = new BufferedWaveProvider(new WaveFormat(16000, 16, 1));
|
||||
|
||||
@ -16,6 +18,9 @@ namespace RageCoop.Client.Sync
|
||||
|
||||
public static void StopRecording()
|
||||
{
|
||||
if (!IsRecording)
|
||||
return;
|
||||
|
||||
_waveIn.StopRecording();
|
||||
GTA.UI.Notification.Show("STOPPED [1]");
|
||||
}
|
||||
@ -49,11 +54,19 @@ namespace RageCoop.Client.Sync
|
||||
WaveFormat = _waveProvider.WaveFormat
|
||||
};
|
||||
_waveIn.DataAvailable += WaveInDataAvailable;
|
||||
_waveIn.RecordingStopped += (object sender, StoppedEventArgs e) =>
|
||||
{
|
||||
IsRecording = false;
|
||||
};
|
||||
GTA.UI.Notification.Show("INIT");
|
||||
}
|
||||
|
||||
public static void StartRecording()
|
||||
{
|
||||
if (IsRecording)
|
||||
return;
|
||||
|
||||
IsRecording = true;
|
||||
_waveIn.StartRecording();
|
||||
GTA.UI.Notification.Show("STARTED");
|
||||
}
|
||||
@ -66,6 +79,7 @@ namespace RageCoop.Client.Sync
|
||||
try
|
||||
{
|
||||
_waveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
|
||||
Networking.SendVoiceMessage(e.Buffer);
|
||||
} catch (Exception ex)
|
||||
{
|
||||
// if some happens along the way...
|
||||
|
@ -34,10 +34,13 @@ namespace RageCoop.Core
|
||||
P2PConnect = 19,
|
||||
HolePunchInit=20,
|
||||
HolePunch=21,
|
||||
|
||||
Voice = 22,
|
||||
|
||||
#region Sync
|
||||
PedSync = 22,
|
||||
VehicleSync = 23,
|
||||
ProjectileSync =24,
|
||||
PedSync = 23,
|
||||
VehicleSync = 24,
|
||||
ProjectileSync =25,
|
||||
#endregion
|
||||
|
||||
#region EVENT
|
||||
@ -66,17 +69,18 @@ namespace RageCoop.Core
|
||||
internal enum ConnectionChannel
|
||||
{
|
||||
Default = 0,
|
||||
Chat = 5,
|
||||
Native = 6,
|
||||
Mod = 7,
|
||||
File = 8,
|
||||
Event = 9,
|
||||
RequestResponse=10,
|
||||
PingPong = 11,
|
||||
VehicleSync =20,
|
||||
PedSync=21,
|
||||
ProjectileSync = 22,
|
||||
SyncEvents =30,
|
||||
Chat = 1,
|
||||
Voice = 2,
|
||||
Native = 3,
|
||||
Mod = 4,
|
||||
File = 5,
|
||||
Event = 6,
|
||||
RequestResponse=7,
|
||||
PingPong = 8,
|
||||
VehicleSync = 9,
|
||||
PedSync= 10,
|
||||
ProjectileSync = 11,
|
||||
SyncEvents = 12,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
|
24
RageCoop.Core/Packets/Voice.cs
Normal file
24
RageCoop.Core/Packets/Voice.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RageCoop.Core
|
||||
{
|
||||
internal partial class Packets
|
||||
{
|
||||
internal class Voice : Packet
|
||||
{
|
||||
public byte[] Buffer { get; set; }
|
||||
public override PacketType Type => PacketType.Voice;
|
||||
public override byte[] Serialize()
|
||||
{
|
||||
var data = new List<byte>();
|
||||
data.AddArray(Buffer);
|
||||
return data.ToArray();
|
||||
}
|
||||
public override void Deserialize(byte[] array)
|
||||
{
|
||||
var reader = new BitReader(array);
|
||||
Buffer = reader.ReadByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -484,6 +484,15 @@ namespace RageCoop.Server
|
||||
}
|
||||
break;
|
||||
|
||||
case PacketType.Voice:
|
||||
{
|
||||
var msg = MainNetServer.CreateMessage();
|
||||
Packets.Voice packet = data.GetPacket<Packets.Voice>();
|
||||
packet.Deserialize(data);
|
||||
MainNetServer.SendMessage(msg, MainNetServer.Connections, NetDeliveryMethod.ReliableOrdered, (int)ConnectionChannel.Voice);
|
||||
}
|
||||
break;
|
||||
|
||||
case PacketType.CustomEvent:
|
||||
{
|
||||
Packets.CustomEvent packet = new Packets.CustomEvent();
|
||||
|
Loading…
x
Reference in New Issue
Block a user