Пример #1
0
    public void SendLogin(string _name, string _pass)
    {
        
        CreateConnection(NetworkOutboundDestination.LoginServer);

        Packet p = new Packet(PacketType.Login);
        p.Push_nData(new NetData(HelperMethods.SHA1_Encrypt(_name)));
        p.Push_nData(new NetData(HelperMethods.SHA1_Encrypt(_pass)));
        byte[] transferData = p.ToStream();


        try
        {
            //NetConnection.SendTo(p.ToStream(), currentConnectionEP);
            sock.Send(transferData,transferData.Length);
            //NetConnection.SendTo(Encoding.ASCII.GetBytes("Hi"),currentConnectionEP);
            //Debug.Log("Login Packet Sent");
        }
        catch
        {
            Debug.LogError("Failed to send message to Login Server");
        }
        //HelperMethods.SHA1_Encrypt("temporaryPassword");
    }
Пример #2
0
        private void HandleMessage(byte[] msg, IPEndPoint connection)
        {
            packet = new Packet(msg);
            int uID;
            switch (packet.packet_type)
            {
                //DEBUG MESSAGE RECIEVED
                case PacketType.ServerMsg:
                    NetData tmp = packet.Pop_nData();
                    StringBuilder sb = new StringBuilder("ServerDebugMsg: ");
                    while (tmp != null)
                    {
                        sb.Append(tmp.To_String());
                        sb.Append(" ");
                        tmp = packet.Pop_nData();
                    }
                    Console.WriteLine(sb);
                    sb = null;
                    tmp = null;
                    break;
                case PacketType.Login:

                    //TODO: CLEANUP
                    string CryptUsername = packet.Pop_nData().To_String();
                    string CryptPassword = packet.Pop_nData().To_String();
                    Console.WriteLine("Login Request Received. <" + connection.Address + ">");
                    //Console.WriteLine("Password: "******"PosUpdate: uID[{0}]: Pos{1}", OnlinePlayers[playerIndex].UID, OnlinePlayers[playerIndex].PlayerPosition.ToString()));
                        Packet posUp = new Packet(PacketType.PositionUpdate);
                        posUp.Push_nData(new NetData(OnlinePlayers[playerIndex].UID));
                        posUp.Push_nData(new NetData(OnlinePlayers[playerIndex].PlayerPosition.x));
                        posUp.Push_nData(new NetData(OnlinePlayers[playerIndex].PlayerPosition.y));
                        posUp.Push_nData(new NetData(OnlinePlayers[playerIndex].PlayerPosition.z));

                        Send_All(OnlinePlayers[playerIndex].CurrentMap,posUp);
                    }
                    catch (ArgumentNullException e)
                    {
                        Console.WriteLine("Couldn't find player in list!");
                    }
                break;
                case PacketType.ChangeMap:
                    try
                    {
                        uID = packet.Pop_nData().To_Int();
                        int playerIndex = OnlinePlayers.FindIndex(ply => ply.UID == uID);
                        int mapID = packet.Pop_nData().To_Int();
                        OnlinePlayers[playerIndex].CurrentMap = mapID;
                        Console.WriteLine(string.Format("uID[{0}]: Switching to MapID<{1}>", mapID));

                    }
                    catch (ArgumentNullException e)
                    {
                        Console.WriteLine("Couldn't find player in list!");
                    }
                    break;
                case PacketType.HitboxCreate:
                    //Hitbox Spawned
                    uID = packet.Pop_nData().To_Int();
                    int pIndex = OnlinePlayers.FindIndex(ply => ply.UID == uID);
                    Vector3 pos = new Vector3(packet.Pop_nData().To_Float(), packet.Pop_nData().To_Float(), packet.Pop_nData().To_Float());
                    //Console.WriteLine(string.Format("HitboxCreated: uID[{0}] at Pos{1}", uID, pos));

                    //Inform rest of players in map
                    Packet hitboxPacket = new Packet(PacketType.HitboxCreate);
                    hitboxPacket.Push_nData(new NetData(uID));
                    hitboxPacket.Push_nData(new NetData(pos.x));
                    hitboxPacket.Push_nData(new NetData(pos.y));
                    hitboxPacket.Push_nData(new NetData(pos.z));
                    hitboxPacket.Push_nData(new NetData(packet.Pop_nData().To_Float()));
                    hitboxPacket.Push_nData(new NetData(packet.Pop_nData().To_Float()));

                    Send_All(OnlinePlayers[pIndex].CurrentMap, hitboxPacket);
                    break;
                case PacketType.ProjectileCreate:
                    //Hitbox Spawned
                    //Inform rest of players in map
                    uID = packet.Pop_nData().To_Int();
                    int pProjIndex = OnlinePlayers.FindIndex(ply => ply.UID == uID);
                    Vector3 proj_pos = new Vector3(packet.Pop_nData().To_Float(), packet.Pop_nData().To_Float(), packet.Pop_nData().To_Float());
                    Vector3 proj_dir = new Vector3(packet.Pop_nData().To_Float(), packet.Pop_nData().To_Float(), packet.Pop_nData().To_Float());
                    //Console.WriteLine(string.Format("ProjectileCreated: uID[{0}] at Pos{1} Direction{2}", uID, proj_pos, proj_dir));


                    //Inform rest of players in map
                    Packet projPacket = new Packet(PacketType.ProjectileCreate);
                    projPacket.Push_nData(new NetData(uID));
                    projPacket.Push_nData(new NetData(proj_pos.x));
                    projPacket.Push_nData(new NetData(proj_pos.y));
                    projPacket.Push_nData(new NetData(proj_pos.z));
                    projPacket.Push_nData(new NetData(proj_dir.x));
                    projPacket.Push_nData(new NetData(proj_dir.y));
                    projPacket.Push_nData(new NetData(proj_dir.z));
                    projPacket.Push_nData(new NetData(packet.Pop_nData().To_Int()));
                    projPacket.Push_nData(new NetData(packet.Pop_nData().To_Float()));
                    projPacket.Push_nData(new NetData(packet.Pop_nData().To_Float()));

                    Send_All(OnlinePlayers[pProjIndex].CurrentMap, projPacket);
                    break;
                case PacketType.Damage:
                    //Inform rest of players in map
                    break;
                case PacketType.CrowdControl:
                    //Inform rest of players in map
                    break;
                case PacketType.Death:
                    //Inform rest of players in map
                    break;
                case PacketType.ItemAdd:
                    //Query server database
                    break;
                case PacketType.ItemRemove:
                    //Query server database
                    break;
                case PacketType.GetEquipment:
                    //Query server database
                    uID = packet.Pop_nData().To_Int();
                    Packet equipQuery = new Packet(PacketType.SERVER_QueryEquip);
                    equipQuery.Push_nData(new NetData(connection.Address.ToString()));
                    equipQuery.Push_nData(new NetData(uID));
                    BackEnd.Send_ToBackend(equipQuery);
                    break;
                case PacketType.SetEquipment:
                    break;
                case PacketType.GetInventory:
                    //Query server database
                    break;
                case PacketType.CharacterInfo:
                    uID = packet.Pop_nData().To_Int();
                    Packet charQuery = new Packet(PacketType.SERVER_QueryEquip);
                    charQuery.Push_nData(new NetData(uID));
                    BackEnd.Send_ToBackend(charQuery);
                    break;
            }
        }