Ejemplo n.º 1
0
        public void initialize(bool bServer, string serverIP, int serverPort)
        {
            _typeToTypeName   = new Dictionary <ushort, string> ();
            _toLoadNamespaces = new HashSet <string> ();
            _toLoadNamespaces.Add("JGame.StreamObject");
            JLogicHelper.IsServer = bServer;

            //initialize log system.
            JLog.Initialize();
            //initialize time
            JTime.Start();

            //initialize server or client network manager
            if (bServer)
            {
                JServerSocketManager.SingleInstance.Initialize(serverIP, serverPort);
                JProcessorRegister.RegisterServerProcessor();
            }
            else
            {
                JClientSocketManager.SingleInstance.Initialize(serverIP, serverPort);
            }

            //register stream objects.
            Assembly asmbs = Assembly.GetExecutingAssembly();

            foreach (Type curType in asmbs.GetTypes())
            {
                try
                {
                    //JLog.Info(curType.Namespace);
                    if (_toLoadNamespaces.Contains(curType.Namespace))
                    {
                        if (curType.IsClass)
                        {
                            MethodInfo methodinfo = curType.GetMethod("Type");
                            if (methodinfo != null)
                            {
                                string str = methodinfo.Invoke(Activator.CreateInstance(curType), null).ToString();
                                RegisterStreamObj(ushort.Parse(str), curType.Namespace + "." + curType.Name);
                            }
                        }
                    }
                }
                catch (Exception e) {
                    JLog.Error(e.Message);
                }
            }

            if (bServer)
            {
                JLogicThread.Start();
            }

            JLog.Debug("JGameManager initialize finished .");
        }
Ejemplo n.º 2
0
        public string GetStreamObjTypeName(ushort objType)
        {
            if (!_typeToTypeName.ContainsKey(objType))
            {
                JLog.Error("JGameManager.RegisterStreamObj can not find object type name of type:"
                           + JGameUtil.GetDescription((StreamObject.JObjectType)objType));
                return(null);
            }

            return(_typeToTypeName [objType]);
        }
Ejemplo n.º 3
0
 public bool ShutDown()
 {
     try
     {
         JLog.Info("JGameManager.ShutDown:Shut down server and client socket manager ...", JLogCategory.Network);
         JServerSocketManager.SingleInstance.ShutDown();
         JClientSocketManager.SingleInstance.ShutDown();
         JLog.Info("JGameManager.ShutDown:Shut down server and client socket manager finished.", JLogCategory.Network);
     }
     catch (Exception e) {
         JLog.Error("JGameManager.ShutDown:" + e.Message);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 4
0
        public void RegisterStreamObj(ushort objType, string typeName)
        {
            if (typeName == null)
            {
                JLog.Error("JGameManager.RegisterStreamObj empty  object type");
                return;
            }

            if (_typeToTypeName.ContainsKey(objType))
            {
                JLog.Error("JGameManager.RegisterStreamObj registed  object type" + typeName);
                return;
            }

            _typeToTypeName [objType] = typeName;
        }