Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1792)

Issue 7470: Type checking on IDs

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 6 months ago by Kayden
Modified:
9 years, 4 months ago
Reviewers:
ragnar
Base URL:
https://planeshift.svn.sourceforge.net/svnroot/planeshift/trunk/
Visibility:
Public.

Description

PlaneShift has many different kinds of IDs. Currently, these are simply typed as "int" or "unsigned int" and given enlightening names like "id", "owner id", or the like - which certainly don't clarify which kind of ID one is dealing with. It's easy to mix them up, and we've had several recent bugs caused by a developer doing so. By creating distinct ID types, we can not only document what kind of ID is in use, but also allow the compiler to statically type-check ID usage - killing an entire class of bugs, and making the project more maintainable. The following patch creates distinct ID types for PID, EID, and AccountID - more can come in future patches once this is in trunk. You'll find the definition and associated operations in psconst.h. Additional changes in this patch: ================================ * It fixes two bugs: - actionmanager.cpp/"Access is denied." - use of AccountID where a ClientID should go. - adminmanager.cpp/LIGHTNING - use of EID where a ClientID should go. * It exposes an EID/PID mismatch in EntityManager::CreatePet (which cannot possibly work), but simply returns NULL instead of attempting to fix it. AFAIK, pets are currently unused - only familiars, which have separate (but similar) code. * It changes NPCClient to use 0 as an invalid ID, rather than (size_t) -1, for consistency. Methods on ID Types: ==================== - IsValid(): 0 is considered invalid (most code already assumed this) - Show(): returns a csString like "EID:12345", so our output messages always indicate the type of ID. - Unbox(): returns the underlying integer (say, for passing to a DB query). Think twice before using this. - Operators ==, !=, <.

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1592 lines, -1646 lines) Patch
src/client/authentclient.cpp View 2 chunks +2 lines, -2 lines 0 comments Download
src/client/cmdusers.cpp View 2 chunks +3 lines, -3 lines 1 comment Download
src/client/gui/inventorywindow.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/client/gui/pawscontainerdescwindow.h View 1 chunk +1 line, -1 line 0 comments Download
src/client/gui/pawscontainerdescwindow.cpp View 3 chunks +4 lines, -4 lines 1 comment Download
src/client/gui/pawsinfowindow.cpp View 1 chunk +3 lines, -0 lines 0 comments Download
src/client/gui/pawsinteractwindow.cpp View 2 chunks +3 lines, -3 lines 0 comments Download
src/client/gui/pawslootwindow.h View 2 chunks +2 lines, -2 lines 0 comments Download
src/client/gui/pawspetstatwindow.cpp View 2 chunks +2 lines, -2 lines 0 comments Download
src/client/gui/pawsquestrewardwindow.cpp View 1 chunk +1 line, -2 lines 0 comments Download
src/client/gui/pawsskillwindow.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/client/modehandler.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/client/pscelclient.h View 7 chunks +8 lines, -8 lines 0 comments Download
src/client/pscelclient.cpp View 13 chunks +21 lines, -21 lines 0 comments Download
src/client/psclientchar.cpp View 3 chunks +4 lines, -4 lines 0 comments Download
src/client/psclientdr.cpp View 4 chunks +4 lines, -6 lines 0 comments Download
src/common/net/messages.h View 44 chunks +66 lines, -64 lines 0 comments Download
src/common/net/messages.cpp View 74 chunks +129 lines, -129 lines 0 comments Download
src/common/net/npcmessages.h View 2 chunks +4 lines, -4 lines 0 comments Download
src/common/net/npcmessages.cpp View 35 chunks +82 lines, -85 lines 0 comments Download
src/common/util/psconst.h View 3 chunks +54 lines, -7 lines 0 comments Download
src/npcclient/gem.h View 5 chunks +8 lines, -10 lines 0 comments Download
src/npcclient/gem.cpp View 4 chunks +5 lines, -5 lines 0 comments Download
src/npcclient/networkmgr.h View 2 chunks +2 lines, -2 lines 0 comments Download
src/npcclient/networkmgr.cpp View 34 chunks +73 lines, -79 lines 0 comments Download
src/npcclient/npc.h View 7 chunks +13 lines, -14 lines 0 comments Download
src/npcclient/npc.cpp View 25 chunks +31 lines, -36 lines 0 comments Download
src/npcclient/npcbehave.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/npcclient/npcclient.h View 5 chunks +10 lines, -16 lines 0 comments Download
src/npcclient/npcclient.cpp View 19 chunks +35 lines, -41 lines 0 comments Download
src/npcclient/npcoperations.h View 2 chunks +2 lines, -1 line 0 comments Download
src/npcclient/npcoperations.cpp View 8 chunks +15 lines, -16 lines 0 comments Download
src/npcclient/perceptions.h View 1 chunk +2 lines, -2 lines 0 comments Download
src/npcclient/tribe.h View 2 chunks +6 lines, -1 line 0 comments Download
src/npcclient/tribe.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/server/actionmanager.h View 1 chunk +1 line, -1 line 0 comments Download
src/server/actionmanager.cpp View 6 chunks +10 lines, -10 lines 0 comments Download
src/server/adminmanager.h View 9 chunks +11 lines, -11 lines 0 comments Download
src/server/adminmanager.cpp View 61 chunks +99 lines, -97 lines 0 comments Download
src/server/authentserver.h View 2 chunks +5 lines, -5 lines 0 comments Download
src/server/authentserver.cpp View 10 chunks +13 lines, -13 lines 0 comments Download
src/server/bulkobjects/pscharacter.h View 13 chunks +32 lines, -32 lines 0 comments Download
src/server/bulkobjects/pscharacter.cpp View 53 chunks +99 lines, -102 lines 0 comments Download
src/server/bulkobjects/pscharacterloader.h View 7 chunks +16 lines, -16 lines 0 comments Download
src/server/bulkobjects/pscharacterloader.cpp View 30 chunks +76 lines, -100 lines 0 comments Download
src/server/bulkobjects/pscharinventory.h View 1 chunk +2 lines, -2 lines 0 comments Download
src/server/bulkobjects/pscharinventory.cpp View 7 chunks +11 lines, -13 lines 0 comments Download
src/server/bulkobjects/psguildinfo.h View 3 chunks +5 lines, -5 lines 0 comments Download
src/server/bulkobjects/psguildinfo.cpp View 12 chunks +15 lines, -19 lines 0 comments Download
src/server/bulkobjects/psitem.h View 5 chunks +9 lines, -9 lines 0 comments Download
src/server/bulkobjects/psitem.cpp View 10 chunks +13 lines, -13 lines 0 comments Download
src/server/bulkobjects/psitemstats.h View 3 chunks +4 lines, -4 lines 0 comments Download
src/server/bulkobjects/psitemstats.cpp View 4 chunks +6 lines, -7 lines 0 comments Download
src/server/bulkobjects/psmerchantinfo.h View 1 chunk +1 line, -1 line 0 comments Download
src/server/bulkobjects/psmerchantinfo.cpp View 1 chunk +2 lines, -2 lines 0 comments Download
src/server/bulkobjects/psnpcdialog.h View 2 chunks +3 lines, -3 lines 0 comments Download
src/server/bulkobjects/psnpcdialog.cpp View 2 chunks +3 lines, -3 lines 0 comments Download
src/server/bulkobjects/psnpcloader.cpp View 5 chunks +11 lines, -11 lines 0 comments Download
src/server/bulkobjects/psquestprereqops.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/server/bulkobjects/psspell.h View 2 chunks +3 lines, -3 lines 0 comments Download
src/server/bulkobjects/psspell.cpp View 4 chunks +4 lines, -4 lines 0 comments Download
src/server/bulkobjects/pstrainerinfo.h View 1 chunk +1 line, -1 line 0 comments Download
src/server/bulkobjects/pstrainerinfo.cpp View 1 chunk +2 lines, -2 lines 0 comments Download
src/server/bulkobjects/servervitals.h View 1 chunk +1 line, -1 line 0 comments Download
src/server/bulkobjects/servervitals.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/server/cachemanager.h View 1 chunk +2 lines, -2 lines 0 comments Download
src/server/cachemanager.cpp View 3 chunks +6 lines, -6 lines 0 comments Download
src/server/client.h View 4 chunks +8 lines, -8 lines 0 comments Download
src/server/client.cpp View 9 chunks +20 lines, -40 lines 0 comments Download
src/server/clients.h View 1 chunk +2 lines, -2 lines 0 comments Download
src/server/clients.cpp View 2 chunks +2 lines, -2 lines 0 comments Download
src/server/clientstatuslogger.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/server/combatmanager.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/server/command.cpp View 17 chunks +34 lines, -45 lines 0 comments Download
src/server/creationmanager.h View 1 chunk +2 lines, -2 lines 0 comments Download
src/server/creationmanager.cpp View 10 chunks +17 lines, -18 lines 0 comments Download
src/server/economymanager.h View 1 chunk +2 lines, -2 lines 0 comments Download
src/server/economymanager.cpp View 3 chunks +5 lines, -5 lines 0 comments Download
src/server/entitymanager.h View 4 chunks +7 lines, -7 lines 0 comments Download
src/server/entitymanager.cpp View 22 chunks +42 lines, -37 lines 0 comments Download
src/server/events.h View 5 chunks +5 lines, -5 lines 0 comments Download
src/server/events.cpp View 20 chunks +31 lines, -31 lines 0 comments Download
src/server/gem.h View 12 chunks +28 lines, -28 lines 0 comments Download
src/server/gem.cpp View 33 chunks +61 lines, -64 lines 0 comments Download
src/server/gmeventmanager.h View 7 chunks +8 lines, -8 lines 0 comments Download
src/server/gmeventmanager.cpp View 23 chunks +29 lines, -31 lines 0 comments Download
src/server/guildmanager.cpp View 1 chunk +4 lines, -11 lines 0 comments Download
src/server/marriagemanager.cpp View 2 chunks +2 lines, -6 lines 0 comments Download
src/server/npcmanager.h View 1 chunk +1 line, -1 line 0 comments Download
src/server/npcmanager.cpp View 44 chunks +112 lines, -114 lines 0 comments Download
src/server/progressionmanager.cpp View 3 chunks +3 lines, -3 lines 0 comments Download
src/server/psproxlist.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/server/psserver.h View 3 chunks +3 lines, -2 lines 0 comments Download
src/server/psserver.cpp View 2 chunks +6 lines, -11 lines 0 comments Download
src/server/psserverchar.h View 1 chunk +1 line, -1 line 0 comments Download
src/server/psserverchar.cpp View 4 chunks +4 lines, -4 lines 0 comments Download
src/server/questmanager.cpp View 1 chunk +1 line, -1 line 0 comments Download
src/server/serverstatus.cpp View 3 chunks +4 lines, -4 lines 0 comments Download
src/server/slotmanager.cpp View 4 chunks +4 lines, -4 lines 0 comments Download
src/server/spawnmanager.h View 6 chunks +6 lines, -6 lines 0 comments Download
src/server/spawnmanager.cpp View 10 chunks +18 lines, -18 lines 0 comments Download
src/server/spellmanager.cpp View 2 chunks +4 lines, -4 lines 0 comments Download
src/server/usermanager.cpp View 14 chunks +22 lines, -20 lines 0 comments Download
src/server/workmanager.cpp View 13 chunks +23 lines, -23 lines 0 comments Download

