/// <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()); }
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]); }