Esempio n. 1
0
        public object KNetDeserializeReference(byte[] data)
        {
            MemoryStream    ms = new MemoryStream(data);
            BinaryFormatter bf = new BinaryFormatter();

            return(KlivenNet.FindPlayer((int)bf.Deserialize(ms)));
        }
Esempio n. 2
0
 /// <summary>
 /// Should be executed when Server starts. You have to call it manually.
 /// </summary>
 protected virtual void OnServerStarted()
 {
     if (KlivenNet.IsConnected || KlivenNet.IsServer)
     {
         throw new Exception("KlivenNetworking: Cannot start server instance, because other instance (server or client) is already running on that application. Note that KlivenNetworking does not support Host mode (client & server at once)");
     }
     KlivenNet.ServerInstance   = this;
     KlivenNet.MyConnection     = new KNetConnection(0);
     KlivenNet.ServerConnection = KlivenNet.MyConnection;
     KlivenNet.AddView(new KNetZeroView());
 }
Esempio n. 3
0
        internal void RecieveWelcomePacket(byte[] packet)
        {
            MemoryStream    ms = new MemoryStream(packet);
            BinaryFormatter bf = new BinaryFormatter();

            object[] welcomePacket = (object[])bf.Deserialize(ms);

            string[] viewTypeNames = (string[])welcomePacket[0];
            int[]    viewIds       = (int[])welcomePacket[1];

            for (int i = 0; i < viewIds.Length; i++)
            {
                var view = (KNetView)Activator.CreateInstance(Type.GetType(viewTypeNames[i]));
                //view.Init(viewIds[i]);
                KlivenNet.AddView(view, viewIds[i]);
            }
            KlivenNet.ServerConnection = new KNetConnection(0);
            //KlivenNet.MyConnection = new KNetConnection((short)welcomePacket[0]);
        }
Esempio n. 4
0
        internal static void RecieveBufferedObject(KNetSerializedField serializedField)
        {
            KNetView view = KlivenNet.FindView(serializedField.viewId);

            if (view == null)
            {
                KNetLogger.LogError($"KNetClient: could not Recieve buffered object: KNetView of id {serializedField.viewId}: view does not exist.");
                return;
            }
            var field = serializedField.fieldId < view.BufferedFields.Length ? view.BufferedFields[serializedField.fieldId] : null;

            if (field == null)
            {
                KNetLogger.LogError($"KNetClient: could not Recieve buffered object: KNetView of id {serializedField.viewId}: field id {serializedField.fieldId} is not defined.");
                return;
            }
            field.SetValue(view, KNetUtils.Deserialize(serializedField.data, serializedField.count
                                                       , KNetUtils.IsSerializable(field.FieldType), field.FieldType));
        }