Messages

Total messages: 2
Kayden
15 years, 6 months ago (2008-10-14 18:03:34 UTC) #1
Kayden
15 years, 6 months ago (2008-10-14 18:51:47 UTC) #2
Added some comments from IRC to put them on the official record. :)

http://codereview.appspot.com/7470/diff/1/104
File src/client/cmdusers.cpp (right):

http://codereview.appspot.com/7470/diff/1/104#newcode636
Line 636: options.Format("eid:%u",
psengine->GetCharManager()->GetTarget()->GetEID().Unbox());
I only used Show() for user readable messages, but left this using Unbox(). 
This way, someone could change how Show() displays without breaking the server.

Ragnarin suggests I should make a Read() or Scan() method for doing the inverse
of Show(), and make both sides use those.  That way, they'd stay in sync.

http://codereview.appspot.com/7470/diff/1/91
File src/client/gui/pawscontainerdescwindow.cpp (left):

http://codereview.appspot.com/7470/diff/1/91#oldcode109
Line 109: sigData.Format("invslot_%d", mesg.containerID * 100 + mesg.slotID +
16);
Ragnarin says this code is incredibly ugly.  And it is!

As I recall, container IDs mean the following:
< 0 = an enumeration (CONTAINER_EXCHANGE_OFFERING etc.)
< 1000 = an inventory slot ID (container in bulk inventory)
>= 10000 = an EID (container in the world)

I didn't attempt to clean up Vengeance's container mess.  It's worth doing, but
is dangerous and a big job in and of itself.  I feel we should come up with a
new user interface for inventory and crafting first, which would necessitate
changes here.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b