mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 20:16:36 -04:00
WIP on ignoring unwanted positions after TPing, spawning a player
This commit is contained in:
parent
ffe4707394
commit
5ea3e77b56
@ -259,10 +259,16 @@ namespace MCGalaxy.Network
|
|||||||
bool serverToClient = buffer[offset + 1] != 0;
|
bool serverToClient = buffer[offset + 1] != 0;
|
||||||
ushort data = NetUtils.ReadU16(buffer, offset + 2);
|
ushort data = NetUtils.ReadU16(buffer, offset + 2);
|
||||||
|
|
||||||
|
//player.Message("&bServerToClient? {0}, data {1}", serverToClient, data);
|
||||||
|
|
||||||
if (!serverToClient) {
|
if (!serverToClient) {
|
||||||
// Client-> server ping, immediately send reply.
|
// Client-> server ping, immediately send reply.
|
||||||
Send(Packet.TwoWayPing(false, data));
|
Send(Packet.TwoWayPing(false, data));
|
||||||
} else {
|
} else {
|
||||||
|
if (Ping.UnIgnorePosition(data)) {
|
||||||
|
player.IgnorePosition = false;
|
||||||
|
player.Message("Your position is no longer being ignored, received {0}", data);
|
||||||
|
}
|
||||||
// Server -> client ping, set time received for reply.
|
// Server -> client ping, set time received for reply.
|
||||||
Ping.Update(data);
|
Ping.Update(data);
|
||||||
}
|
}
|
||||||
@ -358,6 +364,7 @@ namespace MCGalaxy.Network
|
|||||||
if (id == Entities.SelfID) pos.Y -= 22;
|
if (id == Entities.SelfID) pos.Y -= 22;
|
||||||
|
|
||||||
Send(Packet.Teleport(id, pos, rot, player.hasExtPositions));
|
Send(Packet.Teleport(id, pos, rot, player.hasExtPositions));
|
||||||
|
DoIgnorePositionPing(id);
|
||||||
}
|
}
|
||||||
public override bool SendTeleport(byte id, Position pos, Orientation rot,
|
public override bool SendTeleport(byte id, Position pos, Orientation rot,
|
||||||
Packet.TeleportMoveMode moveMode, bool usePos = true, bool interpolateOri = false, bool useOri = true) {
|
Packet.TeleportMoveMode moveMode, bool usePos = true, bool interpolateOri = false, bool useOri = true) {
|
||||||
@ -368,8 +375,16 @@ namespace MCGalaxy.Network
|
|||||||
{ pos.Y -= 22; }
|
{ pos.Y -= 22; }
|
||||||
|
|
||||||
Send(Packet.TeleportExt(id, usePos, moveMode, useOri, interpolateOri, pos, rot, player.hasExtPositions));
|
Send(Packet.TeleportExt(id, usePos, moveMode, useOri, interpolateOri, pos, rot, player.hasExtPositions));
|
||||||
|
DoIgnorePositionPing(id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
void DoIgnorePositionPing(byte id) {
|
||||||
|
if (!hasTwoWayPing || id != Entities.SelfID) { return; }
|
||||||
|
ushort data = Ping.NextTwoWayPingData(true);
|
||||||
|
SendTwoWayPing(data);
|
||||||
|
player.IgnorePosition = true;
|
||||||
|
player.Message("Now ignoring your position until {0}", data);
|
||||||
|
}
|
||||||
|
|
||||||
public override void SendRemoveEntity(byte id) {
|
public override void SendRemoveEntity(byte id) {
|
||||||
Send(Packet.RemoveEntity(id));
|
Send(Packet.RemoveEntity(id));
|
||||||
@ -521,11 +536,15 @@ namespace MCGalaxy.Network
|
|||||||
|
|
||||||
public override void SendPing() {
|
public override void SendPing() {
|
||||||
if (hasTwoWayPing) {
|
if (hasTwoWayPing) {
|
||||||
Send(Packet.TwoWayPing(true, Ping.NextTwoWayPingData()));
|
SendTwoWayPing(Ping.NextTwoWayPingData());
|
||||||
} else {
|
} else {
|
||||||
Send(Packet.Ping());
|
Send(Packet.Ping());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void SendTwoWayPing(BlockID data) {
|
||||||
|
if (!hasTwoWayPing) { return; }
|
||||||
|
Send(Packet.TwoWayPing(true, data));
|
||||||
|
}
|
||||||
|
|
||||||
public override void SendSetSpawnpoint(Position pos, Orientation rot) {
|
public override void SendSetSpawnpoint(Position pos, Orientation rot) {
|
||||||
if (Supports(CpeExt.SetSpawnpoint)) {
|
if (Supports(CpeExt.SetSpawnpoint)) {
|
||||||
@ -559,6 +578,8 @@ namespace MCGalaxy.Network
|
|||||||
} else {
|
} else {
|
||||||
Send(Packet.AddEntity(id, name, pos, rot, player.hasCP437, player.hasExtPositions));
|
Send(Packet.AddEntity(id, name, pos, rot, player.hasCP437, player.hasExtPositions));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DoIgnorePositionPing(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SendLevel(Level prev, Level level) {
|
public override void SendLevel(Level prev, Level level) {
|
||||||
|
@ -36,8 +36,16 @@ namespace MCGalaxy.Network
|
|||||||
public PingEntry[] Entries = new PingEntry[10];
|
public PingEntry[] Entries = new PingEntry[10];
|
||||||
int pingCounter, nextPingHead;
|
int pingCounter, nextPingHead;
|
||||||
|
|
||||||
|
long ignorePositionData = -1;
|
||||||
|
public bool UnIgnorePosition(ushort data) {
|
||||||
|
if (Interlocked.Read(ref ignorePositionData) == data) {
|
||||||
|
Interlocked.Exchange(ref ignorePositionData, -1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public ushort NextTwoWayPingData() {
|
public ushort NextTwoWayPingData(bool waitingForMovementAcknowledged = false) {
|
||||||
int pingValue = Interlocked.Increment(ref pingCounter);
|
int pingValue = Interlocked.Increment(ref pingCounter);
|
||||||
int pingHead = (Interlocked.Increment(ref nextPingHead) - 1) % 10;
|
int pingHead = (Interlocked.Increment(ref nextPingHead) - 1) % 10;
|
||||||
|
|
||||||
@ -45,6 +53,7 @@ namespace MCGalaxy.Network
|
|||||||
Entries[pingHead].TimeRecv = default(DateTime);
|
Entries[pingHead].TimeRecv = default(DateTime);
|
||||||
Entries[pingHead].TimeSent = DateTime.UtcNow;
|
Entries[pingHead].TimeSent = DateTime.UtcNow;
|
||||||
|
|
||||||
|
if (waitingForMovementAcknowledged) Interlocked.Exchange(ref ignorePositionData, pingValue);
|
||||||
return (ushort)pingValue;
|
return (ushort)pingValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ permissions and limitations under the Licenses.
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Threading;
|
||||||
using MCGalaxy.Drawing;
|
using MCGalaxy.Drawing;
|
||||||
using MCGalaxy.Drawing.Brushes;
|
using MCGalaxy.Drawing.Brushes;
|
||||||
using MCGalaxy.Drawing.Transforms;
|
using MCGalaxy.Drawing.Transforms;
|
||||||
@ -109,6 +110,15 @@ namespace MCGalaxy {
|
|||||||
public bool onTrain, trainInvincible;
|
public bool onTrain, trainInvincible;
|
||||||
int mbRecursion;
|
int mbRecursion;
|
||||||
|
|
||||||
|
private long _ignorePosition = 0;
|
||||||
|
internal bool IgnorePosition {
|
||||||
|
get { return Interlocked.Read(ref _ignorePosition) > 0; }
|
||||||
|
set {
|
||||||
|
if (value) Interlocked.Exchange(ref _ignorePosition, 1);
|
||||||
|
else Interlocked.Exchange(ref _ignorePosition, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool frozen;
|
public bool frozen;
|
||||||
public string following = "";
|
public string following = "";
|
||||||
public string possess = "";
|
public string possess = "";
|
||||||
|
@ -224,6 +224,7 @@ namespace MCGalaxy
|
|||||||
public void ProcessMovement(int x, int y, int z, byte yaw, byte pitch, int held) {
|
public void ProcessMovement(int x, int y, int z, byte yaw, byte pitch, int held) {
|
||||||
if (held >= 0) ClientHeldBlock = (BlockID)held;
|
if (held >= 0) ClientHeldBlock = (BlockID)held;
|
||||||
|
|
||||||
|
if (IgnorePosition) { return; }
|
||||||
if (trainGrab || following.Length > 0) { CheckBlocks(Pos, Pos); return; }
|
if (trainGrab || following.Length > 0) { CheckBlocks(Pos, Pos); return; }
|
||||||
Position next = new Position(x, y, z);
|
Position next = new Position(x, y, z);
|
||||||
CheckBlocks(Pos, next);
|
CheckBlocks(Pos, next);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user