Creative Mode
#1
I got creative mode mostly working now. You load into the server in creative, but can still take fall damage, and if you die you respawn in normal mode. Breaking blocks doesn't work yet, but you can place any block from your unlimited inventory without crashing now.


I was surprised at how easy it was to add a new packet. I'm sure I probably did something wrong, at least it works though. hehe


I'm guessing blocks don't break because it either sends a different packet for block breaks, or the server is waiting for a block dig start packet? I haven't looked yet.


I'll upload the files shortly and post the link here.

http://code.google.com/p/mc-server/source/detail?r=15



>.> and I changed the port again.
Reply
Thanks given by:
#2
Creative mode client only sends Started digging.

I want the server to support both per client and per server creative mode.

For now I think I'll make it so the server is either in or out of creative mode.
Creative mode now breaks blocks without providing block drops. I need to work with the player's inventory to get the placement of blocks and current inventory to work with creative mode though. I am also declaring and assigning a value to the constant Int GAMEMODE in two separate areas. That should be changed to a single location. It seems like changing the respawn packet fixed dying in gamemode 1, but you can still take damage.

Uploading new files shortly.

R16 is here: http://code.google.com/p/mc-server/sourc...th=/trunk/


Reply
Thanks given by:
#3
Now up to r17.

http://code.google.com/p/mc-server/source/detail?r=17


More changes for creative mode. Players can't take damage, but still sometimes spawn dead. Falling through the void doesn't kill you.
Reply
Thanks given by:
#4
You have a giant bug in the cPacket_CreateInventoryAction packet.

Code:
static const unsigned int c_Size = 1 + 4 + 2 + 2 + 2;
This totals 11 bytes, while the protcol documentation says it's 9 bytes (which makes sense: 4 shorts (8bytes) + packet id (1byte) = 9bytes)

I'm still looking at the other changes you made

---------
Code:
short m_Short;
Should be m_Damage;

--------
Code:
if( m_ItemID <= 0 ) m_ItemID = -1; // Fix, to make sure no invalid values are sent.
                        // WARNING: HERE ITS -1, BUT IN NAMED ENTITY SPAWN PACKET ITS 0 !!
Make sure this is true for this packet, minecraft is not consistent with this. Sometimes empty is 0, and sometimes it's -1, the client WILL crash if it's wrong

