예제 #1
0
        public override Task HandleAsync(ChatSendPacket packet, StarConnection connection)
        {
            if (packet.Text.StartsWith("/"))
            {
                string command = packet.Text.Substring(1);

                //Star command found, we're done here.
                if (Program.PlayerCommandManager.PassCommand(command, new PlayerCommandContext(connection.Proxy.Player)))
                {
                    packet.Ignore = true;

                    return(Task.FromResult(false));
                }

                bool found = false;
                foreach (IPluginManager pm in StarMain.Instance.PluginManagers)
                {
                    if (pm.PassCommand(command, connection.Proxy.Player))
                    {
                        found = true;
                    }
                }

                packet.Ignore = found;
            }

            return(Task.FromResult(false));
        }
예제 #2
0
        public override Task HandleAsync(HandshakeChallengePacket packet, StarConnection connection)
        {
            if (packet.IsReceive && connection.Proxy.Player.AuthAttempted)
            {
                packet.Ignore = true;
            }

            return(Task.FromResult(false));
        }
예제 #3
0
    private void RenderStarConnections(StarConnection connection)
    {
        GameObject connectionObj = GameObject.Instantiate (Resources.Load ("Prefabs/StarConnection")) as GameObject;
        LineRenderer starConnectionRenderer = connectionObj.GetComponent<LineRenderer> ();

        starConnectionRenderer.SetWidth (lineWidth, lineWidth);
        starConnectionRenderer.renderer.material = Resources.Load ("LineMaterial") as Material;

        starConnectionRenderer.SetVertexCount (2);

        starConnectionRenderer.SetPosition (0, connection.startPoint);
        starConnectionRenderer.SetPosition (1, connection.endPoint);
    }
예제 #4
0
        public override Task HandleAsync(ServerDisconnectPacket packet, StarConnection connection)
        {
            StarProxy proxy = connection.Proxy;

            Task.Delay(TimeSpan.FromSeconds(5)).ContinueWith(_ =>
            {
                if (proxy.Connected)
                {
                    proxy.CloseAsync().Wait();
                }
            });

            return(Task.FromResult(false));
        }
예제 #5
0
        public override Task HandleAsync(ConnectFailurePacket packet, StarConnection connection)
        {
            StarProxy proxy = connection.Proxy;

            //if the player is still connected within 5 seconds
            //then terminate the proxy
            Task.Delay(TimeSpan.FromSeconds(5)).ContinueWith(_ =>
            {
                if (proxy.Connected)
                {
                    proxy.CloseAsync().Wait();
                }
            });

            return(Task.FromResult(false));
        }
예제 #6
0
        protected void RegisterHeartbeatCheck(StarProxy proxy)
        {
            StarConnection sc = proxy.ClientConnection;

            var packetRecv = Observable.FromEventPattern <PacketEventArgs>(p => sc.PacketReceived += p, p => sc.PacketReceived -= p);
            var heartbeat  = (from p in packetRecv where p.EventArgs.Packet.PacketType == PacketType.Heartbeat select p)
                             .Timeout(TimeSpan.FromSeconds(StarMain.Instance.ServerConfig.HeartbeatTimeout));

            var checker = heartbeat.Subscribe(e => { }, e =>
            {
                if (!sc.IsDisposed && sc.Connected)
                {
                    if (!string.IsNullOrEmpty(proxy.Player.Name))
                    {
                        StarLog.DefaultLogger.Info("Did not receive a heartbeat packet from the player {0} for a while, kicking.", proxy.Player.Name);
                    }
                    else
                    {
                        StarLog.DefaultLogger.Info("Did not receive a heartbeat packet from the client {0} for a while, kicking.", proxy.ConnectionId);
                    }
                }

                try
                {
                    proxy.CloseAsync().Wait();
                }
                catch
                {
                }
            }, () => { });

            sc.Disconnected += (s, e) =>
            {
                IDisposable watched;

                ProxyHeartbeats.TryRemove(proxy, out watched);

                if (watched != null)
                {
                    watched.Dispose();
                }
            };

            ProxyHeartbeats.AddOrUpdate(proxy, checker, (p, d) => p);
        }
