<commit_before>package main

import (
	"net"

	"fmt"

	"github.com/xiaonanln/goworld/entity"
	"github.com/xiaonanln/goworld/gwlog"
	"github.com/xiaonanln/goworld/netutil"
	"github.com/xiaonanln/goworld/proto"
)

type DispatcherClientProxy struct {
	proto.GoWorldConnection
	owner  *DispatcherService
	gameid int
}

func newDispatcherClientProxy(owner *DispatcherService, conn net.Conn) *DispatcherClientProxy {
	return &DispatcherClientProxy{
		GoWorldConnection: proto.NewGoWorldConnection(conn),
		owner:             owner,
	}
}

func (dcp *DispatcherClientProxy) serve() {
	// Serve the dispatcher client from game / gate
	defer func() {
		dcp.Close()

		err := recover()
		if err != nil && !netutil.IsConnectionClosed(err) {
			gwlog.Error("Client %s paniced with error: %v", dcp, err)
		}
	}()

	gwlog.Info("New dispatcher client: %s", dcp)
	for {
		var msgtype proto.MsgType_t
		pkt, err := dcp.Recv(&msgtype)
		if err != nil {
			gwlog.Panic(err)
		}

		gwlog.Info("%s.RecvPacket: msgtype=%v, payload=%v", dcp, msgtype, pkt.Payload())
		if msgtype == proto.MT_SET_GAME_ID {
			gameid := int(pkt.ReadUint16())
			dcp.gameid = gameid
			dcp.owner.HandleSetGameID(dcp, gameid)
		} else if msgtype == proto.MT_NOTIFY_CREATE_ENTITY {
			eid := entity.EntityID(pkt.ReadBytes(entity.ENTITYID_LENGTH))
			dcp.owner.HandleNotifyCreateEntity(dcp, eid)
		}
	}<commit_msg>creating entity and notifying the dispatcher<commit_after>package main

import (
	"net"

	"fmt"

	"github.com/xiaonanln/goworld/entity"
	"github.com/xiaonanln/goworld/gwlog"
	"github.com/xiaonanln/goworld/netutil"
	"github.com/xiaonanln/goworld/proto"
)

type DispatcherClientProxy struct {
	proto.GoWorldConnection
	owner  *DispatcherService
	gameid int
}

func newDispatcherClientProxy(owner *DispatcherService, conn net.Conn) *DispatcherClientProxy {
	return &DispatcherClientProxy{
		GoWorldConnection: proto.NewGoWorldConnection(conn),
		owner:             owner,
	}
}

func (dcp *DispatcherClientProxy) serve() {
	// Serve the dispatcher client from game / gate
	defer func() {
		dcp.Close()

		err := recover()
		if err != nil && !netutil.IsConnectionClosed(err) {
			gwlog.Error("Client %s paniced with error: %v", dcp, err)
		}
	}()

	gwlog.Info("New dispatcher client: %s", dcp)
	for {
		var msgtype proto.MsgType_t
		pkt, err := dcp.Recv(&msgtype)
		if err != nil {
			gwlog.Panic(err)
		}

		gwlog.Info("%s.RecvPacket: msgtype=%v, payload=%v", dcp, msgtype, pkt.Payload())
		if msgtype == proto.MT_NOTIFY_CREATE_ENTITY {
			eid := entity.EntityID(pkt.ReadBytes(entity.ENTITYID_LENGTH))
			dcp.owner.HandleNotifyCreateEntity(dcp, eid)
		} else if msgtype == proto.MT_SET_GAME_ID {
			gameid := int(pkt.ReadUint16())
			dcp.gameid = gameid
			dcp.owner.HandleSetGameID(dcp, gameid)
		}
	}
{'fraction_non_alphanumeric': 0.1294755877034358, 'fraction_numerical': 0.0014466546112115732, 'mean_word_length': 4.2988505747126435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5442528', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1029, 'n_words': 197}