This commit is contained in:
2023-10-11 19:37:50 +03:00
parent 5d812d7acc
commit 6422db783a
33 changed files with 300 additions and 129 deletions
@@ -16,6 +16,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
using Ragon.Server.Lobby;
using Ragon.Server.Plugin.Web;
@@ -40,7 +41,7 @@ public sealed class AuthorizationOperation: BaseOperation
_writer = writer;
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
if (context.ConnectionStatus == ConnectionStatus.Authorized)
{
@@ -15,6 +15,7 @@
*/
using Ragon.Protocol;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -29,5 +30,5 @@ public abstract class BaseOperation
Writer = writer;
}
public abstract void Handle(RagonContext context);
public abstract void Handle(RagonContext context, NetworkChannel channel);
}
@@ -17,6 +17,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.Entity;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -28,7 +29,7 @@ public sealed class EntityCreateOperation : BaseOperation
{
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var player = context.RoomPlayer;
var room = context.Room;
@@ -17,6 +17,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.Event;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -28,7 +29,7 @@ public sealed class EntityEventOperation : BaseOperation
{
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var player = context.RoomPlayer;
var room = context.Room;
@@ -1,5 +1,23 @@
/*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -11,7 +29,7 @@ public sealed class EntityOwnershipOperation : BaseOperation
{
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var currentOwner = context.RoomPlayer;
var room = context.Room;
@@ -17,6 +17,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.Entity;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -28,7 +29,7 @@ public sealed class EntityDestroyOperation: BaseOperation
{
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var player = context.RoomPlayer;
var room = context.Room;
@@ -16,6 +16,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -27,7 +28,7 @@ public sealed class EntityStateOperation: BaseOperation
{
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var room = context.Room;
var player = context.RoomPlayer;
@@ -16,6 +16,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
using Ragon.Server.Lobby;
using Ragon.Server.Plugin;
using Ragon.Server.Plugin.Web;
@@ -36,7 +37,7 @@ public sealed class RoomCreateOperation : BaseOperation
_ragonWebHookPlugin = ragonWebHook;
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
{
@@ -16,6 +16,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -25,7 +26,7 @@ public sealed class RoomDataOperation : BaseOperation
{
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var player = context.RoomPlayer;
var room = context.Room;
@@ -42,8 +43,8 @@ public sealed class RoomDataOperation : BaseOperation
var sendData = new byte[size];
Array.Copy(playerData, 0, sendData, 0, playerData.Length);
Array.Copy(payloadData, 0, sendData, playerData.Length, payloadData.Length);
Array.Copy(payloadData, 1, sendData, playerData.Length, payloadData.Length - 1);
room.Broadcast(sendData);
room.Broadcast(sendData, channel);
}
}
@@ -1,5 +1,6 @@
using Ragon.Protocol;
using Ragon.Server.Event;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -9,7 +10,7 @@ public class RoomEventOperation : BaseOperation
{
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var room = context.Room;
var player = context.RoomPlayer;
@@ -16,7 +16,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.Plugin;
using Ragon.Server.IO;
using Ragon.Server.Plugin.Web;
using Ragon.Server.Room;
@@ -33,7 +33,7 @@ public sealed class RoomJoinOperation : BaseOperation
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var roomId = Reader.ReadString();
var lobbyPlayer = context.LobbyPlayer;
@@ -16,6 +16,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
using Ragon.Server.Lobby;
using Ragon.Server.Plugin;
using Ragon.Server.Plugin.Web;
@@ -36,7 +37,7 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation
_ragonWebHookPlugin = plugin;
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
{
@@ -16,6 +16,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
using Ragon.Server.Plugin;
using Ragon.Server.Plugin.Web;
@@ -31,7 +32,7 @@ public sealed class RoomLeaveOperation: BaseOperation
_webHook = plugin;
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var room = context.Room;
var roomPlayer = context.RoomPlayer;
@@ -1,6 +1,22 @@
/*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using NLog;
using Ragon.Protocol;
using Ragon.Server.Entity;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -12,7 +28,7 @@ public sealed class RoomOwnershipOperation : BaseOperation
{
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
}
@@ -14,9 +14,9 @@
* limitations under the License.
*/
using NLog;
using Ragon.Protocol;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -26,7 +26,7 @@ public class SceneLoadOperation: BaseOperation
public SceneLoadOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer) {}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var roomOwner = context.Room.Owner;
var currentPlayer = context.RoomPlayer;
@@ -17,6 +17,7 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.Entity;
using Ragon.Server.IO;
using Ragon.Server.Lobby;
using Ragon.Server.Room;
@@ -31,7 +32,7 @@ public sealed class SceneLoadedOperation : BaseOperation
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
return;
@@ -1,4 +1,21 @@
/*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Ragon.Protocol;
using Ragon.Server.IO;
namespace Ragon.Server.Handler;
@@ -8,7 +25,7 @@ public class TimestampSyncOperation: BaseOperation
{
}
public override void Handle(RagonContext context)
public override void Handle(RagonContext context, NetworkChannel channel)
{
var timestamp0 = Reader.Read(32);
var timestamp1 = Reader.Read(32);
+1 -2
View File
@@ -21,7 +21,6 @@ public interface INetworkServer
public Executor Executor { get; }
public void Stop();
public void Update();
public void BroadcastUnreliable(byte[] data);
public void BroadcastReliable(byte[] data);
public void Broadcast(byte[] data, NetworkChannel channel);
public void Start(INetworkListener listener, NetworkConfiguration configuration);
}
+17 -1
View File
@@ -1,8 +1,24 @@
/*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Ragon.Server.IO;
public enum NetworkChannel
{
RELIABLE = 1,
UNRELIABLE = 2,
RAW = 3,
}
+2 -2
View File
@@ -197,7 +197,7 @@ public class RagonServer : IRagonServer, INetworkListener
_reader.FromArray(data);
var operation = _reader.ReadByte();
_handlers[operation].Handle(context);
_handlers[operation].Handle(context, channel);
}
}
catch (Exception ex)
@@ -220,7 +220,7 @@ public class RagonServer : IRagonServer, INetworkListener
_writer.Write(value.Int1, 32);
var sendData = _writer.ToArray();
_server.BroadcastUnreliable(sendData);
_server.Broadcast(sendData, NetworkChannel.UNRELIABLE);
}
public BaseOperation ResolveOperation(RagonOperation operation)