예제 #7
0
        public override Task HandleAsync(ConnectSuccessPacket packet, StarConnection connection)
        {
            if (!connection.Proxy.Player.AuthSuccess)
            {
                packet.Ignore = true;
            }

            if (connection.Proxy.Player.Account != null)
            {
                StarLog.DefaultLogger.Info("Player {0} ({1}) has joined", connection.Proxy.Player.Name, connection.Proxy.Player.Account.Username);
            }
            else
            {
                StarLog.DefaultLogger.Info("Player {0} has joined", connection.Proxy.Player.Name);
            }

            return(Task.FromResult(false));
        }
    //Each star searches all other stars, if it's within the maximum distance, create a new StarConnection between the two points and add it to the list.
    public void PopulateConnections()
    {
        for (int i = 0; i < StarList.Count; i++)
        {
            for(int j = 0; j < StarList.Count; j++)
            {
                if(StarList[i] != StarList[j] && GetDistance(StarList[i].transform.position, StarList[j].transform.position) < maxConnectDistance)
                {
                    StarConnection newConnection = new StarConnection();
                    newConnection.startPoint = StarList[i].transform.position;
                    newConnection.endPoint = StarList[j].transform.position;

                    if(StarConnectionList.Contains(newConnection) == false)
                        StarConnectionList.Add(newConnection);
                }
            }
        }
    }
예제 #9
0
        public override Task HandleAsync(ChatReceivePacket packet, StarConnection connection)
        {
            if (packet.Message.StartsWith("/"))
            {
                string command = packet.Message.Substring(1);

                if (!Program.PlayerCommandManager.PassCommand(command, new PlayerCommandContext(connection.Proxy.Player)))
                {
                    if (!StarMain.Instance.PassPlayerEventCommand(command, connection.Proxy.Player))
                    {
                        connection.Proxy.SendChatMessage("server", "No such command!");
                    }
                }

                packet.Ignore = true;
            }

            return(Task.FromResult(false));
        }
예제 #10
0
    public void set(StarConnection starConnection)
    {
        starNode = GameManager.instance.selectedStar;
        if (starNode == null)
        {
            Debug.Log("starNode not found in starconnection");
        }
        if (starConnection.state.nodes[0] == starNode)
        {
            other = starConnection.state.nodes[1];
        }
        else
        {
            other = starConnection.state.nodes[0];
        }
        var name = other.name;

        text.text = name;
    }
예제 #11
0
 public abstract Task HandleSentAsync(T packet, StarConnection connection);
예제 #12
0
 public override Task HandleSentAsync(HandshakeChallengePacket packet, StarConnection connection)
 {
     return(Task.FromResult(false));
 }
예제 #13
0
        /// <summary>
        /// Sends a packet right before a different type of packet is about to be sent.
        /// </summary>
        /// <typeparam name="T">The type of packet to be sent "after"</typeparam>
        /// <param name="toSendBefore">The packet to be sent before</param>
        /// <param name="afterDir">The direction that type of packet is going to be sent to</param>
        /// <param name="conn">The connection where the "before" packet should be sent to</param>
        public static void RegisterSendBefore <T>(this Packet toSendBefore, Direction afterDir, StarConnection conn) where T : Packet
        {
            var bEvt = Observable.FromEventPattern <PacketEventArgs>(p => conn.PacketSent += p,
                                                                     p => conn.PacketSent -= p).Select(p => p.EventArgs);

            StarConnection sendToConn;

            if (afterDir == Direction.Client)
            {
                sendToConn = conn.Proxy.ServerConnection;
            }
            else
            {
                sendToConn = conn.Proxy.ClientConnection;
            }

            var sEvt = Observable.FromEventPattern <PacketEventArgs>(p => sendToConn.PacketSending += p,
                                                                     p => sendToConn.PacketSending -= p).Select(p => p.EventArgs);

            var afterObs  = sEvt.Where(p => p.Packet.GetType() == typeof(T));
            var beforeObs = bEvt.Where(p => p.Packet == toSendBefore);

            afterObs.Take(1).Finally(() => conn.SendPacket(toSendBefore)).Subscribe(p =>
            {
                p.Packet.Ignore = true;

                beforeObs.Take(1).Subscribe(x =>
                {
                    p.Packet.Ignore = false;

                    sendToConn.SendPacket(p.Packet);
                });
            });
        }
예제 #14
0
 public override Task HandleSentAsync(CallScriptedEntityPacket packet, StarConnection connection)
 {
     return(Task.FromResult(false));
 }
예제 #15
0
        public override Task HandleAsync(CallScriptedEntityPacket packet, StarConnection connection)
        {
            Console.WriteLine(packet.Function);

            return(Task.FromResult(false));
        }
예제 #16
0
 public override Task HandleAsync(PlayerWarpPacket packet, StarConnection connection)
 {
     return(Task.FromResult(false));
 }
