Giter VIP home page Giter VIP logo

Comments (22)

climu avatar climu commented on July 29, 2024 1

Cool !
I am quite a github newbie. I think I need to add you as a collaborator for this. I invited you.

from openstudyroom.

SolarBear avatar SolarBear commented on July 29, 2024

It does not seem that the list of online players is available through the web interface: we'll need to communicate directly with KGS.

Lots of interesting material about the KGS protocol here : http://www.gokgs.com/help/protocol.html

Sadly (or interestingly) it's not a REST or SOAP API, it's a binary stream protocol, although there is a WAR client provided. This gives us two possibilities:

  1. Make calls to the WAR client from the Python code. This implies to set up a Tomcat server and make calls to it. It involves some work but it seems reasonably simple.
  2. Reimplement the whole protocol, which would involve a lot of guessing and trial and error. Hard to know how much work this implies precisely without knowing the specifics of the protocol but I don't think it would be a good idea on the short-term, plus it could possibly break the KGS use policies.

I'll start working on this, it sounds fun. :)

from openstudyroom.

climu avatar climu commented on July 29, 2024

Thanks !

So you think this bot calls a Tomcat server ?

I have no clue about the how/what running a Tomcat server is about.

We definitely don't want to break KGS policies :)

Anyway, let us know how it goes.

from openstudyroom.

SolarBear avatar SolarBear commented on July 29, 2024

That code you link to seems weird before it's referencing stuff that doesn't seem to exist; for instance, it calls a few class constants (ie. KGS_URL) that I can't find anywhere, and towards the end it creates a ASRClass object, but I can't find the class definition anywhere! So this code seems really, really incomplete.

from openstudyroom.

climu avatar climu commented on July 29, 2024

ASRClass object definition is in models.py

But you are right. The code is incomplete.
The KGS_URL is imported from a setting file that was not uploaded to github.

from openstudyroom.

SolarBear avatar SolarBear commented on July 29, 2024

I'm definitely working on this, can you set me as Assignee?

from openstudyroom.

SolarBear avatar SolarBear commented on July 29, 2024

Done!

For the record, interfacing directly with KGS through the servlet isn't terribly complicated.

  1. Set up a bare-bones Tomcat server (download it from the site or install the package) - requires Java installed.
  2. Move the KGS WAR file to Tomcat's webapps folder.
  3. I had to copy a java-json.jar file into the app folder but this might be related to me having OpenJDK installed instead of the Oracle official Java distribution.

And, just like that, it worked: I could login into KGS from my Python code! Next on my list is 1) translate the messages KGS sends back to usable Python Message objects and 2) keep the connection alive.

Feel free to browse my code in the kgs/ folder of my fork, in the kgs-connection branch.

from openstudyroom.

climu avatar climu commented on July 29, 2024

That's good news !

I will have a look at your code today.

Did you noticed this api explorer that the meta kgs guys did ?

from openstudyroom.

SolarBear avatar SolarBear commented on July 29, 2024

Update:

This is coming along pretty well: I can connect to the server, receive and send messages and parse them into usable objects.

Next step is taking some data (I'll start with users) and saving it into the database. Not quite sure if I should map User objects to KGS users or simply extend the Users table with some new columns: keeping the KGS data separate would allow us, some day, to allow for instance multiple accounts for a single OSR account or some such.

When this is done, I'll make a PR, close this issue and then work on individual features for KGS integration.

EDIT: I'm also pondering making the KGS package a full-blown external library, since it would be perfectly reusable as it is by any other kind of project since it is not yet bound to Django. On the one hand doing so right now seems hasty since it's lacking in features but on the other hand extracting it would require some more code to wrap the library and bind it to our app. ;) Stay tuned.

from openstudyroom.

climu avatar climu commented on July 29, 2024

Great !

As for the user table integration, I think best would be not to extend user model but to create a league_profile model that would be onetoone with user.

Such profile model would have user profile infos like:

  • various servers usernames
  • short bio
  • online status
  • avatar ( from machina)
  • signature (from machina)

One day we should write a view to allow user change their profile.

Why that would be best, I don't know. Just read everywhere that people tend to do that.

As for the external lib, it's indeed a very good idea. Your call obviously.

from openstudyroom.

SolarBear avatar SolarBear commented on July 29, 2024

I think the league profile is a good idea, it will allow us to dissociate linking the user to his KGS data directly. That way we could switch to a different server someday (or hell, simply support more than one!)

I wasn't 100% sure how to handle the online status: from what I've seen, when we log in the server sends us a lot of data, including all existing room names, but not the players' list (which would've been too much data, I guess). Then it hit me: since the scraper will have an account (kind of like a bot), it can use the friends feature! I'll simply register league members as friends when they set their KGS user name and the server will send a message containing online friends when we log in as well as messages when their status updates, IIRC.

from openstudyroom.

climu avatar climu commented on July 29, 2024

Hey !
I agree about supporting different servers. We have plans to support OGS as soon as possible.

I think you can have the players list with the "ROOM_JOIN" messages.
Such messages have all the games and players that are currently in a room.
Just filter with our room id (3627409) and it's done.

from openstudyroom.

climu avatar climu commented on July 29, 2024

Hey, an idea just poped my mind so I write it there:

We could have a button "I wanna play" on user profile that would send a kgs pm to all connected players of his group: "User wants to play a OSR league game for the B group !"

from openstudyroom.

SolarBear avatar SolarBear commented on July 29, 2024

from openstudyroom.

climu avatar climu commented on July 29, 2024

well, we could also send pm to user who are not in a game I guess :)
Or, as you suggest, allow users to have setting for that: always pm | pm if not in a game | never pm

from openstudyroom.

SolarBear avatar SolarBear commented on July 29, 2024

from openstudyroom.

climu avatar climu commented on July 29, 2024

Good news !

With new kgs update, we don't need to run a tomcat server anymore !

We can just call http://www.gokgs.com/json/access directly.

Check out how Ilya is doing with Gouniverse here for instance.

Idea: Maybe we could have a fork of Gouniverse on our website that display directly users of your group, OSR admins...

from openstudyroom.

SolarBear avatar SolarBear commented on July 29, 2024

I've seen that! That's awesome and much less hassle and maintenance for us.

Just for the record, I haven't had much free time in the last 10 days or so, and what little time I had I spent on trying to make an actual PIP package and... that was a lot of work for nothing. It's just not working and since I simply don't want to lose any more time on this, I'll just scrap that project and get back to it if it ever becomes necessary.

from openstudyroom.

climu avatar climu commented on July 29, 2024

Sounds good !

Thanks, let us know how it goes.

You might want to know that in this commit, I wrote a user profile class.
That field might be of your interest
last_kgs_online = models.DateTimeField(blank=True,null=True)

If you think a boolean field is_online would be better, let me know.

from openstudyroom.

xcombelle avatar xcombelle commented on July 29, 2024

there is an http api end point by kgs, so no more need to deploy a war. I have to check the address

from openstudyroom.

climu avatar climu commented on July 29, 2024

Hi,
Indeed I saw that and mentioned here in this very same issue.

@SolarBear was working on quite a serious python implementation.
I am not sure we need all that at OSR and I have no news from him since quite some time.

Do you feel like helping out here ?

from openstudyroom.

climu avatar climu commented on July 29, 2024

I wrote a very basic stuff that kinda work for now.

I feel ashame after all the work you did, but I didn't know how to use it...

from openstudyroom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.