mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-18 11:48:33 -04:00
Add an opcodes class with names of packets, instead of just using the numerical constants.
This commit is contained in:
parent
a190713648
commit
03887f1f79
@ -40,7 +40,7 @@ namespace MCGalaxy.Commands
|
||||
{
|
||||
byte[] buffer = new byte[65];
|
||||
Player.StringFormat(" ", 64).CopyTo(buffer, 1);
|
||||
p.SendRaw(13, buffer);
|
||||
p.SendRaw(Opcode.Message, buffer);
|
||||
buffer = null;
|
||||
}
|
||||
public override void Help(Player p)
|
||||
|
@ -40,7 +40,7 @@ namespace MCGalaxy.Commands
|
||||
{
|
||||
byte[] buffer = new byte[65];
|
||||
Player.StringFormat(" ", 64).CopyTo(buffer, 1);
|
||||
p.SendRaw(13, buffer);
|
||||
p.SendRaw(Opcode.Message, buffer);
|
||||
buffer = null;
|
||||
}
|
||||
public override void Help(Player p)
|
||||
|
@ -66,7 +66,7 @@ namespace MCGalaxy.Commands
|
||||
p.level = level;
|
||||
p.SendMotd();
|
||||
|
||||
p.SendRaw(2);
|
||||
p.SendRaw(Opcode.LevelInitialise);
|
||||
byte[] buffer = new byte[level.blocks.Length + 4];
|
||||
BitConverter.GetBytes(IPAddress.HostToNetworkOrder(level.blocks.Length)).CopyTo(buffer, 0);
|
||||
//ushort xx; ushort yy; ushort zz;
|
||||
@ -86,13 +86,13 @@ namespace MCGalaxy.Commands
|
||||
Buffer.BlockCopy(buffer, length, tempbuffer, 0, buffer.Length - length);
|
||||
buffer = tempbuffer;
|
||||
send[1026] = (byte)(i * 100 / number);
|
||||
p.SendRaw(3, send);
|
||||
p.SendRaw(Opcode.LevelDataChunk, send);
|
||||
Thread.Sleep(10);
|
||||
} buffer = new byte[6];
|
||||
Player.HTNO((short)level.Width).CopyTo(buffer, 0);
|
||||
Player.HTNO((short)level.Height).CopyTo(buffer, 2);
|
||||
Player.HTNO((short)level.Length).CopyTo(buffer, 4);
|
||||
p.SendRaw(4, buffer);
|
||||
p.SendRaw(Opcode.LevelFinalise, buffer);
|
||||
|
||||
ushort x = (ushort)((0.5 + level.spawnx) * 32);
|
||||
ushort y = (ushort)((1 + level.spawny) * 32);
|
||||
|
@ -68,17 +68,17 @@ namespace MCGalaxy.Levels.Textures
|
||||
if (text == "")
|
||||
{
|
||||
Player.StringFormat(detail, 64).CopyTo(buffer, 1);
|
||||
p.SendRaw(13, buffer);
|
||||
p.SendRaw(Opcode.Message, buffer);
|
||||
}
|
||||
else if (!text.StartsWith("^"))
|
||||
{
|
||||
Player.StringFormat("^detail.user=" + text, 64).CopyTo(buffer, 1);
|
||||
p.SendRaw(13, buffer);
|
||||
p.SendRaw(Opcode.Message, buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Player.StringFormat(text, 64).CopyTo(buffer, 1);
|
||||
p.SendRaw(13, buffer);
|
||||
p.SendRaw(Opcode.Message, buffer);
|
||||
}
|
||||
}
|
||||
buffer = null;
|
||||
|
@ -432,6 +432,7 @@
|
||||
<Compile Include="Levels\Physics\TrainPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\TntPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\ZombiePhysics.cs" />
|
||||
<Compile Include="Network\Opcode.cs" />
|
||||
<Compile Include="Network\Player.Networking.cs" />
|
||||
<Compile Include="Player\Alias.cs" />
|
||||
<Compile Include="API\API.cs" />
|
||||
|
63
Network/Opcode.cs
Normal file
63
Network/Opcode.cs
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright 2015 MCGalaxy
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
public static class Opcode {
|
||||
|
||||
public const byte Handshake = 0;
|
||||
public const byte Ping = 1;
|
||||
public const byte LevelInitialise = 2;
|
||||
public const byte LevelDataChunk = 3;
|
||||
public const byte LevelFinalise = 4;
|
||||
public const byte SetBlockClient = 5;
|
||||
public const byte SetBlock = 6;
|
||||
public const byte AddEntity = 7;
|
||||
public const byte EntityTeleport = 8;
|
||||
public const byte RelPosAndOrientationUpdate = 9;
|
||||
public const byte RelPosUpdate = 10;
|
||||
public const byte OrientationUpdate = 11;
|
||||
public const byte RemoveEntity = 12;
|
||||
public const byte Message = 13;
|
||||
public const byte Kick = 14;
|
||||
public const byte SetPermission = 15;
|
||||
|
||||
public const byte CpeExtInfo = 16;
|
||||
public const byte CpeExtEntry = 17;
|
||||
public const byte CpeSetClickDistance = 18;
|
||||
public const byte CpeCustomBlockSupportLevel = 19;
|
||||
public const byte CpeHoldThis = 20;
|
||||
public const byte CpeSetTextHotkey = 21;
|
||||
public const byte CpeExtAddPlayerName = 22;
|
||||
public const byte CpeExtAddEntity = 23;
|
||||
public const byte CpeExtRemovePlayerName = 24;
|
||||
public const byte CpeEnvColours = 25;
|
||||
public const byte CpeMakeSelection = 26;
|
||||
public const byte CpeRemoveSelection = 27;
|
||||
public const byte CpeSetBlockPermission = 28;
|
||||
public const byte CpeChangeModel = 29;
|
||||
public const byte CpeEnvSetMapApperance = 30;
|
||||
public const byte CpeEnvWeatherType = 31;
|
||||
public const byte CpeHackControl = 32;
|
||||
public const byte CpeExtAddEntity2 = 33;
|
||||
public const byte CpePlayerClick = 34;
|
||||
public const byte CpeDefineBlock = 35;
|
||||
public const byte CpeRemoveBlockDefinition = 36;
|
||||
}
|
||||
}
|
@ -107,7 +107,7 @@ namespace MCGalaxy {
|
||||
{
|
||||
byte[] buffer = new byte[65];
|
||||
Player.StringFormat("^detail.user.here=" + p.color + p.name, 64).CopyTo(buffer, 1);
|
||||
SendRaw(13, buffer);
|
||||
SendRaw(Opcode.Message, buffer);
|
||||
buffer = null;
|
||||
}
|
||||
});
|
||||
@ -329,7 +329,7 @@ namespace MCGalaxy {
|
||||
StringFormat437(newLine, 64).CopyTo(buffer, 1);
|
||||
else
|
||||
StringFormat(newLine, 64).CopyTo(buffer, 1);
|
||||
SendRaw(13, buffer);
|
||||
SendRaw(Opcode.Message, buffer);
|
||||
}
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
@ -359,8 +359,7 @@ namespace MCGalaxy {
|
||||
if ( OnSendMOTD != null ) {
|
||||
OnSendMOTD(this, buffer);
|
||||
}
|
||||
SendRaw(0, buffer);
|
||||
|
||||
SendRaw(Opcode.Handshake, buffer);
|
||||
}
|
||||
|
||||
public void SendUserMOTD() {
|
||||
@ -380,7 +379,7 @@ namespace MCGalaxy {
|
||||
buffer[129] = 100;
|
||||
else
|
||||
buffer[129] = 0;
|
||||
SendRaw(0, buffer);
|
||||
SendRaw(Opcode.Handshake, buffer);
|
||||
}
|
||||
|
||||
public void SendMap() {
|
||||
@ -402,7 +401,7 @@ namespace MCGalaxy {
|
||||
buffer[4 + i] = (byte)Block.Convert(Block.ConvertCPE(level.blocks[i]));
|
||||
}
|
||||
}
|
||||
SendRaw(2);
|
||||
SendRaw(Opcode.LevelInitialise);
|
||||
|
||||
buffer = buffer.GZip();
|
||||
int number = (int)Math.Ceiling(( (double)buffer.Length ) / 1024);
|
||||
@ -416,7 +415,7 @@ namespace MCGalaxy {
|
||||
buffer = tempbuffer;
|
||||
send[1026] = (byte)( i * 100 / number );
|
||||
//send[1026] = (byte)(100 - (i * 100 / number)); // Backwards progress lololol...
|
||||
SendRaw(3, send);
|
||||
SendRaw(Opcode.LevelDataChunk, send);
|
||||
if ( ip == "127.0.0.1" ) { }
|
||||
else if ( Server.updateTimer.Interval > 1000 ) Thread.Sleep(100);
|
||||
else Thread.Sleep(10);
|
||||
@ -424,7 +423,7 @@ namespace MCGalaxy {
|
||||
HTNO((short)level.Width).CopyTo(buffer, 0);
|
||||
HTNO((short)level.Height).CopyTo(buffer, 2);
|
||||
HTNO((short)level.Length).CopyTo(buffer, 4);
|
||||
SendRaw(4, buffer);
|
||||
SendRaw(Opcode.LevelFinalise, buffer);
|
||||
Loading = false;
|
||||
if (HasExtension("EnvWeatherType"))
|
||||
{
|
||||
@ -504,11 +503,12 @@ namespace MCGalaxy {
|
||||
HTNO(y).CopyTo(buffer, 67);
|
||||
HTNO(z).CopyTo(buffer, 69);
|
||||
buffer[71] = rotx; buffer[72] = roty;
|
||||
SendRaw(7, buffer);
|
||||
SendRaw(Opcode.AddEntity, buffer);
|
||||
|
||||
if (HasExtension("ChangeModel"))
|
||||
{
|
||||
Player.players.ForEach(p =>
|
||||
Player.players.ForEach(
|
||||
p =>
|
||||
{
|
||||
if (p.level == this.level)
|
||||
if (p == this) unchecked { SendChangeModel((byte)-1, model); }
|
||||
@ -534,22 +534,23 @@ namespace MCGalaxy {
|
||||
pos[0] = x; pos[1] = y; pos[2] = z;
|
||||
rot[0] = rotx; rot[1] = roty;
|
||||
|
||||
/*
|
||||
pos = new ushort[3] { x, y, z };
|
||||
rot = new byte[2] { rotx, roty };*/
|
||||
byte[] buffer = new byte[9]; buffer[0] = id;
|
||||
byte[] buffer = new byte[9];
|
||||
buffer[0] = id;
|
||||
HTNO(x).CopyTo(buffer, 1);
|
||||
HTNO(y).CopyTo(buffer, 3);
|
||||
HTNO(z).CopyTo(buffer, 5);
|
||||
buffer[7] = rotx; buffer[8] = roty;
|
||||
SendRaw(8, buffer);
|
||||
buffer[7] = rotx;
|
||||
buffer[8] = roty;
|
||||
SendRaw(Opcode.EntityTeleport, buffer);
|
||||
}
|
||||
// Update user type for weather or not they are opped
|
||||
public void SendUserType(bool op) {
|
||||
SendRaw(15, op ? (byte)100 : (byte)0);
|
||||
SendRaw(Opcode.SetPermission, op ? (byte)100 : (byte)0);
|
||||
}
|
||||
//TODO: Figure a way to SendPos without changing rotation
|
||||
public void SendDie(byte id) { SendRaw(0x0C, new byte[1] { id }); }
|
||||
public void SendDie(byte id) {
|
||||
SendRaw(Opcode.RemoveEntity, new byte[1] { id });
|
||||
}
|
||||
public void SendBlockchange(ushort x, ushort y, ushort z, byte type) {
|
||||
if (x < 0 || y < 0 || z < 0) return;
|
||||
if (x >= level.Width || y >= level.Height || z >= level.Length) return;
|
||||
@ -580,15 +581,19 @@ rot = new byte[2] { rotx, roty };*/
|
||||
buffer[6] = (byte)Block.Convert(Block.ConvertCPE(type));
|
||||
}
|
||||
}
|
||||
SendRaw(6, buffer);
|
||||
SendRaw(Opcode.SetBlock , buffer);
|
||||
}
|
||||
void SendKick(string message) {
|
||||
SendRaw(Opcode.Kick, StringFormat(message, 64));
|
||||
}
|
||||
void SendPing() {
|
||||
SendRaw(Opcode.Ping);
|
||||
}
|
||||
void SendKick(string message) { SendRaw(14, StringFormat(message, 64)); }
|
||||
void SendPing() { /*pingDelay = 0; pingDelayTimer.Start();*/ SendRaw(1); }
|
||||
void SendExtInfo( byte count ) {
|
||||
byte[] buffer = new byte[66];
|
||||
StringFormat( "MCGalaxy " + Server.Version, 64 ).CopyTo( buffer, 0 );
|
||||
HTNO( count ).CopyTo( buffer, 64 );
|
||||
SendRaw( 16, buffer );
|
||||
SendRaw( Opcode.CpeExtInfo, buffer );
|
||||
}
|
||||
void SendExtEntry( string name, int version ) {
|
||||
byte[] version_ = BitConverter.GetBytes(version);
|
||||
@ -597,23 +602,23 @@ rot = new byte[2] { rotx, roty };*/
|
||||
byte[] buffer = new byte[68];
|
||||
StringFormat(name, 64).CopyTo(buffer, 0);
|
||||
version_.CopyTo(buffer, 64);
|
||||
SendRaw( 17, buffer );
|
||||
SendRaw( Opcode.CpeExtEntry, buffer );
|
||||
}
|
||||
void SendClickDistance( short distance ) {
|
||||
byte[] buffer = new byte[2];
|
||||
HTNO( distance ).CopyTo( buffer, 0 );
|
||||
SendRaw( 18, buffer );
|
||||
SendRaw( Opcode.CpeSetClickDistance, buffer );
|
||||
}
|
||||
void SendCustomBlockSupportLevel(byte level) {
|
||||
byte[] buffer = new byte[1];
|
||||
buffer[0] = level;
|
||||
SendRaw( 19, buffer );
|
||||
SendRaw( Opcode.CpeCustomBlockSupportLevel, buffer );
|
||||
}
|
||||
void SendHoldThis( byte type, byte locked ) { // if locked is on 1, then the player can't change their selected block.
|
||||
byte[] buffer = new byte[2];
|
||||
buffer[0] = type;
|
||||
buffer[1] = locked;
|
||||
SendRaw( 20, buffer );
|
||||
SendRaw( Opcode.CpeHoldThis, buffer );
|
||||
}
|
||||
void SendTextHotKey( string label, string command, int keycode, byte mods ) {
|
||||
byte[] buffer = new byte[133];
|
||||
@ -621,7 +626,7 @@ rot = new byte[2] { rotx, roty };*/
|
||||
StringFormat( command, 64 ).CopyTo( buffer, 64 );
|
||||
BitConverter.GetBytes( keycode ).CopyTo( buffer, 128 );
|
||||
buffer[132] = mods;
|
||||
SendRaw( 21, buffer );
|
||||
SendRaw( Opcode.CpeSetTextHotkey, buffer );
|
||||
}
|
||||
public void SendExtAddPlayerName(short id, string name, Group grp, string displayname = "")
|
||||
{
|
||||
@ -632,7 +637,7 @@ rot = new byte[2] { rotx, roty };*/
|
||||
StringFormat(displayname, 64).CopyTo(buffer, 66);
|
||||
StringFormat(grp.color + grp.name.ToUpper() + "s:", 64).CopyTo(buffer, 130);
|
||||
buffer[194] = (byte)grp.Permission.GetHashCode();
|
||||
SendRaw(22, buffer);
|
||||
SendRaw(Opcode.CpeExtAddPlayerName, buffer);
|
||||
}
|
||||
|
||||
public void SendExtAddEntity(byte id, string name, string displayname = "")
|
||||
@ -642,12 +647,12 @@ rot = new byte[2] { rotx, roty };*/
|
||||
StringFormat(name, 64).CopyTo(buffer, 1);
|
||||
if (displayname == "") { displayname = name; }
|
||||
StringFormat(displayname, 64).CopyTo(buffer, 65);
|
||||
SendRaw(23, buffer);
|
||||
SendRaw( Opcode.CpeExtAddEntity, buffer);
|
||||
}
|
||||
public void SendDeletePlayerName( byte id ) {
|
||||
byte[] buffer = new byte[2];
|
||||
HTNO( (short)id ).CopyTo( buffer, 0 );
|
||||
SendRaw( 24, buffer );
|
||||
SendRaw( Opcode.CpeExtRemovePlayerName, buffer );
|
||||
}
|
||||
public void SendEnvColors( byte type, short r, short g, short b ) {
|
||||
byte[] buffer = new byte[7];
|
||||
@ -655,7 +660,7 @@ rot = new byte[2] { rotx, roty };*/
|
||||
HTNO( r ).CopyTo( buffer, 1 );
|
||||
HTNO( g ).CopyTo( buffer, 3 );
|
||||
HTNO( b ).CopyTo( buffer, 5 );
|
||||
SendRaw( 25, buffer );
|
||||
SendRaw( Opcode.CpeEnvColours, buffer );
|
||||
}
|
||||
public void SendMakeSelection( byte id, string label, short smallx, short smally, short smallz, short bigx, short bigy, short bigz, short r, short g, short b, short opacity ) {
|
||||
byte[] buffer = new byte[85];
|
||||
@ -671,25 +676,25 @@ rot = new byte[2] { rotx, roty };*/
|
||||
HTNO( g ).CopyTo( buffer, 79);
|
||||
HTNO( b ).CopyTo( buffer, 81 );
|
||||
HTNO( opacity ).CopyTo( buffer, 83 );
|
||||
SendRaw( 26, buffer );
|
||||
SendRaw( Opcode.CpeMakeSelection, buffer );
|
||||
}
|
||||
public void SendDeleteSelection( byte id ) {
|
||||
byte[] buffer = new byte[1];
|
||||
buffer[0] = id;
|
||||
SendRaw( 27, buffer );
|
||||
SendRaw( Opcode.CpeRemoveSelection, buffer );
|
||||
}
|
||||
void SendSetBlockPermission( byte type, byte canplace, byte candelete ) {
|
||||
byte[] buffer = new byte[3];
|
||||
buffer[0] = type;
|
||||
buffer[1] = canplace;
|
||||
buffer[2] = candelete;
|
||||
SendRaw( 28, buffer );
|
||||
SendRaw( Opcode.CpeSetBlockPermission, buffer );
|
||||
}
|
||||
public void SendChangeModel( byte id, string model ) {
|
||||
byte[] buffer = new byte[65];
|
||||
buffer[0] = id;
|
||||
StringFormat( model, 64 ).CopyTo( buffer, 1 );
|
||||
SendRaw( 29, buffer );
|
||||
SendRaw( Opcode.CpeChangeModel, buffer );
|
||||
}
|
||||
public void SendSetMapAppearance( string url, byte sideblock, byte edgeblock, short sidelevel ) {
|
||||
byte[] buffer = new byte[68];
|
||||
@ -697,13 +702,15 @@ rot = new byte[2] { rotx, roty };*/
|
||||
buffer[64] = sideblock;
|
||||
buffer[65] = edgeblock;
|
||||
HTNO( sidelevel ).CopyTo( buffer, 66 );
|
||||
SendRaw( 30, buffer );
|
||||
SendRaw( Opcode.CpeEnvSetMapApperance, buffer );
|
||||
}
|
||||
|
||||
public void SendSetMapWeather( byte weather ) { // 0 - sunny; 1 - raining; 2 - snowing
|
||||
byte[] buffer = new byte[1];
|
||||
buffer[0] = weather;
|
||||
SendRaw( 31, buffer );
|
||||
SendRaw( Opcode.CpeEnvWeatherType, buffer );
|
||||
}
|
||||
|
||||
void SendHackControl( byte allowflying, byte allownoclip, byte allowspeeding, byte allowrespawning, byte allowthirdperson, byte allowchangingweather, short maxjumpheight ) {
|
||||
byte[] buffer = new byte[7];
|
||||
buffer[0] = allowflying;
|
||||
@ -713,8 +720,9 @@ rot = new byte[2] { rotx, roty };*/
|
||||
buffer[4] = allowthirdperson;
|
||||
buffer[5] = allowchangingweather;
|
||||
HTNO( maxjumpheight ).CopyTo( buffer, 6 );
|
||||
SendRaw( 32, buffer );
|
||||
SendRaw( Opcode.CpeHackControl, buffer );
|
||||
}
|
||||
|
||||
public void SendBlockDefinitions(BlockDefinitions bd)
|
||||
{
|
||||
byte[] buffer = new byte[79];
|
||||
@ -734,7 +742,7 @@ rot = new byte[2] { rotx, roty };*/
|
||||
buffer[76] = bd.FogR;
|
||||
buffer[77] = bd.FogG;
|
||||
buffer[78] = bd.FogB;
|
||||
SendRaw(35, buffer);
|
||||
SendRaw(Opcode.CpeDefineBlock, buffer);
|
||||
}
|
||||
|
||||
void UpdatePosition() {
|
||||
|
@ -1140,7 +1140,7 @@ namespace MCGalaxy {
|
||||
{
|
||||
byte[] buffer = new byte[65];
|
||||
Player.StringFormat("^detail.user.join=" + color + name + c.white, 64).CopyTo(buffer, 1);
|
||||
p1.SendRaw(13, buffer);
|
||||
p1.SendRaw(Opcode.Message, buffer);
|
||||
buffer = null;
|
||||
}
|
||||
else
|
||||
@ -3121,7 +3121,7 @@ return;
|
||||
{
|
||||
byte[] buffer = new byte[65];
|
||||
Player.StringFormat("^detail.user.part=" + color + name + c.white, 64).CopyTo(buffer, 1);
|
||||
p1.SendRaw(13, buffer);
|
||||
p1.SendRaw(Opcode.Message, buffer);
|
||||
buffer = null;
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user