Esempio n. 1
0
        static void Main(string[] args)
        {
            MyPlugins.Load();

            var asyncInput = ReadConsoleAsync();
            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs eventArgs)
            {
                eventArgs.Cancel = true;
                IsRunning = false;
            };

            m_client = new MyRakNetClient((ulong)m_port);

            for (int i = 0; i < 10; i++)
            {
                switch (m_client.Startup(m_port))
                {
                    case StartupResultEnum.SOCKET_PORT_ALREADY_IN_USE:
                        m_port++;
                        break;
                    default:
                        break;
                }
            }

            new MyRakNetSyncLayer().LoadData(m_client, typeof(Program).Assembly);

            //MySyncedClass mySyncedObject = new MySyncedClass();
            //MySyncedFloatSNorm F = new MySyncedFloatSNorm();
            //mySyncedObject.Add(F);
            //MySyncedInt I = new MySyncedInt();
            //mySyncedObject.Add(I);

            //MySyncedClass myInnerSyncedObject = new MySyncedClass();
            //MySyncedVector3 V3 = new MySyncedVector3();
            //mySyncedObject.Add(V3);
            //mySyncedObject.Add(myInnerSyncedObject);
            //MyRakNetSyncLayer.RegisterSynced(mySyncedObject);

            MyRakNetSyncLayer.Static.OnEntityCreated += Static_OnEntityCreated;
            MyRakNetSyncLayer.Static.OnEntityDestroyed += Static_OnEntityDestroyed;

            RegisterEvents(m_client);
            var result = m_client.Connect("127.0.0.1", 27025);

            while (IsRunning)
            {
                if (asyncInput.IsCompleted)
                {
                    var cmd = asyncInput.Result;
                    if (!String.IsNullOrEmpty(cmd))
                    {
                        if (cmd == "quit")
                        {
                            IsRunning = false;
                        }
                        else
                        {
                            m_client.SendChatMessage(cmd);
                        }
                    }
                    asyncInput = ReadConsoleAsync();
                }

                m_client.Update();

                if (foo != null)
                {
                    if (lastD != foo.Position.Get().X)
                    {
                        for (int i = 0; i < (foo.Position.Get().X + 1) / 2 * 115; i++)
                        {
                            Console.Out.Write("|");
                        }
                        Console.Out.WriteLine();
                        lastD = foo.Position.Get().X;
                    }

                    if (lastStr != foo.Name.Get())
                    {
                        Console.WriteLine(foo.Name.Get());
                        lastStr = foo.Name.Get();
                    }
                }

                //if (lastF != F)
                //{
                //    for (int i = 0; i < (F + 1) / 2 * 115; i++)
                //    {
                //        Console.Out.Write("|");
                //    }
                //    Console.Out.WriteLine();
                //    lastF = F;
                //}

                //if (lastI != I)
                //{
                //    for (int i = 0; i < I % 116; i++)
                //    {
                //        Console.Out.Write("-");
                //    }
                //    Console.Out.WriteLine();
                //    lastI = I;
                //}

                Thread.Sleep(16);
            }
            m_client.Dispose();
            MyRakNetSyncLayer.Static.UnloadData();
            MyPlugins.Unload();
        }
Esempio n. 2
0
 private static void RegisterEvents(MyRakNetClient client)
 {
     client.OnAlreadyConnected += client_OnAlreadyConnected;
     client.OnChatMessage += client_OnChatMessage;
     client.OnClientJoined += client_OnClientJoined;
     client.OnClientLeft += client_OnClientLeft;
     client.OnConnectionAttemptFailed += client_OnConnectionAttemptFailed;
     client.OnConnectionBanned += client_OnConnectionBanned;
     client.OnConnectionLost += client_OnConnectionLost;
     client.OnDisconnectionNotification += client_OnDisconnectionNotification;
     client.OnInvalidPassword += client_OnInvalidPassword;
     client.OnModListRecieved += client_OnModListRecieved;
     client.OnWorldDownloadProgress += client_OnWorldDownloadProgress;
     client.OnWorldRecieved += client_OnWorldRecieved;
 }