mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 20:53:40 -04:00
x
This commit is contained in:
parent
d2f5f8fcbb
commit
f578c6bc07
@ -38,21 +38,21 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Attempts to parse the given argument as an enumeration member. </summary>
|
/// <summary> Attempts to parse the given argument as an enumeration member. </summary>
|
||||||
public static bool GetEnum<TEnum>(Player p, string input, string type,
|
public static bool GetEnum<TEnum>(Player p, string input, string argName,
|
||||||
ref TEnum result) where TEnum : struct {
|
ref TEnum result) where TEnum : struct {
|
||||||
try {
|
try {
|
||||||
result = (TEnum)Enum.Parse(typeof(TEnum), input, true);
|
result = (TEnum)Enum.Parse(typeof(TEnum), input, true);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
string[] names = Enum.GetNames(typeof(TEnum));
|
string[] names = Enum.GetNames(typeof(TEnum));
|
||||||
Player.Message(p, type + " must be one of the following: " + names.Join());
|
Player.Message(p, argName + " must be one of the following: " + names.Join());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary> Attempts to parse the given argument as an integer. </summary>
|
/// <summary> Attempts to parse the given argument as an integer. </summary>
|
||||||
public static bool GetInt(Player p, string input, string type, ref int result,
|
public static bool GetInt(Player p, string input, string argName, ref int result,
|
||||||
int min = int.MinValue, int max = int.MaxValue) {
|
int min = int.MinValue, int max = int.MaxValue) {
|
||||||
int value;
|
int value;
|
||||||
if (!int.TryParse(input, out value)) {
|
if (!int.TryParse(input, out value)) {
|
||||||
@ -62,11 +62,11 @@ namespace MCGalaxy {
|
|||||||
if (value < min || value > max) {
|
if (value < min || value > max) {
|
||||||
// Try to provide more helpful range messages
|
// Try to provide more helpful range messages
|
||||||
if (max == int.MaxValue) {
|
if (max == int.MaxValue) {
|
||||||
Player.Message(p, "{0} must be {1} or greater", type, min);
|
Player.Message(p, "{0} must be {1} or greater", argName, min);
|
||||||
} else if (min == int.MinValue) {
|
} else if (min == int.MinValue) {
|
||||||
Player.Message(p, "{0} must be {1} or less", type, max);
|
Player.Message(p, "{0} must be {1} or less", argName, max);
|
||||||
} else {
|
} else {
|
||||||
Player.Message(p, "{0} must be between {1} and {2}", type, min, max);
|
Player.Message(p, "{0} must be between {1} and {2}", argName, min, max);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -76,19 +76,19 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
|
|
||||||
/// <summary> Attempts to parse the given argument as an byte. </summary>
|
/// <summary> Attempts to parse the given argument as an byte. </summary>
|
||||||
public static bool GetByte(Player p, string input, string type, ref byte result,
|
public static bool GetByte(Player p, string input, string argName, ref byte result,
|
||||||
byte min = byte.MinValue, byte max = byte.MaxValue) {
|
byte min = byte.MinValue, byte max = byte.MaxValue) {
|
||||||
int temp = 0;
|
int temp = 0;
|
||||||
if (!GetInt(p, input, type, ref temp, min, max)) return false;
|
if (!GetInt(p, input, argName, ref temp, min, max)) return false;
|
||||||
|
|
||||||
result = (byte)temp; return true;
|
result = (byte)temp; return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Attempts to parse the given argument as an byte. </summary>
|
/// <summary> Attempts to parse the given argument as an byte. </summary>
|
||||||
public static bool GetUShort(Player p, string input, string type, ref ushort result,
|
public static bool GetUShort(Player p, string input, string argName, ref ushort result,
|
||||||
ushort min = ushort.MinValue, ushort max = ushort.MaxValue) {
|
ushort min = ushort.MinValue, ushort max = ushort.MaxValue) {
|
||||||
int temp = 0;
|
int temp = 0;
|
||||||
if (!GetInt(p, input, type, ref temp, min, max)) return false;
|
if (!GetInt(p, input, argName, ref temp, min, max)) return false;
|
||||||
|
|
||||||
result = (ushort)temp; return true;
|
result = (ushort)temp; return true;
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,6 @@ using MCGalaxy.Network;
|
|||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
public sealed partial class Player : IDisposable {
|
public sealed partial class Player : IDisposable {
|
||||||
|
|
||||||
public NetworkStream Stream;
|
|
||||||
|
|
||||||
static void Receive(IAsyncResult result) {
|
static void Receive(IAsyncResult result) {
|
||||||
//Server.s.Log(result.AsyncState.ToString());
|
//Server.s.Log(result.AsyncState.ToString());
|
||||||
Player p = (Player)result.AsyncState;
|
Player p = (Player)result.AsyncState;
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace MCGalaxy.Network {
|
namespace MCGalaxy.Network {
|
||||||
/// <summary> Combines block changes and sends them as either a CPE BulkBlockUpdate packet,
|
/// <summary> Combines block changes and sends them as either a single CPE BulkBlockUpdate packet,
|
||||||
/// or 256 SetBlock packets combined as a single byte array to reduce overhead. </summary>
|
/// or 256 SetBlock packets combined as a single byte array to reduce overhead. </summary>
|
||||||
public sealed class BufferedBlockSender {
|
public sealed class BufferedBlockSender {
|
||||||
|
|
||||||
@ -42,6 +42,9 @@ namespace MCGalaxy.Network {
|
|||||||
this.level = player.level;
|
this.level = player.level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Adds a block change, and potentially sends block change packets if
|
||||||
|
/// number of buffered block changes has reached the limit. </summary>
|
||||||
|
/// <returns> Whether block change packets were actually sent. </returns>
|
||||||
public bool Add(int index, byte block, byte extBlock) {
|
public bool Add(int index, byte block, byte extBlock) {
|
||||||
indices[count] = index;
|
indices[count] = index;
|
||||||
if (block == Block.custom_block) types[count] = extBlock;
|
if (block == Block.custom_block) types[count] = extBlock;
|
||||||
@ -51,16 +54,16 @@ namespace MCGalaxy.Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Sends the block change packets if either 'force' is true,
|
/// <summary> Sends the block change packets if either 'force' is true,
|
||||||
/// or the number of blocks in the buffer has reached the limit. </summary>
|
/// or the number of buffered block changes has reached the limit. </summary>
|
||||||
/// <returns> Whether block change packets were actually sent. </returns>
|
/// <returns> Whether block change packets were actually sent. </returns>
|
||||||
public bool Send(bool force) {
|
public bool Send(bool force) {
|
||||||
if (count > 0 && (force || count == 256)) {
|
if (count > 0 && (force || count == 256)) {
|
||||||
if (player != null) SendPlayer();
|
if (player != null) SendPlayer();
|
||||||
else SendLevel();
|
else SendLevel();
|
||||||
count = 0;
|
count = 0;
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendLevel() {
|
void SendLevel() {
|
||||||
|
@ -20,6 +20,8 @@ using System.IO;
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
|
||||||
namespace MCGalaxy.Network {
|
namespace MCGalaxy.Network {
|
||||||
|
|
||||||
|
/// <summary> Streams the compressed form of a map directly to a player's network socket. </summary>
|
||||||
public sealed class LevelChunkStream : Stream {
|
public sealed class LevelChunkStream : Stream {
|
||||||
public override bool CanRead { get { return false; } }
|
public override bool CanRead { get { return false; } }
|
||||||
public override bool CanSeek { get { return false; } }
|
public override bool CanSeek { get { return false; } }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user