예제 #17
0
        public override async Task HandleAsync(HandshakeResponsePacket packet, StarConnection connection)
        {
            Account account = connection.Proxy.Player.Account;

            if (account != null)
            {
                Ban acctBan = StarMain.Instance.Database.GetBanByAccount(account.Id);

                if (acctBan != null && acctBan.Active)
                {
                    //ban has expired, set ban to inactive
                    if (DateTime.Now > acctBan.ExpirationTime)
                    {
                        acctBan.Active = false;

                        StarMain.Instance.Database.SaveBan(acctBan);
                        StarMain.Instance.Database.AddEvent(
                            string.Format("The ban for account {0} ({1}) has been lifted", account.Username, connection.Proxy.Player.Name),
                            new[] { "auto" });
                    }
                    else
                    {
                        await connection.Proxy.ClientConnection.SendPacketAsync(new ConnectFailurePacket
                        {
                            Reason = string.Format(StarMain.Instance.CurrentLocalization["BanReasonMessage"].Replace("\\n", "\n"), acctBan.Reason,
                                                   acctBan.ExpirationTime.ToString(StarMain.Instance.CurrentLocalization["BanMessageExpirationDateFormat"]))
                        });

                        StarMain.Instance.Database.AddEvent(
                            string.Format("Banned account {0} ({1}) attempted to join!", account.Username, connection.Proxy.Player.Name),
                            new[] { "bans" });

                        return;
                    }
                }

                byte[] acctHash = Convert.FromBase64String(account.PasswordHash);

                connection.Proxy.Player.AuthSuccess = packet.PasswordHash.SequenceEqual(acctHash);

                if (!connection.Proxy.Player.AuthSuccess)
                {
                    await connection.Proxy.ClientConnection.SendPacketAsync(new ConnectFailurePacket
                    {
                        Reason = StarMain.Instance.CurrentLocalization["WrongPasswordError"]
                    });

                    StarMain.Instance.Database.AddEvent(
                        string.Format("Player {0} ({1}) failed to login with the username {2}", connection.Proxy.Player.Name,
                                      connection.Proxy.Player.Uuid.Id, connection.Proxy.Player.Account.Username), new[] { "auth" });

                    connection.Proxy.Player.Account = null;
                }
                else
                {
                    //add the character to the databse and associate it with the account
                    Character ch = StarMain.Instance.Database.GetCharacterByUuid(connection.Proxy.Player.Uuid.Id) ?? new Character();

                    ch.Account = account;

                    StarMain.Instance.Database.SaveCharacter(ch);
                }
            }
            else if (!connection.Proxy.Player.AuthAttempted)
            {
                connection.Proxy.Player.AuthSuccess = true;
            }
            else
            {
                await connection.Proxy.ClientConnection.SendPacketAsync(new ConnectFailurePacket
                {
                    Reason = StarMain.Instance.CurrentLocalization["WrongPasswordError"]
                });
            }
        }
예제 #18
0
        /// <summary>
        /// Sends a packet right before a different instance of a packet is about to be sent.
        /// </summary>
        /// <param name="toSendBefore">The packet to send before</param>
        /// <param name="toSendAfter">The packet to send after</param>
        /// <param name="conn">The connection where the "before" packet should be sent to</param>
        public static void RegisterSendBefore(this Packet toSendBefore, Packet toSendAfter, StarConnection conn)
        {
            var bEvt = Observable.FromEventPattern <PacketEventArgs>(p => conn.PacketSent += p,
                                                                     p => conn.PacketSent -= p).Select(p => p.EventArgs);

            StarConnection sendToConn;

            if (toSendAfter.Direction == Direction.Client)
            {
                sendToConn = conn.Proxy.ClientConnection;
            }
            else
            {
                sendToConn = conn.Proxy.ServerConnection;
            }

            var sEvt = Observable.FromEventPattern <PacketEventArgs>(p => sendToConn.PacketSending += p,
                                                                     p => sendToConn.PacketSending -= p).Select(p => p.EventArgs);

            var afterObs  = sEvt.Where(p => p.Packet == toSendAfter);
            var beforeObs = bEvt.Where(p => p.Packet == toSendBefore);

            beforeObs.Take(1).Subscribe(_ =>
            {
                toSendAfter.Ignore = false;

                sendToConn.SendPacket(toSendAfter);
            });

            afterObs.Take(1).Finally(() => conn.SendPacket(toSendBefore)).Subscribe(_ =>
            {
                toSendAfter.Ignore = true;
            });

            conn.SendPacket(toSendBefore);
        }
