Beispiel #1
0
        private void sendPacket(Packet pkt)
        {
            if (this.tcpClient == null)
            {
                GoWorldLogger.Warn("GameClient", "Game Client Is Not Connected, Send Packet Failed: " + pkt);
            }

            Debug.Assert(pkt.writePos >= sizeof(UInt16));
            this.sendAll(BitConverter.GetBytes((UInt32)pkt.writePos), sizeof(UInt32));
            this.sendAll(pkt.payload, pkt.writePos);
        }
Beispiel #2
0
 private void disconnectTCPClient()
 {
     if (this.tcpClient != null)
     {
         this.tcpClient.Close();
         this.tcpClient        = null;
         this.packetReceiver   = null;
         this.startConnectTime = DateTime.MinValue;
         GoWorldLogger.Warn(this.ToString(), "Disconnected");
     }
 }
Beispiel #3
0
 private void onConnected(IAsyncResult ar)
 {
     if (this.tcpClient.Connected)
     {
         GoWorldLogger.Info(this.ToString(), "Connected " + this.tcpClient.Connected);
     }
     else
     {
         GoWorldLogger.Warn(this.ToString(), "Connect Failed!");
         this.disconnectTCPClient();
     }
 }
Beispiel #4
0
        internal void OnSyncEntityInfo(string entityID, float x, float y, float z, float yaw)
        {
            ClientEntity entity;

            try
            {
                entity = this.entities[entityID];
            } catch (KeyNotFoundException)
            {
                GoWorldLogger.Warn("EntityManager", "Entity {0} Sync Entity Info Failed: Entity Not Found", entityID);
                return;
            }

            entity.OnSyncEntityInfo(x, y, z, yaw);
        }
Beispiel #5
0
        internal void OnMapAttrClear(string entityID, ListAttr path)
        {
            ClientEntity entity;

            try
            {
                entity = this.entities[entityID];
            }
            catch (KeyNotFoundException)
            {
                GoWorldLogger.Warn("EntityManager", "Entity {0} Sync Entity Info Failed: Entity Not Found", entityID);
                return;
            }

            entity.OnMapAttrClear(path);
        }
Beispiel #6
0
        internal ClientEntity CreateEntity(string typeName, string entityID, bool isClientOwner, float x, float y, float z, float yaw, MapAttr attrs)
        {
            if (typeName == SPACE_ENTITY_NAME)
            {
                typeName = "ClientSpace";
            }

            GoWorldLogger.Assert(this.entityTypes.ContainsKey(typeName), "Entity Type {0} Not Found", typeName);

            if (this.entities.ContainsKey(entityID))
            {
                ClientEntity old = this.entities[entityID];
                GoWorldLogger.Warn("EntityManager", "Entity {0} Already Exists, Destroying Old One: {1}", entityID, old);
                old.Destroy();
            }

            // create new Game Object of specified type
            Type entityType = this.entityTypes[typeName];

            System.Reflection.MethodInfo createGameObjectMethod = entityType.GetMethod("CreateGameObject");
            GoWorldLogger.Assert(createGameObjectMethod != null, "CreateGameObject Method Not Found For Entity Type {0}", typeName);

            GameObject gameObject = createGameObjectMethod.Invoke(null, new object[1] {
                attrs
            }) as GameObject;

            if (gameObject == null)
            {
                GoWorldLogger.Error("EntityManager", "Fail To Create GameObject For Entity Type {0}, Please Define New CreateGameObject Method Like: public static new GameObject CreateGameObject(MapAttr attrs) { ... }", typeName);
                return(null);
            }

            ClientEntity e = gameObject.GetComponent <ClientEntity>();

            if (e == null || e.GetType().Name != typeName)
            {
                // GameObject created, but wrong entity type
                GameObject.Destroy(gameObject);
                GoWorldLogger.Error("EntityManager", "Fail To Create GameObject For Entity Type {0}: wrong entity type {1}", typeName, e.GetType().Name);
                return(null);
            }

            GameObject.DontDestroyOnLoad(gameObject);
            e.init(entityID, isClientOwner, x, y, z, yaw, attrs);
            this.entities[entityID]       = e;
            gameObject.transform.position = e.Position;
            gameObject.transform.rotation = Quaternion.Euler(new Vector3(0f, e.Yaw, 0f));
            e.onCreated();

            // new entity created
            if (e.IsSpace)
            {
                // enter new space
                if (this.Space != null)
                {
                    this.Space.Destroy();
                }

                this.Space = e as ClientSpace;
                this.onEnterSpace();
            }
            else
            {
                if (e.IsClientOwner)
                {
                    if (this.ClientOwner != null)
                    {
                        GoWorldLogger.Warn("EntityManager", "Replacing Existing Player: " + this.ClientOwner);
                        this.ClientOwner.Destroy();
                    }

                    this.ClientOwner = e;
                    e.becomeClientOwner();
                }

                if (this.Space != null)
                {
                    e.enterSpace();
                }
            }
            return(e);
        }