예제 #1
0
        public CoreContext(MonoBehaviour view, bool autoStartup, GameObject debugInfoObject) : base(view, autoStartup)
        {
            _instance = this;

            ContextView = view;

            if (IsDebugMode)
            {
                DebugInfoObject = (GameObject)GameObject.Instantiate(debugInfoObject);
                DebugInfoObject.transform.parent = view.transform;
                DebugInfoObject.SetActive(false);
            }

            NetworkingCore = new NetworkingCore();
        }
예제 #2
0
        public static void StartClient(string ip, int port = 8606)
        {
            GenericSetup();

            SingleplayerServerStarter.Instance.StartServerThenCall(delegate             // clone drone requires us to start a bolt server to spawn players and such
            {
                NetworkingCore.StartClient(ip, port);
                ThreadSafeDebug.Log("Connected!");

                RegisterNetworkMessageHandelers();

                MapSendingMessge.OnMapSpawnedClient += delegate
                {
                };
            });
        }
예제 #3
0
        public static void StartServer(int port = 8606)
        {
            GenericSetup();

            SingleplayerServerStarter.Instance.StartServerThenCall(delegate // clone drone requires us to start a bolt server to spawn players and such
            {
                NetworkingCore.SERVER_OnClientConnected += SERVER_OnClientConnected;

                NetworkingCore.StartServer(port);

                RegisterNetworkMessageHandelers();

                CurrentGameData.CurentLevelID = "ModdedMultiplayerTestLevel.json";

                LevelManager.Instance.SpawnCurrentLevel(false).MoveNext();
            });
        }
        public void SendTo(byte[] data, ushort reciver)
        {
            if (Channel == MessageChannel.Unsafe && data.Length != MAX_UNSAFE_PACKAGE_SIZE)
            {
                throw new ArgumentException("The passed array must be " + MAX_UNSAFE_PACKAGE_SIZE + " long if the channel is set to unsafe", nameof(data));
            }

            byte[] msg = createFullMsg(FullMessageID, data);

            if (NetworkingCore.CurrentClientType == ClientType.Client)
            {
                throw new Exception("Cannot send data to a reciver from a client");
            }
            else if (NetworkingCore.CurrentClientType == ClientType.Host)
            {
                if (Channel == MessageChannel.Safe)
                {
                    if (reciver == 0)                    // if the target is the server, just run the function locally
                    {
                        NetworkingCore.ScheduleForMainThread(delegate
                        {
                            OnPackageReceivedClient(data);
                        });
                    }
                    else
                    {
                        NetworkingCore.SendServerTcpMessage(msg, reciver);
                    }
                }
                else if (Channel == MessageChannel.Unsafe)
                {
                    if (reciver == 0)                    // if the target is the server, just run the function locally
                    {
                        NetworkingCore.ScheduleForMainThread(delegate
                        {
                            OnPackageReceivedClient(data);
                        });
                    }
                    else
                    {
                        NetworkingCore.SendServerUdpMessage(msg, reciver);
                    }
                }
            }
        }
        public void Send(byte[] data)
        {
            if (Channel == MessageChannel.Unsafe && data.Length != MAX_UNSAFE_PACKAGE_SIZE)
            {
                throw new ArgumentException("The passed array must be " + MAX_UNSAFE_PACKAGE_SIZE + " long if the channel is set to unsafe", nameof(data));
            }

            byte[] msg = createFullMsg(FullMessageID, data);

            if (NetworkingCore.CurrentClientType == ClientType.Client)
            {
                if (Channel == MessageChannel.Safe)
                {
                    NetworkingCore.SendClientTcpMessage(msg);
                }
                else if (Channel == MessageChannel.Unsafe)
                {
                    NetworkingCore.SendClientUdpMessage(msg);
                }
            }
            else if (NetworkingCore.CurrentClientType == ClientType.Host)
            {
                if (Channel == MessageChannel.Safe)
                {
                    NetworkingCore.ScheduleForMainThread(delegate
                    {
                        OnPackageReceivedClient(data);                         // since the server is itself kind of a client we call on received client locally too
                    });
                    NetworkingCore.SendServerTcpMessage(msg);
                }
                else if (Channel == MessageChannel.Unsafe)
                {
                    NetworkingCore.ScheduleForMainThread(delegate
                    {
                        OnPackageReceivedClient(data);                         // since the server is itself kind of a client we call on received client locally too
                    });
                    NetworkingCore.SendServerUdpMessage(msg);
                }
            }
        }
예제 #6
0
 public static void DrawRay(Vector3 point1, Vector3 direction, Color color, float timeToSay = 0)
 {
     NetworkingCore.ScheduleForMainThread(() => debug.DrawRay(point1, direction, color, timeToSay));
 }
예제 #7
0
 public static void DrawLine(Vector3 point1, Vector3 point2, Color color, float timeToSay = 0)
 {
     NetworkingCore.ScheduleForMainThread(() => debug.DrawLine(point1, point2, color, timeToSay));
 }
예제 #8
0
 public static void Log(object msg, Color color)
 {
     NetworkingCore.ScheduleForMainThread(() => debug.Log(msg, color));
 }
예제 #9
0
 public static void Log(string msg)
 {
     NetworkingCore.ScheduleForMainThread(() => debug.Log(msg));
 }