예제 #19
0
 public override Task HandleSentAsync(ClientConnectPacket packet, StarConnection connection)
 {
     return(Task.FromResult(false));
 }
예제 #20
0
 public Task HandleBeforeAsync(Packet packet, StarConnection connection)
 {
     return(HandleAsync((T)packet, connection));
 }
예제 #21
0
 public Task HandleAfterAsync(Packet packet, StarConnection connection)
 {
     return(HandleSentAsync((T)packet, connection));
 }
    //Each star generates an amount of connections to have, searches for closest stars, create a new StarConnection between the two points and add it to the list.
    public void PopulateConnectionsByNum()
    {
        int randNumofConnections = 0;

        for (int i = 0; i < StarList.Count; i++)
        {
            randNumofConnections = Random.Range (1, 20);
            List<GameObject> closestStar = GetNearestStars(StarList[i], randNumofConnections);

            for(int j = 0; j < closestStar.Count; j++)
            {
                StarConnection newConnection = new StarConnection();
                newConnection.startPoint = StarList[i].transform.position;
                newConnection.endPoint = closestStar[j].transform.position;

                if(StarConnectionList.Contains(newConnection) == false)
                    StarConnectionList.Add(newConnection);
            }
        }

        /*int randNumofConnections = 0;

        for (int i = 0; i < StarList.Count; i++)
        {
            randNumofConnections = Random.Range (1, 5);
            List<GameObject> closestStar = GetNearestStars(StarList[i], randNumofConnections);

            for(int j = 0; j < closestStar.Count; j++)
            {
                Debug.DrawLine(StarList[i].transform.position, closestStar[j].transform.position, Color.red);
            }
        }*/
    }
예제 #23
0
        public override async Task HandleAsync(ClientConnectPacket packet, StarConnection connection)
        {
            Player plr = connection.Proxy.Player;

            plr.Name = packet.PlayerName;
            plr.Uuid = packet.Uuid;

            string    uuid = plr.Uuid.Id;
            Character ch   = StarMain.Instance.Database.GetCharacterByUuid(uuid) ?? new Character();

            ch.Name          = plr.Name;
            ch.Uuid          = uuid;
            ch.LastIpAddress = connection.Proxy.ClientConnection.RemoteEndPoint.Address.ToString();
            ch.Account       = null;

            StarMain.Instance.Database.SaveCharacter(ch);

            if (!string.IsNullOrEmpty(packet.Account) && Program.Configuration.EnableSharpAccounts)
            {
                Account account = StarMain.Instance.Database.GetAccountByUsername(packet.Account);

                if (account == null)
                {
                    return;
                }

                connection.Proxy.Player.Account = account;

                packet.Account = string.Empty;

                connection.Proxy.Player.AuthAttempted = true;

                await connection.Proxy.ClientConnection.SendPacketAsync(new HandshakeChallengePacket
                {
                    Salt = Encoding.UTF8.GetBytes(account.PasswordSalt)
                });
            }
            else
            {
                Ban ban = StarMain.Instance.Database.GetBanByIp(connection.Proxy.ClientConnection.RemoteEndPoint.Address.ToString());
                if (ban != null && ban.Active)
                {
                    if (DateTime.Now > ban.ExpirationTime)
                    {
                        ban.Active = false;

                        StarMain.Instance.Database.SaveBan(ban);
                        StarMain.Instance.Database.AddEvent(string.Format("The ban for uuid {0} ({1}) has been lifted", plr.Uuid.Id, plr.Name),
                                                            new[] { "auto" });
                    }
                    else
                    {
                        await connection.Proxy.ClientConnection.SendPacketAsync(new ConnectFailurePacket
                        {
                            Reason = string.Format(StarMain.Instance.CurrentLocalization["BanReasonMessage"].Replace("\\n", "\n"), ban.Reason,
                                                   ban.ExpirationTime.ToString(StarMain.Instance.CurrentLocalization["BanMessageExpirationDateFormat"]))
                        });

                        StarMain.Instance.Database.AddEvent(string.Format("Banned uuid {0} ({1}) attempted to join!", plr.Uuid.Id, plr.Name),
                                                            new[] { "bans" });

                        return;
                    }
                }

                connection.Proxy.Player.AuthSuccess = true;
            }
        }
 public override Task HandleAsync(ClientDisconnectRequestPacket packet, StarConnection connection)
 {
     return(Task.FromResult(false));
 }