What are the PVP rules in the Sword Art Online MMORPGs? The show, Sword Art Online has 2 Massively Multiplayer Online Role-Playing Games in it, Sword Art Online (SAO) and Alfheim Online (AFO). What are the player-vs-player rules in these 2 games? Sometimes the rules seem to either make no sense (being able to attack someone in a home town but not be attacked back) or seem contradictory (requiring a mutual duel sometimes and sometimes not). 

Also, I realize the rules from the 2 in-anime games are probably different. Where SAO seems to have free PvP in non-safezones, AFO requires duels (but only sometimes?).

Do the light novels go into any details about this?
Warning, there are spoilers in this answer if you haven't watched SAO completely yet.

For the SAO arc, outside of towns, you're constantly "flagged" for PvP. From the beginnings, when you're getting explained how the players are divided:


  Inside the city, or the places mostly referred to as «Safe Areas», there was protection implemented by the system and players couldn't hurt each other. But it wasn't like that outside. The stragglers made teams with other stragglers and ambushed other players —which was in many ways much more profitable than hunting monsters— out on the fields or the labyrinth areas. 


Players that commit crimes are marked orange (i.e., their cursor turns orange). From when Kirito and Asuna encounter the troop from The Army in the forest:


  More importantly, whenever a player committed a crime, their cursor would turn orange and wouldn't turn back to green for a long time.


Note that attacking an orange player doesn't change your cursor to orange. From when Asuna steps in to stop Kuradeel from killing Kirito:


  Kuradeel bounced back up as if he had springs and attempted to form an excuse with his nervous voice. But before he could finish, Asuna's right hand flashed and the tip of her sword tore Kuradeel's mouth. She didn't become a criminal since her opponent already had an orange cursor.


Inside of towns, you have the town protection in place, which doesn't allow open PvP, so many new players originally stayed in town to be safe. You can attack other people in towns, but it won't do anything except for some special shiny effects and knockback.

If players engage in duels, there are several options:


First Strike Mode - from the duel against Kuradeel:



  I nodded in reply, then pressed Yes and chose the «First Strike Mode» from the options. This was a duel that could be won either by landing the first clean hit or by reducing the opponent's HP to half.
  Complete Decisive Mode - from the Inner Area PK incident:



  But unfortunately, there were still some loopholes around this rule. One of them is when the player's sleeping. There are times when players, with their energy exhausted through long durations of battle, are basically unconscious when they go into a deep sleep, and unable to wake up even with some stimulations. With that opportunity, one could raise a request to duel in «Complete Decisive Mode» and moved the sleeping opponent's finger to press on the OK button. All that was left was to literally make the opponent sleep like the dead.



The other options are not explained or mentioned as far as I can see.

For the ALO arc, there's PvP against other fairy races in your native race's (controlled) towns. From when Lyfa/Suguha shows Kirito around meeting Sigurd:


  Somehow, a circle of onlookers had already surrounded them, drawn by the signs of trouble. If this was a formal duel, or if he were an actual Spriggan spy, then fine. But it would be dishonorable if Sigurd instigated a fight with a tourist like Kirito, who can't even fight back in this area.


And in that same quote, it's mentioned that a "formal duel" is possible, but that's not further explained. Outside of towns, you can fight without restrictions. This can be seen by people just fighting about everywhere. Note that if a race's lord is killed by another race, the other race will gain control over that lord's territory. From when Lyfa explains why the Salamander want to stop the Sylphid-Cait Sith alliance:


  "Also, if they kill the Lord, they will get some amazing bonuses. They will unconditionally receive 30% of the lord's funds stored in the mansion, and for ten days, the territory that the lord rules over would become occupied, then they are free to set taxes and take that money. That is a tremendous amount of money. The reason why Salamander became the largest force in the game was because in the past, they had set a trap for Sylph's first Lord and killed him. Normally lords don't venture into neutral territory. In the history of ALO, only one lord has ever been killed."