Most of protocol implementation

Not yet compiled/tested--needs text buffer