mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 21:02:55 +08:00
Merge branch 'master' into set-busy-timeout
This commit is contained in:
commit
c8cad6d9aa
@ -1 +1 @@
|
|||||||
Subproject commit e1352a8b0b5d1ba8acd9335a56c714d2ccc2f6a6
|
Subproject commit 5f3a7fe4d0537820a33b817a41623b4b22a3ec59
|
@ -49,7 +49,7 @@ namespace osu.Game.IO.Legacy
|
|||||||
int len = ReadInt32();
|
int len = ReadInt32();
|
||||||
if (len > 0) return ReadBytes(len);
|
if (len > 0) return ReadBytes(len);
|
||||||
if (len < 0) return null;
|
if (len < 0) return null;
|
||||||
return new byte[0];
|
return Array.Empty<byte>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Reads a char array from the buffer, handling nulls and the array length. </summary>
|
/// <summary> Reads a char array from the buffer, handling nulls and the array length. </summary>
|
||||||
@ -58,7 +58,7 @@ namespace osu.Game.IO.Legacy
|
|||||||
int len = ReadInt32();
|
int len = ReadInt32();
|
||||||
if (len > 0) return ReadChars(len);
|
if (len > 0) return ReadChars(len);
|
||||||
if (len < 0) return null;
|
if (len < 0) return null;
|
||||||
return new char[0];
|
return Array.Empty<char>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Reads a DateTime from the buffer. </summary>
|
/// <summary> Reads a DateTime from the buffer. </summary>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Extensions;
|
|
||||||
using osu.Framework.IO.Network;
|
using osu.Framework.IO.Network;
|
||||||
|
|
||||||
namespace osu.Game.Online.API
|
namespace osu.Game.Online.API
|
||||||
@ -70,13 +69,11 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}";
|
protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}";
|
||||||
|
|
||||||
private double remainingTime => Math.Max(0, Timeout - (DateTime.Now.TotalMilliseconds() - (startTime ?? 0)));
|
private double remainingTime => Math.Max(0, Timeout - (DateTimeOffset.UtcNow - (startTime ?? DateTimeOffset.MinValue)).TotalMilliseconds);
|
||||||
|
|
||||||
public bool ExceededTimeout => remainingTime == 0;
|
public bool ExceededTimeout => remainingTime == 0;
|
||||||
|
|
||||||
private double? startTime;
|
private DateTimeOffset? startTime;
|
||||||
|
|
||||||
public double StartTime => startTime ?? -1;
|
|
||||||
|
|
||||||
protected APIAccess API;
|
protected APIAccess API;
|
||||||
protected WebRequest WebRequest;
|
protected WebRequest WebRequest;
|
||||||
@ -96,7 +93,7 @@ namespace osu.Game.Online.API
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (startTime == null)
|
if (startTime == null)
|
||||||
startTime = DateTime.Now.TotalMilliseconds();
|
startTime = DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
if (remainingTime <= 0)
|
if (remainingTime <= 0)
|
||||||
throw new TimeoutException(@"API request timeout hit");
|
throw new TimeoutException(@"API request timeout hit");
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Framework.Extensions;
|
|
||||||
|
|
||||||
namespace osu.Game.Online.API
|
namespace osu.Game.Online.API
|
||||||
{
|
{
|
||||||
@ -22,12 +21,12 @@ namespace osu.Game.Online.API
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return AccessTokenExpiry - DateTime.Now.ToUnixTimestamp();
|
return AccessTokenExpiry - DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
AccessTokenExpiry = DateTime.Now.AddSeconds(value).ToUnixTimestamp();
|
AccessTokenExpiry = DateTimeOffset.Now.AddSeconds(value).ToUnixTimeSeconds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ namespace osu.Game.Online.API.Requests
|
|||||||
req.Method = HttpMethod.POST;
|
req.Method = HttpMethod.POST;
|
||||||
req.AddParameter(@"target_type", message.TargetType.GetDescription());
|
req.AddParameter(@"target_type", message.TargetType.GetDescription());
|
||||||
req.AddParameter(@"target_id", message.TargetId.ToString());
|
req.AddParameter(@"target_id", message.TargetId.ToString());
|
||||||
|
req.AddParameter(@"is_action", message.IsAction.ToString().ToLower());
|
||||||
req.AddParameter(@"message", message.Content);
|
req.AddParameter(@"message", message.Content);
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
@ -30,4 +31,4 @@ namespace osu.Game.Online.API.Requests
|
|||||||
|
|
||||||
protected override string Target => @"chat/messages";
|
protected override string Target => @"chat/messages";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,13 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Game.Users;
|
|
||||||
|
|
||||||
namespace osu.Game.Online.Chat
|
namespace osu.Game.Online.Chat
|
||||||
{
|
{
|
||||||
public class ErrorMessage : Message
|
public class ErrorMessage : InfoMessage
|
||||||
{
|
{
|
||||||
private static int errorId = -1;
|
public ErrorMessage(string message) : base(message)
|
||||||
|
|
||||||
public ErrorMessage(string message) : base(errorId--)
|
|
||||||
{
|
{
|
||||||
Timestamp = DateTimeOffset.Now;
|
Sender.Colour = @"ff0000";
|
||||||
Content = message;
|
|
||||||
|
|
||||||
Sender = new User
|
|
||||||
{
|
|
||||||
Username = @"system",
|
|
||||||
Colour = @"ff0000",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
osu.Game/Online/Chat/InfoMessage.cs
Normal file
25
osu.Game/Online/Chat/InfoMessage.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.Chat
|
||||||
|
{
|
||||||
|
public class InfoMessage : Message
|
||||||
|
{
|
||||||
|
private static int infoID = -1;
|
||||||
|
|
||||||
|
public InfoMessage(string message) : base(infoID--)
|
||||||
|
{
|
||||||
|
Timestamp = DateTimeOffset.Now;
|
||||||
|
Content = message;
|
||||||
|
|
||||||
|
Sender = new User
|
||||||
|
{
|
||||||
|
Username = @"system",
|
||||||
|
Colour = @"0000ff",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,9 @@ namespace osu.Game.Online.Chat
|
|||||||
[JsonProperty(@"target_id")]
|
[JsonProperty(@"target_id")]
|
||||||
public int TargetId;
|
public int TargetId;
|
||||||
|
|
||||||
|
[JsonProperty(@"is_action")]
|
||||||
|
public bool IsAction;
|
||||||
|
|
||||||
[JsonProperty(@"timestamp")]
|
[JsonProperty(@"timestamp")]
|
||||||
public DateTimeOffset Timestamp;
|
public DateTimeOffset Timestamp;
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
|
|
||||||
private const float padding = 15;
|
private const float padding = 15;
|
||||||
private const float message_padding = 200;
|
private const float message_padding = 200;
|
||||||
|
private const float action_padding = 3;
|
||||||
private const float text_size = 20;
|
private const float text_size = 20;
|
||||||
|
|
||||||
private Color4 customUsernameColour;
|
private Color4 customUsernameColour;
|
||||||
@ -194,6 +195,8 @@ namespace osu.Game.Overlays.Chat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (message.IsAction && senderHasBackground)
|
||||||
|
contentFlow.Colour = OsuColour.FromHex(message.Sender.Colour);
|
||||||
|
|
||||||
updateMessageContent();
|
updateMessageContent();
|
||||||
FinishTransforms(true);
|
FinishTransforms(true);
|
||||||
@ -206,7 +209,17 @@ namespace osu.Game.Overlays.Chat
|
|||||||
|
|
||||||
timestamp.Text = $@"{message.Timestamp.LocalDateTime:HH:mm:ss}";
|
timestamp.Text = $@"{message.Timestamp.LocalDateTime:HH:mm:ss}";
|
||||||
username.Text = $@"{message.Sender.Username}" + (senderHasBackground ? "" : ":");
|
username.Text = $@"{message.Sender.Username}" + (senderHasBackground ? "" : ":");
|
||||||
contentFlow.Text = message.Content;
|
|
||||||
|
if (message.IsAction)
|
||||||
|
{
|
||||||
|
contentFlow.Clear();
|
||||||
|
contentFlow.AddText("[", sprite => sprite.Padding = new MarginPadding { Right = action_padding });
|
||||||
|
contentFlow.AddText(message.Content, sprite => sprite.Font = @"Exo2.0-MediumItalic");
|
||||||
|
contentFlow.AddText("]", sprite => sprite.Padding = new MarginPadding { Left = action_padding });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
contentFlow.Text = message.Content;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MessageSender : ClickableContainer, IHasContextMenu
|
private class MessageSender : ClickableContainer, IHasContextMenu
|
||||||
|
@ -465,7 +465,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
textbox.Text = string.Empty;
|
textbox.Text = string.Empty;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(postText))
|
if (string.IsNullOrWhiteSpace(postText))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var target = currentChannel;
|
var target = currentChannel;
|
||||||
@ -478,11 +478,36 @@ namespace osu.Game.Overlays
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isAction = false;
|
||||||
|
|
||||||
if (postText[0] == '/')
|
if (postText[0] == '/')
|
||||||
{
|
{
|
||||||
// TODO: handle commands
|
string[] parameters = postText.Substring(1).Split(new[] { ' ' }, 2);
|
||||||
target.AddNewMessages(new ErrorMessage("Chat commands are not supported yet!"));
|
string command = parameters[0];
|
||||||
return;
|
string content = parameters.Length == 2 ? parameters[1] : string.Empty;
|
||||||
|
|
||||||
|
switch (command)
|
||||||
|
{
|
||||||
|
case "me":
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(content))
|
||||||
|
{
|
||||||
|
currentChannel.AddNewMessages(new ErrorMessage("Usage: /me [action]"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isAction = true;
|
||||||
|
postText = content;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "help":
|
||||||
|
currentChannel.AddNewMessages(new InfoMessage("Supported commands: /help, /me [action]"));
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
currentChannel.AddNewMessages(new ErrorMessage($@"""/{command}"" is not supported! For a list of supported commands see /help"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var message = new LocalEchoMessage
|
var message = new LocalEchoMessage
|
||||||
@ -491,6 +516,7 @@ namespace osu.Game.Overlays
|
|||||||
Timestamp = DateTimeOffset.Now,
|
Timestamp = DateTimeOffset.Now,
|
||||||
TargetType = TargetType.Channel, //TODO: read this from channel
|
TargetType = TargetType.Channel, //TODO: read this from channel
|
||||||
TargetId = target.Id,
|
TargetId = target.Id,
|
||||||
|
IsAction = isAction,
|
||||||
Content = postText
|
Content = postText
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
if (mod == null)
|
if (mod == null)
|
||||||
{
|
{
|
||||||
Mods = new Mod[0];
|
Mods = Array.Empty<Mod>();
|
||||||
Alpha = 0;
|
Alpha = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -121,13 +121,14 @@ namespace osu.Game.Screens.Menu
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool rightward;
|
||||||
|
|
||||||
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
|
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
|
||||||
{
|
{
|
||||||
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
|
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
|
||||||
|
|
||||||
if (!IsHovered) return;
|
if (!IsHovered) return;
|
||||||
|
|
||||||
bool rightward = beatIndex % 2 == 1;
|
|
||||||
double duration = timingPoint.BeatLength / 2;
|
double duration = timingPoint.BeatLength / 2;
|
||||||
|
|
||||||
icon.RotateTo(rightward ? 10 : -10, duration * 2, Easing.InOutSine);
|
icon.RotateTo(rightward ? 10 : -10, duration * 2, Easing.InOutSine);
|
||||||
@ -139,6 +140,8 @@ namespace osu.Game.Screens.Menu
|
|||||||
i => i.MoveToY(0, duration, Easing.In),
|
i => i.MoveToY(0, duration, Easing.In),
|
||||||
i => i.ScaleTo(new Vector2(1, 0.9f), duration, Easing.In)
|
i => i.ScaleTo(new Vector2(1, 0.9f), duration, Easing.In)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
rightward = !rightward;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(InputState state)
|
protected override bool OnHover(InputState state)
|
||||||
@ -152,7 +155,7 @@ namespace osu.Game.Screens.Menu
|
|||||||
double duration = TimeUntilNextBeat;
|
double duration = TimeUntilNextBeat;
|
||||||
|
|
||||||
icon.ClearTransforms();
|
icon.ClearTransforms();
|
||||||
icon.RotateTo(10, duration, Easing.InOutSine);
|
icon.RotateTo(rightward ? -10 : 10, duration, Easing.InOutSine);
|
||||||
icon.ScaleTo(new Vector2(1, 0.9f), duration, Easing.Out);
|
icon.ScaleTo(new Vector2(1, 0.9f), duration, Easing.Out);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -372,6 +372,7 @@
|
|||||||
<Compile Include="Online\API\Requests\PostMessageRequest.cs" />
|
<Compile Include="Online\API\Requests\PostMessageRequest.cs" />
|
||||||
<Compile Include="Online\Chat\Channel.cs" />
|
<Compile Include="Online\Chat\Channel.cs" />
|
||||||
<Compile Include="Online\Chat\ErrorMessage.cs" />
|
<Compile Include="Online\Chat\ErrorMessage.cs" />
|
||||||
|
<Compile Include="Online\Chat\InfoMessage.cs" />
|
||||||
<Compile Include="Online\Chat\LocalEchoMessage.cs" />
|
<Compile Include="Online\Chat\LocalEchoMessage.cs" />
|
||||||
<Compile Include="Online\Chat\Message.cs" />
|
<Compile Include="Online\Chat\Message.cs" />
|
||||||
<Compile Include="Online\Multiplayer\GameType.cs" />
|
<Compile Include="Online\Multiplayer\GameType.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user