GithubHelp home page GithubHelp logo

anothervehicleclaimsystem's Introduction

Another Vehicle Claim System (AVCS)

Goal

As this is made for MP, I am very conscious about efficiency thus I try my best to minimize meaningless loops which can and will become a performance nightmare for any server. Also, minimize inefficient use of network bandwidth and upstream as this is also a important consideration for server. All in all, I want to make vehicle claim system optimized for server usage.

Technical - How it works

Tracking Vehicle Ownership

Tracking vehicle is unusually difficult in PZ. PZ does not provide a good source of unique identifier for vehicles. Upon looking through the PZ methods document, the only arguably unique identifier is via "getSQLID()". Yet, it is only arguably unique identifier because client-side and server-side hold different set of "getSQLID()" which I assume is because client-side does not have the full vehicle database. The workaround solution is to simply tag the server-side "getSQLID()" as object mod data onto the vehicle so everybody will have the same identifier. Strangely enough, vehicle object doesn't hold mod data thus we proceed to unremovable objects (Thanks K15). Apparently, transmitModData() is bugged for vehicle object thus giving the wrong impression that vehicle object couldn't hold mod data. An workaround is implemented but will only be released publicly on B42 as is quite a headache to transfer existing moddata to another object. Also hope that in B42, transmitModData() will be fixed.

Global Database

This mod started out with the goal of having a centralized database thus in this case, we use the global mod data. Global mod data is basically a fancy key/value table and so we structured two such tables

  • AVCSByVehicleSQLID
    • [Vehicle SQL ID]
      • OwnerPlayerID = Username
      • ClaimDateTime = getTimestamp()
      • CarModel = Base.Car
      • LastLocationX = 1239
      • LastLocationY = 1459
      • LastLocationUpdateDateTime = getTimestamp()
  • AVCSByPlayerID
    • [Username]
      • [VehicleSQLID1] = true
      • [VehicleSQLID2] = true
      • [VehicleSQLID.etc] = true
      • LastKnownLogonTime = getTimestamp()

These tables are structured similarily to a database with vehicle SQL ID acting as either primary or foreign key, player username acting as either primary or foreign key. As this is a key/value table, as long we have vehicle SQL ID or player username, we can obtain the related data easily with minimum overhead.

In PZ, global mod data is fully controlled by the modder such that the modders have to keep it sync-ed between the client-side and server-side. The lazy way is to simply transmit the entire mod data when there's any changes but this can become a bandwidth and upstream nightmare. Obviously, that is not done here. The only time the entire global mod data is sent is during when player first joined the server and when there is a unknown cause of desync occurred. Otherwise, only bare minimum data is sent.

Overriding "IS" actions

In animated actions, it go through several stages. We override the very first stage to do our permission checking, it is the only stage that make sense.

Logging

"ISAVCSVehicleClaimAction" and "ISAVCSVehicleUnclaimAction" can be manually added to log in "servertest.ini". Otherwise, if you enabled server-side permission validation for claiming and unclaiming, any abnormality will logged to the vanilla log folder under AVCS tag.

Future

I don't know what future will hold for this mod. This mod can be expanded into a more comphrensive claiming system involving a seperate claim for factions and safehouses, likewise customized permissions just by expanding the database via global mod data and add related code to it. Unforutnately, time is not something I have a lot of time to do thus likely not add these features which is why I made this open source so in hope that others will expand it if they ever have the passion to.

anothervehicleclaimsystem's People

Contributors

lu5ck avatar ziopao avatar

Stargazers

 avatar

Watchers

 avatar

anothervehicleclaimsystem's Issues

AVCS Sends full database over and over

I was doing some packet inspection of our MP Server (WastelandRP) and found that occasionally, one client will be streamed the entire AVCS Database over and over. I have a dump of the packets for WireShark as proof.

I think this could be triggered in https://github.com/Lu5ck/AnotherVehicleClaimSystem/blob/main/contents/mods/AnotherVehicleClaimSystemB41/media/lua/client/AVCSClient.lua

My theory is:

  1. The player has no AVCS.dbByVehicleSQLID or AVCS.dbByPlayerID. (Why, idk maybe bug or desync?)
  2. A series of changes happens on the server (vehicles moved, permissions changed, w/e).
  3. Those changes all hit the player at once via normal sendServerCommand
  4. AVCS client starts to process them, and every single one of them triggers another ModData.request

Possible solution:

Add in a lastModDataSync which stores a timestamp. If that timestamp is lets say under 5 seconds, do not request again.

Some notes:

  • We are a veryyy busy server with >80 people on for many hours a day
  • We have A LOT of claimed cars. Maybe the desync has to do with packets being dropped or lost?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.