basic protocol handling and packfile parsing code