Caller ip on event process

Failing to get the caller IP from the context inside the processEvent handler. Well, it makes sense if you buffering the event and spread them, then we are not anymore in a specific client context. But before looking for another solution I wonder if there is a way to get the IP address of the client who sent the event?

Thanks

@oshribin The context object of the event processor function you register in the server runtime is called by a fixed size worker pool of lightweight threads (goroutines). These consume from the circular buffer to enable you to process game events or to batch and forward events to an analytics service, etc. You can tune these parameters in the server settings:

https://heroiclabs.com/docs/install-configuration/#runtime

runtime.event_queue_workers Number of workers to use for concurrent processing of events. Default 8.

runtime.event_queue_size Size of the event queue buffer. Default 65536.

The context object passed into the event processor is just used. to observe cancellations in the server runtime and as you noted does not include any other context for the user on an event. The simplest way to add the IP address to an event is to just pass it in as a property of the event from the caller of your nk.Event functions. These will likely be dispatched from an RPC function or similar where the IP address can be extracted like so:

// ctx comes from an RPC function called by the user's game client
clientIP, ok := ctx.Value(runtime.RUNTIME_CTX_CLIENT_IP).(string)
if !ok {
    // No IP address found in the referrer header for the request.
}

A small word of caution about how you use the IP address though. The value should be anonymized away from the identifier for the user otherwise you could have problems later with the EU GDPR laws and possibly Privacy Shield in the US.

Hope this helps.