--------
You made some unnecessary changes to cPlugin.h, cInventory.h and Bindings.cpp.
cPlugin.h and cInventory.h both have some classes Forward declared, you only have to do that when you actually use the classes (in this case you're not using cPacket_CreateInventoryAction in those files)
Bindings.cpp is automagically generated by "trunk/source/AllToLua.bat", it's a windows executable that reads several *.h files and creates Lua bindings.

--------
You added
Code:
static const int GAMEMODE = 1; //0 = Survival, 1 = Creative;
to cPacket.h, this is not the right place for this, and packets should not be initialized with a gamemode. I suggest moving this to the cWorld class, and reading the gamemode from cWorld while filling in a packet before sending it.

For example:
Code:
// Create Respawn player packet
cPacket_Respawn Packet;
Packet.m_CreativeMode = cRoot::Get()->GetWorld()->GetGameMode();
// .. fill in some more stuff
// Send packet
// ???
// profit
Same goes for the login packet

--------
Since players might want to switch to creative/survival mode on the fly, GAMEMODE should not be a constant value in cClientHandle, just make it a regular int m_GameMode (in cClientHandle OR cPlayer) and initialize it to the current cWorld value (see above) then when a player decides to change game mode, just switch the integer to 0 or 1
(I see you moved it to one spot, but above still applies, and it should actually be in 2 places)
Reply
Thanks given by:
#5
Thanks, I'll get those errors fixed.

I knew I was going to get some things wrong.

I completely forgot about changing the c_Size


The reason I put m_Short instead of m_Damage was because in cPacket_EntityEquipment I notice it used m_Short instead od m_Damage. I just followed suit instead of trying m_Damage.
Reply
Thanks given by:
#6
These are just some pointers, don't take it too hardTongue I thought you said you're new to C++ so I'm sure there's so much stuff going on you don't even know what's happening.

I suspect that I created cPacket_EntityEquipment before the documentation was complete, and nobody had any idea what it did, so I just named it m_Short ^^
Reply
Thanks given by:
#7
(10-27-2011, 05:53 AM)FakeTruth Wrote: These are just some pointers, don't take it too hardTongue I thought you said you're new to C++ so I'm sure there's so much stuff going on you don't even know what's happening.

I suspect that I created cPacket_EntityEquipment before the documentation was complete, and nobody had any idea what it did, so I just named it m_Short ^^

Yes, I'm new to C++ and greatly appreciate any help or pointers you can give. I'm open to all advice.Big Grin Learning this is a handful right now, but it's a ton of fun.

I think I added m_Gamemode to cWorld correctly, now I'm working on sending the packets with the correct information. I'll probably have some more questions soon.

I fixed most of the problems and made the changes you suggested for the gamemode. I've got it working for the respawn:

Code:
void cPlayer::Respawn()
{
        m_Health = 20;

        cWorld* World = cRoot::Get()->GetWorld();
        // Create Respawn player packet
        cPacket_Respawn Packet;
        //Set Gamemode for packet by looking at world's gamemode (Need to check players gamemode.)
        Packet.m_CreativeMode = cRoot::Get()->GetWorld()->GetGameMode();
        //Send Packet
        m_ClientHandle->Send( Packet );
        TeleportTo( World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ() );
        SetVisible( true );
}

but I'm not sure where or how the login packet is sent from the server yet.

Edit:
figured it out. It's just done differently in cClientHandle than it is in cPlayer.



Going to upload my changes now.

It does appear

if( m_ItemID <= 0 ) m_ItemID = -1; // Fix, to make sure no invalid values are sent

is correct for this packet.


Edit:
Changes at: http://code.google.com/p/mc-server/source/detail?r=18
Reply
Thanks given by:
#8
I fixed creative mode to allow placement of blocks. Basically, any block added from the creative mode inventory is not acknowledged by the server. cClientHandle.cpp now ignores the check to remove an item in creative mode and allows placement of blocks not in your inventory.

I'm planning on changing creative mode to being player based. A player spawns into the world in whatever mode the world is set to, but all checks of creative mode will be based on the player's current mode.
Reply
Thanks given by:
#9
I added some sanity checks for working with blocks. I want to make the server kick the player if they cause the sanity check to go off too many times now.

MCserver crashes when picking up an inventory item. I'm not sure when this bug started since the server's been in GM 1 for a while now. I'll start looking into it.


Edit:
I added another LOG below the spot I thought was causing the problem and now I can't replicate the crash. Maybe it was just a problem in that one compile. Semms to be working now.

I set the interaction limit to 0.1 seconds. This is easy to hit by clicking quickly. I did this so it'd be easier to test.
Reply
Thanks given by:
#10
(11-02-2011, 03:54 AM)rs2k Wrote: I fixed creative mode to allow placement of blocks. Basically, any block added from the creative mode inventory is not acknowledged by the server. cClientHandle.cpp now ignores the check to remove an item in creative mode and allows placement of blocks not in your inventory.

I'm planning on changing creative mode to being player based. A player spawns into the world in whatever mode the world is set to, but all checks of creative mode will be based on the player's current mode.

That's exactly how I would do it.


(11-02-2011, 06:12 AM)rs2k Wrote: I added some sanity checks for working with blocks. I want to make the server kick the player if they cause the sanity check to go off too many times now.

MCserver crashes when picking up an inventory item. I'm not sure when this bug started since the server's been in GM 1 for a while now. I'll start looking into it.


Edit:
I added another LOG below the spot I thought was causing the problem and now I can't replicate the crash. Maybe it was just a problem in that one compile. Semms to be working now.

I set the interaction limit to 0.1 seconds. This is easy to hit by clicking quickly. I did this so it'd be easier to test.

I never had those problems on my side. I do notice sometimes when testing from cygwin that the server crashes randomly, and when I do a complete recompile of the entire project it works fine, so my guess is that you sometimes have to do a full recompile when using gcc
Reply
Thanks given by:




Users browsing this thread: 2 Guest(s)