Exemplo n.º 1
0
 // methods of IListener
 // internal use only
 public void ProcessMessage(GateToPlayer msg)
 {
     lock ( _messages )
     {
         _messages.Enqueue(msg);
     }
 }
Exemplo n.º 2
0
        public void MessageProcess(GateToPlayer msg)
        {
            ConsoleOutput.Trace("ActorManager: MessageProcess" + " P" + msg.ResponseProperty.Count + " C" + msg.ResponseConfig.Count);
            // process operations
            foreach (Operation operation in msg.Operations)
            {
                _actors_listener.ialOperate(operation.Src, operation.Dest, operation.Ptype, operation.Data);
            }

            // process responses of property
            {
                Dictionary <long, Dictionary <int, ByteString> > properties
                    = new Dictionary <long, Dictionary <int, ByteString> >();
                foreach (IdPtypeData property in msg.ResponseProperty)
                {
                    ActorUtils.InsertIdTypeData
                        (property.Id, property.Ptype, property.Data, properties);
                }

                /* this lock is not necessary */                //lock( _actors_listener )
                {
                    foreach (KeyValuePair <long, Dictionary <int, ByteString> > i in properties)
                    {
                        _actors_listener.ialResponseProperties(i.Key, i.Value);
                    }
                }
            }

            // process responses of config
            {
                Dictionary <long, Dictionary <int, ByteString> > configs
                    = new Dictionary <long, Dictionary <int, ByteString> >();
                foreach (IdCtypeData config in msg.ResponseConfig)
                {
                    ActorUtils.InsertIdTypeData
                        (config.Id, config.Ctype, config.Data, configs);
                }

                /* this lock is not necessary */                //lock( _actors_listener )
                {
                    foreach (KeyValuePair <long, Dictionary <int, ByteString> > i in configs)
                    {
                        _actors_listener.ialResponseConfigs(i.Key, i.Value);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override void OnRead(Socket socket, byte[] buffer)
        {
            if (buffer.Length > 0)
            {
                GateToPlayer g2p = GateToPlayer.Parser.ParseFrom(buffer);

                switch (g2p.Type)
                {
                case GateToPlayer.Types.ETYPE.Message:
                    _listener.ProcessMessage(g2p);
                    break;

                default:
                    Debug.LogWarning("Unknown message from gate");
                    break;
                }
            }
        }
Exemplo n.º 4
0
 public void ProcessMessage()
 {
     GateToPlayer[] messages = null;
     lock ( _messages )
     {
         if (_messages.Count > 0)
         {
             messages = new GateToPlayer[_messages.Count];
             _messages.CopyTo(messages, 0);
         }
         _messages.Clear();
     }
     if (null != messages)
     {
         foreach (GateToPlayer msg in messages)
         {
             _actor_manager.MessageProcess(msg);
             _agent_manager.MessageProcess(msg);
         }
     }
 }
Exemplo n.º 5
0
        public void MessageProcess(GateToPlayer msg)
        {
            ConsoleOutput.Trace("AgentManager: MessageProcess" + " U" + msg.Updated.Count + " E" + msg.Exited.Count);
            // build actor map
            /* this lock is not necessary */            //lock( _agents )
            {
                /* this lock is not necessary */        //lock( _agents_listener ) //TODO need lock?
                {
                    foreach (RegionActorPair rap in msg.Updated)
                    {
                        ConsoleOutput.Trace("AgentManager: MessageProcess " + rap.Actor.Id + "." + rap.Actor.Ptypes.Count + " updated.");
                        if (false == _agents_listener.ialIsSelf(rap.Actor.Id))
                        {
                            // find or create agent
                            AgentUtils <OBJECT> .UpdateOrInsertAgent
                                (rap.Region, rap.Actor.Id, rap.Actor.Ptypes, rap.Actor.Pdatas, _agents);
                        }
                    }

                    foreach (KeyValuePair <long, AgentUtils <OBJECT> .Agent> a in _agents)
                    {
                        long id = a.Key;
                        AgentUtils <OBJECT> .Agent agent = a.Value;

                        // try to create GameObject for new agents
                        if (null == agent.obj)
                        {
                            {
                                string prop_str = "";
                                foreach (KeyValuePair <int, AgentUtils <OBJECT> .Property> kvp in agent.properties)
                                {
                                    prop_str += kvp.Key + "," + kvp.Value.data.Length + ";";
                                }
                                ConsoleOutput.Trace("Agent enter: " + id + "|" + prop_str + " in " + agent.region.Index);
                            }

                            agent.obj = _agents_listener.ialCreate(id, agent.properties);
                        }
                        // update agents
                        else
                        {
                            if (agent.updated)
                            {
                                {
                                    string prop_str = "";
                                    foreach (KeyValuePair <int, AgentUtils <OBJECT> .Property> kvp in agent.properties)
                                    {
                                        prop_str += kvp.Key + "," + kvp.Value.data.Length + ";";
                                    }
                                    ConsoleOutput.Trace("Agent update: " + id + "|" + prop_str + " in " + agent.region.Index);
                                }
                                agent.updated = _agents_listener.ialUpdate(agent.obj, agent.properties);
                            }
                        }
                    }

                    // delete exited agents
                    foreach (RegionIdPair rip in msg.Exited)
                    {
                        AgentUtils <OBJECT> .Agent agent;
                        if (_agents.TryGetValue(rip.Id, out agent))
                        {
                            {
                                ConsoleOutput.Trace("Agent exit: " + rip.Id + " from " + rip.Region.Index);
                            }
                            if (rip.Region.Equals(agent.region))
                            // if they are different
                            // means the agent has entered another region
                            {
                                _agents_listener.ialDestroy(rip.Id, agent.obj);
                                _agents.Remove(rip.Id);
                            }
                        }
                    }
                }
            }
        }